I am working on QuickContactBadge. What I want to do is to show my app icon in the QuickContactBadge like facebook or gmail, and when the user press on the icon it will launch my application a selected activity. And when the the activity is launch i want to get the phone number which user selected.
Currently my application is showing QuickContactBadge and the badge also launch the main activity in the application but i am not able to get the phone number form which user launch the application.
My code is as follow:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(getIntent().getData() != null) {
Cursor cursor = getContentResolver().query(getIntent().getData(), null, null, null, null);
if(cursor != null) {
while (cursor.moveToNext()) {
String contactId = cursor.getString(cursor.getColumnIndex(
ContactsContract.Contacts._ID));
String hasPhone = cursor.getString(cursor.getColumnIndex(
ContactsContract.Contacts.HAS_PHONE_NUMBER));
if (Integer.parseInt(hasPhone) == 1) {
// You know have the number so now query it like this
Cursor phones = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?" ,
new String[]{contactId}, null);
while (phones.moveToNext()) {
String phoneNumber = phones.getString(
phones.getColumnIndex(
ContactsContract.CommonDataKinds.Phone.NUMBER));
}
phones.close();
} else{
Toast.makeText(this, "Invalid Contact", Toast.LENGTH_SHORT).show();
}
}
}
}
setContentView(R.layout.main);
}
It getting the Intent.getData but exception on hasPhone number because column does not exist and also down in the code if I ignore this exception while getting the phone number unable to get it. Plz help me where i am doing wrong.
I have use this code to display my app in the QuickContactBadge
<activity
android:name=".SandBoxProjectActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.item/name" />
</intent-filter>
</activity>