How To Get Number From Contacts

Put your problem here if it does not fit any of the other categories.

How To Get Number From Contacts

Postby grimx » Thu Dec 31, 2009 12:29 am

How do you get the number back from an implicit call to view the contacts list

.java file
Code: Select all
package com.grimx.MakeCall;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MakeCall extends Activity implements View.OnClickListener{
    private static final int CONTACT_ACTIVITY = 100;
    EditText editText;
    Button callBtn;
    Button contactsBtn;
    Button closeBtn;
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        editText = (EditText)findViewById(R.id.editText);
        callBtn = (Button)findViewById(R.id.callBtn);
        callBtn.setOnClickListener(this);
        contactsBtn = (Button)findViewById(R.id.contactsBtn);
        contactsBtn.setOnClickListener(this);
        closeBtn = (Button)findViewById(R.id.closeBtn);
        closeBtn.setOnClickListener(this);
    }

   @Override
   public void onClick(View v) {
      if(v.getId() == R.id.callBtn) {
         String phn_number = editText.getText().toString();
         if(phn_number.equals("")) {
            Toast.makeText(MakeCall.this, "Please Enter A Phone Number", Toast.LENGTH_LONG).show();
            
         }
         else
         {
            Intent call_intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phn_number));
            startActivity(call_intent);
         }
                  
      }
      else if(v.getId() == R.id.contactsBtn) {
         Uri uri = Uri.parse("content://contacts/people");
         Intent contacts_intent = new Intent(Intent.ACTION_PICK, uri);
         startActivityForResult(contacts_intent, CONTACT_ACTIVITY);
      }
      else if(v.getId() == R.id.closeBtn) {
         Toast.makeText(MakeCall.this, "Exiting MakeCall", Toast.LENGTH_LONG).show();
         finish();
      }
   }
   
   public void onActivityResult(int requestCode, int resultCode, Intent data){
      super.onActivityResult(requestCode, resultCode, data);
      
      switch(requestCode){
      case(CONTACT_ACTIVITY): {
         if(resultCode == Activity.RESULT_OK) {
            //want to get the number an put it in the editText
            //editText.setText( );
         }
      break;
      }
         
      }
   }
   
   
}


the layout file
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.    android:orientation="vertical"
  4.    android:layout_width="fill_parent"
  5.    android:layout_height="fill_parent"
  6.    >
  7. <EditText
  8.         android:id="@+id/editText"
  9.         android:phoneNumber="true"
  10.    android:layout_width="fill_parent"
  11.    android:layout_height="wrap_content"
  12.    />
  13. <Button
  14.         android:id="@+id/callBtn"
  15.         android:layout_width="fill_parent"
  16.         android:layout_height="wrap_content"
  17.         android:text="Call"
  18.         />
  19. <Button
  20.         android:id="@+id/contactsBtn"
  21.         android:layout_width="fill_parent"
  22.         android:layout_height="wrap_content"
  23.         android:text="Show Contacts"
  24.         />
  25. <Button
  26.         android:id="@+id/closeBtn"
  27.         android:layout_width="fill_parent"
  28.         android:layout_height="wrap_content"
  29.         android:text="Close"
  30.         />
  31. </LinearLayout>
  32.  
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


my AndroidManifest.xml
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3.      package="com.grimx.MakeCall"
  4.      android:versionCode="1"
  5.      android:versionName="1.0">
  6.     <application android:icon="@drawable/icon" android:label="@string/app_name">
  7.         <activity android:name=".MakeCall"
  8.                  android:label="@string/app_name">
  9.             <intent-filter>
  10.                 <action android:name="android.intent.action.MAIN" />
  11.                 <category android:name="android.intent.category.LAUNCHER" />
  12.             </intent-filter>
  13.         </activity>
  14.  
  15.     </application>
  16.     <uses-sdk android:minSdkVersion="3" />
  17.     <uses-permission android:name="android.permission.CALL_PHONE" />
  18.     <uses-permission android:name="android.permission.CALL_PRIVILEGED" />
  19.  
  20. </manifest>
  21.  
Parsed in 0.003 seconds, using GeSHi 1.0.8.4
grimx
Junior Developer
Junior Developer
 
Posts: 20
Joined: Sat Dec 05, 2009 12:47 am

Top

Postby grimx » Thu Dec 31, 2009 12:34 am

sorry for the quad post :oops:
grimx
Junior Developer
Junior Developer
 
Posts: 20
Joined: Sat Dec 05, 2009 12:47 am

Postby hellshady00 » Sat Jan 02, 2010 3:34 pm

I see you've already solved this -
Ok problem solved.

I forgot to add the permission :
<uses-permission android:name="android.permission.READ_CONTACTS" />
to my AndroidManifest.xml file.


Someone might find that useful :)
User avatar
hellshady00
Developer
Developer
 
Posts: 29
Joined: Thu Dec 24, 2009 11:29 pm
Location: Florida

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 16 guests