Hi Mark,
As suggested by u ,i am using the same code.this is my code:-
But its returning blank screen,eventhough in conatct application i have
added the name,phone no. and email..
*
import* android.app.Activity;
*
import* android.content.ContentUris;
*
import* android.database.Cursor;
*
import* android.net.Uri;
*
import* android.os.Bundle;
*
import* android.provider.Contacts.People;
*
import* android.util.Log;
*
import* android.widget.ListAdapter;
*
import* android.widget.SimpleCursorAdapter;
*
public* *class* GetEmail *extends* Activity {
/** Called when the activity is first created. */
*private* ListAdapter mAdapter;
*public* *static* *final* String[] *METHODS_PROJECTION* = *new* String[] {
People.ContactMethods.*_ID*,
People.ContactMethods.*KIND*,
People.ContactMethods.*DATA*,
People.ContactMethods.*TYPE*,
People.ContactMethods.*LABEL*,
People.ContactMethods.*ISPRIMARY*,
};
Uri mUri;
@Override
*public* *void* onCreate(Bundle savedInstanceState) {
*super*.onCreate(savedInstanceState);
setContentView(R.layout.*main*);
mUri =
ContentUris.*withAppendedId*(Uri.*parse*("content://contacts/people"),1);
//1 is the ID of the first created contact
Uri methodsUri = Uri.*withAppendedPath*(mUri,People.ContactMethods.*
CONTENT_DIRECTORY*);
Cursor methodsCursor = getContentResolver().query
(methodsUri,*METHODS_PROJECTION*, "kind=1", *null*, *null*);
String[] columns = *new* String[]{People.*_ID*}; // Comment
*int*[] names = *new* *int*[]{R.id.*row_entry*};
Log.*i*("Cursor", "Count = " + methodsCursor.getCount());
mAdapter = *new* SimpleCursorAdapter(*this*, R.layout.*main*, methodsCursor,
columns, names);
*this*.setListAdapter(mAdapter);
}
*
private* *void* setListAdapter(ListAdapter adapter) {
// *TODO* Auto-generated method stub
}
}
main.xml:-
<?xml version=*"1.0"* encoding=*"utf-8"*?>
<LinearLayout xmlns:android=*"http://schemas.android.com/apk/res/android"*
android:orientation=*"horizontal"*
android:layout_width=*"fill_parent"*
android:layout_height=*"wrap_content"*
>
<TextView
android:layout_width=*"wrap_content"*
android:layout_height=*"wrap_content"*
android:text=*"email: "
*
/>
<TextView
android:id=*"@+id/row_entry"*
android:layout_width=*"wrap_content"*
android:layout_height=*"wrap_content"*
android:text=*"Name: "*
/>
</LinearLayout>
AndroidManifest:
<?xml version=*"1.0"* encoding=*"utf-8"*?>
<manifest xmlns:android=*"http://schemas.android.com/apk/res/android"
*
package=*"com.android.hello"
*
android:versionCode=*"1"
*
android:versionName=*"1.0.0"*>
<uses-permission android:name=*"android.permission.READ_CONTACTS"*/>
<uses-permission android:name=*"android.permission.CALL_PHONE"*/>
<application android:icon=*"@drawable/icon"* android:label=*
"@string/app_name"*>
<activity android:name=*".GetEmail"
*
android:label=*"@string/app_name"*>
<intent-filter>
<action android:name=*"android.intent.action.MAIN"* />
<category android:name=*"android.intent.category.LAUNCHER"* />
</intent-filter>
</activity>
</application>
</manifest>
On Wed, Feb 4, 2009 at 10:09 PM, dileep singh <[email protected]>wrote:
> Thank you very much Mark.I will try this code and will let you know.once
> again thanks.
>
>
> On Wed, Feb 4, 2009 at 9:12 PM, Mark Roberts <[email protected]> wrote:
>
>>
>> import android.app.Activity;
>> import android.content.ContentUris;
>> import android.database.Cursor;
>> import android.net.Uri;
>> import android.os.Bundle;
>> import android.provider.Contacts.People;
>> import android.util.Log;
>>
>> public class Start extends Activity {
>> /** Called when the activity is first created. */
>> public static final String[] METHODS_PROJECTION = new String[] {
>> People.ContactMethods._ID,
>> People.ContactMethods.KIND,
>> People.ContactMethods.DATA,
>> People.ContactMethods.TYPE,
>> People.ContactMethods.LABEL,
>> People.ContactMethods.ISPRIMARY,
>> };
>> Uri mUri;
>> @Override
>> public void onCreate(Bundle savedInstanceState) {
>> super.onCreate(savedInstanceState);
>> setContentView(R.layout.main);
>>
>> mUri = ContentUris.withAppendedId(Uri.parse("content://contacts/
>> people"), 1); //1 is the ID of the first created contact
>> Uri methodsUri = Uri.withAppendedPath(mUri,
>> People.ContactMethods.CONTENT_DIRECTORY);
>> Cursor methodsCursor = getContentResolver().query
>> (methodsUri,METHODS_PROJECTION, "kind=1", null, null);
>>
>> Log.i("Cursor", "Count = " + methodsCursor.getCount());
>> }
>> }
>>
>> On Feb 4, 4:44 am, dileep singh <[email protected]> wrote:
>> > Hi Mark,
>> > Can u give me some sample code?I am not able to get email with the above
>> > code.
>> > please provide me somple code
>> >
>> > On Wed, Feb 4, 2009 at 12:53 AM, dileep singh <
>> [email protected]>wrote:
>> >
>> > > Thanks a lot mark.I will try the above code.
>> >
>> > > On Tue, Feb 3, 2009 at 10:46 PM, Mark Roberts <[email protected]>
>> wrote:
>> >
>> > >> If you are looking for the emails for a specific contact then you
>> > >> could do it like this where id is the id of the contact for which you
>> > >> are trying to get the data:
>> >
>> > >> public static final String[] METHODS_PROJECTION = new String[] {
>> > >> People.ContactMethods._ID,
>> > >> People.ContactMethods.KIND,
>> > >> People.ContactMethods.DATA,
>> > >> People.ContactMethods.TYPE,
>> > >> People.ContactMethods.LABEL,
>> > >> People.ContactMethods.ISPRIMARY,
>> > >> };
>> > >> mUri = ContentUris.withAppendedId(Uri.parse("content://contacts/
>> > >> people"), id)
>> > >> Uri methodsUri = Uri.withAppendedPath(mUri,
>> > >> People.ContactMethods.CONTENT_DIRECTORY);
>> > >> Cursor methodsCursor = getContentResolver().query(methodsUri,
>> > >> METHODS_PROJECTION, "kind=1", null, null);
>> >
>> > >> On Feb 3, 12:05 pm, dilu <[email protected]> wrote:
>> > >> > Hi,
>> > >> > Please tell me how to get lists of email from contact application
>> in
>> > >> > android?If possible then please provide me some sample code or
>> > >> > tutorial on this.
>> > >> > please help me.
>> > >> > Thanks
>> > >> > dileep
>> >>
>>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---