String[] projection = new String[] {
CallLog.Calls._ID,
CallLog.Calls.CACHED_NAME,
CallLog.Calls.DATE,
CallLog.Calls.DURATION,
CallLog.Calls.NUMBER,
CallLog.Calls.TYPE
};
Cursor cursor = this.getContentResolver().query(
android.provider.CallLog.Calls.CONTENT_URI, projection, null, null, null
);
我想从 android 通话记录中获取应用程序的通话记录。目前我一直在开发 android 4.0 版本。我尝试了上面的代码,它会生成以下异常。这是什么原因?我已将<uses-permission android:name="android.permission.READ_CONTACTS" />
权限标签放置在清单文件中。
01-19 21:25:52.819: E/AndroidRuntime(3280): FATAL EXCEPTION: main
01-19 21:25:52.819: E/AndroidRuntime(3280): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.phonelog/com.example.phonelog.MainActivity}: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.CallLogProvider from ProcessRecord{41397ff8 3280:com.example.phonelog/u0a10053} (pid=3280, uid=10053) requires android.permission.READ_CALL_LOG or android.permission.WRITE_CALL_LOG
01-19 21:25:52.819: E/AndroidRuntime(3280): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-19 21:25:52.819: E/AndroidRuntime(3280): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-19 21:25:52.819: E/AndroidRuntime(3280): at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-19 21:25:52.819: E/AndroidRuntime(3280): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-19 21:25:52.819: E/AndroidRuntime(3280): at android.os.Handler.dispatchMessage(Handler.java:99)
01-19 21:25:52.819: E/AndroidRuntime(3280): at android.os.Looper.loop(Looper.java:137)
01-19 21:25:52.819: E/AndroidRuntime(3280): at android.app.ActivityThread.main(ActivityThread.java:5039)
01-19 21:25:52.819: E/AndroidRuntime(3280): at java.lang.reflect.Method.invokeNative(Native Method)
01-19 21:25:52.819: E/AndroidRuntime(3280): at java.lang.reflect.Method.invoke(Method.java:511)
01-19 21:25:52.819: E/AndroidRuntime(3280): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-19 21:25:52.819: E/AndroidRuntime(3280): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-19 21:25:52.819: E/AndroidRuntime(3280): at dalvik.system.NativeStart.main(Native Method)
01-19 21:25:52.819: E/AndroidRuntime(3280): Caused by: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.CallLogProvider from ProcessRecord{41397ff8 3280:com.example.phonelog/u0a10053} (pid=3280, uid=10053) requires android.permission.READ_CALL_LOG or android.permission.WRITE_CALL_LOG
01-19 21:25:52.819: E/AndroidRuntime(3280): at android.os.Parcel.readException(Parcel.java:1425)
01-19 21:25:52.819: E/AndroidRuntime(3280): at android.os.Parcel.readException(Parcel.java:1379)
01-19 21:25:52.819: E/AndroidRuntime(3280): at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:2530)
01-19 21:25:52.819: E/AndroidRuntime(3280): at android.app.ActivityThread.acquireProvider(ActivityThread.java:4460)
01-19 21:25:52.819: E/AndroidRuntime(3280): at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2002)
01-19 21:25:52.819: E/AndroidRuntime(3280): at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1101)
01-19 21:25:52.819: E/AndroidRuntime(3280): at android.content.ContentResolver.query(ContentResolver.java:356)
01-19 21:25:52.819: E/AndroidRuntime(3280): at android.content.ContentResolver.query(ContentResolver.java:315)
01-19 21:25:52.819: E/AndroidRuntime(3280): at com.example.phonelog.MainActivity.onCreate(MainActivity.java:32)
01-19 21:25:52.819: E/AndroidRuntime(3280): at android.app.Activity.performCreate(Activity.java:5104)
01-19 21:25:52.819: E/AndroidRuntime(3280): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-19 21:25:52.819: E/AndroidRuntime(3280): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-19 21:25:52.819: E/AndroidRuntime(3280): ... 11 more