Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Android
Search Coderanch
Advance search
Google search
Register / Login
This week's book giveaway is in the
Spring
forum.
We're giving away four copies of
Java Persistence with Spring Data and Hibernate
and have Cătălin Tudose on-line!
See
this thread
for details.
Win a copy of
Java Persistence with Spring Data and Hibernate
this week in the
Spring
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Ron McLeod
Tim Cooke
Paul Clapham
Liutauras Vilda
Sheriffs:
Junilu Lacar
Rob Spoor
Jeanne Boyarsky
Saloon Keepers:
Stephan van Hulst
Carey Brown
Tim Holloway
Piet Souris
Bartenders:
Forum:
Android
contacts doesn't display
shawn peter
Ranch Hand
Posts: 1325
1
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
here is my
java
class
package content.providers; import android.app.Activity; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.provider.Contacts.People; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; public class DatabaseExamples extends Activity implements OnClickListener{ /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button queryButton = (Button)findViewById(R.id.queryButton); queryButton.setOnClickListener(this); } private void queryContactPhoneNumber() { String[] cols = new String[] {People.NAME, People.NUMBER}; Uri myContacts = People.CONTENT_URI; Cursor mqCur = managedQuery(myContacts,cols,null,null,null); if (mqCur.moveToFirst()) { String myname = null; String mynumber = null; do { myname = mqCur.getString(mqCur.getColumnIndex(People.NAME)); mynumber = mqCur.getString(mqCur.getColumnIndex(People.NUMBER)); Toast.makeText(this, myname + " " + mynumber, Toast.LENGTH_SHORT).show(); } while (mqCur.moveToNext()); } } @Override public void onClick(View v) { // TODO Auto-generated method stub queryContactPhoneNumber(); } } here is AndroidManifest.xml file [code=java] <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="content.providers" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="3" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".DatabaseExamples" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.WRITE_CONTACTS" /> </application> </manifest>
here is logcat out put
07-20 11:38:25.054: DEBUG/dalvikvm(58): GC_EXPLICIT freed 5193 objects / 305424 bytes in 389ms 07-20 11:38:25.203: WARN/RecognitionManagerService(58): no available voice recognition services found 07-20 11:38:25.403: INFO/installd(34): unlink /data/dalvik-cache/data@app@content.providers-2.apk@classes.dex 07-20 11:38:25.613: DEBUG/AndroidRuntime(355): Shutting down VM 07-20 11:38:25.634: INFO/AndroidRuntime(355): NOTE: attach of thread 'Binder Thread #3' failed 07-20 11:38:25.643: DEBUG/dalvikvm(355): Debugger has detached; object registry had 1 entries 07-20 11:38:26.664: DEBUG/AndroidRuntime(367): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<< 07-20 11:38:26.664: DEBUG/AndroidRuntime(367): CheckJNI is ON 07-20 11:38:26.974: DEBUG/AndroidRuntime(367): --- registering native functions --- 07-20 11:38:27.884: INFO/ActivityManager(58): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=content.providers/.DatabaseExamples } 07-20 11:38:28.044: DEBUG/AndroidRuntime(367): Shutting down VM 07-20 11:38:28.074: DEBUG/dalvikvm(367): Debugger has detached; object registry had 1 entries 07-20 11:38:28.164: INFO/AndroidRuntime(367): NOTE: attach of thread 'Binder Thread #3' failed 07-20 11:38:28.194: INFO/ActivityManager(58): Start proc content.providers for activity content.providers/.DatabaseExamples: pid=374 uid=10039 gids={1015} 07-20 11:38:29.144: INFO/ActivityManager(58): Displayed activity content.providers/.DatabaseExamples: 1102 ms (total 1102 ms) 07-20 11:38:29.613: WARN/IInputConnectionWrapper(156): showStatusIcon on inactive InputConnection 07-20 11:38:34.373: DEBUG/dalvikvm(210): GC_EXPLICIT freed 102 objects / 8368 bytes in 141ms 07-20 11:38:38.174: ERROR/DatabaseUtils(156): Writing exception to parcel 07-20 11:38:38.174: ERROR/DatabaseUtils(156): java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.ContactsProvider2 uri content://contacts/people from pid=374, uid=10039 requires android.permission.READ_CONTACTS 07-20 11:38:38.174: ERROR/DatabaseUtils(156): at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:271) 07-20 11:38:38.174: ERROR/DatabaseUtils(156): at android.content.ContentProvider$Transport.bulkQuery(ContentProvider.java:149) 07-20 11:38:38.174: ERROR/DatabaseUtils(156): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:111) 07-20 11:38:38.174: ERROR/DatabaseUtils(156): at android.os.Binder.execTransact(Binder.java:288) 07-20 11:38:38.174: ERROR/DatabaseUtils(156): at dalvik.system.NativeStart.run(Native Method) 07-20 11:38:38.183: DEBUG/AndroidRuntime(374): Shutting down VM 07-20 11:38:38.183: WARN/dalvikvm(374): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 07-20 11:38:38.213: ERROR/AndroidRuntime(374): FATAL EXCEPTION: main 07-20 11:38:38.213: ERROR/AndroidRuntime(374): java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.ContactsProvider2 uri content://contacts/people from pid=374, uid=10039 requires android.permission.READ_CONTACTS 07-20 11:38:38.213: ERROR/AndroidRuntime(374): at android.os.Parcel.readException(Parcel.java:1247) 07-20 11:38:38.213: ERROR/AndroidRuntime(374): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:160) 07-20 11:38:38.213: ERROR/AndroidRuntime(374): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114) 07-20 11:38:38.213: ERROR/AndroidRuntime(374): at android.content.ContentProviderProxy.bulkQueryInternal(ContentProviderNative.java:330) 07-20 11:38:38.213: ERROR/AndroidRuntime(374): at android.content.ContentProviderProxy.query(ContentProviderNative.java:366) 07-20 11:38:38.213: ERROR/AndroidRuntime(374): at android.content.ContentResolver.query(ContentResolver.java:245) 07-20 11:38:38.213: ERROR/AndroidRuntime(374): at android.app.Activity.managedQuery(Activity.java:1520) 07-20 11:38:38.213: ERROR/AndroidRuntime(374): at content.providers.DatabaseExamples.queryContactPhoneNumber(DatabaseExamples.java:28) 07-20 11:38:38.213: ERROR/AndroidRuntime(374): at content.providers.DatabaseExamples.onClick(DatabaseExamples.java:43) 07-20 11:38:38.213: ERROR/AndroidRuntime(374): at android.view.View.performClick(View.java:2408) 07-20 11:38:38.213: ERROR/AndroidRuntime(374): at android.view.View$PerformClick.run(View.java:8816) 07-20 11:38:38.213: ERROR/AndroidRuntime(374): at android.os.Handler.handleCallback(Handler.java:587) 07-20 11:38:38.213: ERROR/AndroidRuntime(374): at android.os.Handler.dispatchMessage(Handler.java:92) 07-20 11:38:38.213: ERROR/AndroidRuntime(374): at android.os.Looper.loop(Looper.java:123) 07-20 11:38:38.213: ERROR/AndroidRuntime(374): at android.app.ActivityThread.main(ActivityThread.java:4627) 07-20 11:38:38.213: ERROR/AndroidRuntime(374): at java.lang.reflect.Method.invokeNative(Native Method) 07-20 11:38:38.213: ERROR/AndroidRuntime(374): at java.lang.reflect.Method.invoke(Method.java:521) 07-20 11:38:38.213: ERROR/AndroidRuntime(374): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 07-20 11:38:38.213: ERROR/AndroidRuntime(374): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 07-20 11:38:38.213: ERROR/AndroidRuntime(374): at dalvik.system.NativeStart.main(Native Method)
I have added the screenshjot of emulator when i press it.Please advice.
Error.jpg
shawn peter
Ranch Hand
Posts: 1325
1
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I have already added permission to the AndroidManifest.xml file.But it says permission denied.Please advise.
Ulf Dittmer
Rancher
Posts: 43076
77
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Post the permission section of the manifest.
shawn peter
Ranch Hand
Posts: 1325
1
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission> <uses-permission android:name="android.permission.WRITE_CONTACTS"></uses-permission>
shawn peter
Ranch Hand
Posts: 1325
1
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
still i am unable to find the error.Anyone can help ?
What's that smell? I think this tiny ad may have stepped in something.
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
My app works on one phone but not another
Null pointer exception probably due to synchronisation issues; problem in starting activity
OpenYMSG API on android
unable to create the service ,it gives null pointer exception
android uncaught handler: thread main exiting due to uncaught exception
More...