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
答案 0 :(得分:6)
如错误跟踪所示:
requires android.permission.READ_CALL_LOG or android.permission.WRITE_CALL_LOG
您还需要添加
<uses-permission android:name="android.permission.READ_CALL_LOG" />
或
<uses-permission android:name="android.permission.WRITE_CALL_LOG" />
到AndroidManifest中的权限使用列表。
当然,如果您只是阅读,您也不应该同时使用WRITE权限 - 阅读就足够了。
答案 1 :(得分:0)
此错误显示,&#34;我无法读取和写入您收到的通话记录,我需要读取和写入来自CallLogProvider的通话记录的权限#34;,CallLog提供程序包含有关已拨打和已接来电的信息。
现在你应该为你的清单添加 WRITE_CALL_LOG 权限,如果你有这样的错误,
java.lang.SecurityException:Permission Denial:从ProcessRecord打开提供程序com.android.providers.contacts.CallLogProvider {42931860 15578:com.hirecraft.jugunoo.passenger / u0a10095}(pid = 15578,uid = 10095)需要android .permission.READ_CALL_LOG或android.permission.WRITE_CALL_LOG
<uses-permission android:name="android.permission.WRITE_CALL_LOG" />
否则,如果你遇到这样的错误,你应该对你的清单添加 READ_CALL_LOG 权限,
java.lang.SecurityException:Permission Denial:读取com.android.providers.contacts.CallLogProvider uri content:// call_log / calls from pid = 16013,uid = 10095需要android.permission.READ_CALL_LOG或grantUriPermission()< / p>
<uses-permission android:name="android.permission.WRITE_CALL_LOG" />