Hi,
I am was trying to run the example from the chapter 5 on Intents... The created the ContactPicker and ContactPckerTester activities. Everything looks ok - compiling, running but I am not sure what to look for. The first activity that gets invoked is "ContactPickerTester" and rightly so , since the manifest defines the intent filter for it as action.MAIN and category.LAUNCHER.
However, it does not do anything after launching activity. I do not see the button to click "Pick Contact" ( the book says "Pick a Contact"). On debug mode , my control gets into a code outside by codebase after it reaches the
button.setOnClickListener(new OnClickListener() ..
Kindly explain to me what is happening?. I have coded both the contactpicker and contactPickerTest and I am convinced that I am passing the correct Intent. However I do not see the what is shown in the figure 5-1.
I am very confused.. thanks a ton for any help..
The full code for the ContactPickerTester.java is:
public
class ContentPickerTester extends Activity {
publicstaticfinalintPICK_CONTACT =1;
/**Calledwhentheactivityisfirstcreated.*/
@Override
publicvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contentpickertester);
Button button = (Button)findViewById(R.id.pick_content_button);
if (button== null)
System.exit(1);
button.setOnClickListener(new OnClickListener(){
publicvoid onClick(View _view) {
Intent intent = new Intent(Intent.ACTION_PICK,Uri.parse("content://contacts/"));
startActivityForResult(intent,PICK_CONTACT);
}
});
}
@Override
protectedvoid onActivityResult(int reqCode, int resCode, Intent data){
//public void OnActivityResult(int reqCode, int resCode, Intent data){
super.onActivityResult(reqCode, resCode, data);
switch(reqCode){
case (PICK_CONTACT):
if (resCode == Activity.RESULT_OK){
Uri ContactData = data.getData();
Cursor c = managedQuery(ContactData, null, null, null, null);
c.moveToFirst();
String name;
name = c.getString(c.getColumnIndexOrThrow(People.NAME));
TextView tv ;
tv= (TextView)findViewById(R.id.selected_contact_textView);
tv.setText(name);
}
break;
}
}
}
The manifest file:
?
xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.menonmatics.learn.contactpicker"
android:versionCode="1"
android:versionName="1.0.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".ContactPicker"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<data android:path="contacts"
android:scheme="content">
</data>
</intent-filter>
</activity>
<activity android:name=".ContentPickerTester"
android:label="Contact Picker Test">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
</manifest>