Android Read Phone Contacts Example
Read contact from Phone book using Content Provider
Ex12Activity.java
package com.bipin.rupadiya.Ex12;
import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract.PhoneLookup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Ex12Activity extends Activity {
ListView lvContacts;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lvContacts = (ListView) findViewById(R.id.lvContacts);
Cursor c = managedQuery(Uri.parse("content://contacts/phones"), null, null, null, null);
String names[] = new String[ c.getCount() ];
int i=0;
while (c.moveToNext())
names[i++] = c.getString(c.getColumnIndex(PhoneLookup.DISPLAY_NAME)) + "\n" + c.getString(c.getColumnIndex(PhoneLookup.NUMBER));
ArrayAdapter<String> adpt = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, names);
lvContacts.setAdapter(adpt);
}
}
import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract.PhoneLookup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Ex12Activity extends Activity {
ListView lvContacts;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lvContacts = (ListView) findViewById(R.id.lvContacts);
Cursor c = managedQuery(Uri.parse("content://contacts/phones"), null, null, null, null);
String names[] = new String[ c.getCount() ];
int i=0;
while (c.moveToNext())
names[i++] = c.getString(c.getColumnIndex(PhoneLookup.DISPLAY_NAME)) + "\n" + c.getString(c.getColumnIndex(PhoneLookup.NUMBER));
ArrayAdapter<String> adpt = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, names);
lvContacts.setAdapter(adpt);
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView android:layout_x="26dp" android:layout_y="34dp" android:layout_width="270dp" android:layout_height="425dp" android:id="@+id/lvContacts"></ListView>
</AbsoluteLayout>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView android:layout_x="26dp" android:layout_y="34dp" android:layout_width="270dp" android:layout_height="425dp" android:id="@+id/lvContacts"></ListView>
</AbsoluteLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bipin.rupadiya.Ex12"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name="com.bipin.rupadiya.Ex12.Ex12Activity"
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>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bipin.rupadiya.Ex12"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name="com.bipin.rupadiya.Ex12.Ex12Activity"
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>
Labels:
Android,
Mobile Computing
Subscribe to:
Post Comments (Atom)
Subjects
- WordPress
- Mobile Computing-4649303 Practical Solution
- Android Programming New Syllabus Theory
- PHP LAMP Question Bank
- PHP LAMP Theory
- Step by Step Android Example
- Android Practical
- Android Theory
- Android Question Bank
- Networking FON Practical
- Networking FON Theory
- OS Practical
- OS Theory
- HTML
- JavaScript
- J2EE WTAD Theory
- J2EE WTAD Question Bank
- J2EE WTAD Quick Guide
- J2EE WTAD GTU Papers
- J2EE WTAD Practical
- Python
- JAVA Theory
- JAVA Practical
- MIS
Categories
- Android (55)
- c (11)
- Configure Tomcat7 (2)
- CSS (3)
- Decryption (16)
- Difference (1)
- Encryption (16)
- Error Detection and Correction Techniques (3)
- FON (27)
- Framing Technic (2)
- install Tomcat (2)
- J2EE (29)
- JAVA (13)
- JavaScript (19)
- linux (8)
- OS (17)
- PHP (11)
- Protocol (3)
- SERVER SOCKET PROGRAMING (7)
- Servlet (13)
- shell script (33)
- unix (22)
- WTAD (34)
Total Pageviews
© BipinRupadiya.com. Powered by Blogger.
1 comments:
Nice post sir.....
Post a Comment