SecurityException:权限拒绝:打开提供程序

我有以下问题。 我们已经创build了一个游戏中心应用程序,提供了一个框架来创buildad hoc的wifi游戏,并pipe理这些游戏的高分和遇到。

高分数据库访问由一个提供者完成:

<provider android:name="com.identifier.gamecenterapp.contentprovider.MyGamesContentProvider" android:authorities="com.identifier.gamecenterapp.contentprovider" > </provider> 

我们的演示游戏(作为未来游戏开发者的参考)包含以下权限

 <uses-permission android:name="com.identifier.gamecenterapp.contentprovider.READ_DATABASE"/> <uses-permission android:name="com.identifier.gamecenterapp.contentprovider.WRITE_DATABASE"/> 

现在 – 每当我们尝试访问提供商的游戏,我们得到以下错误:

 09-17 12:15:52.221: E/AndroidRuntime(4551): FATAL EXCEPTION: main 09-17 12:15:52.221: E/AndroidRuntime(4551): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.identifier.gamecenter.gctictactoe/com.identifier.gamecenter.game.MainActivity}: java.lang.SecurityException: Permission Denial: opening provider com.identifier.gamecenterapp.contentprovider.MyGamesContentProvider from ProcessRecord{42622078 4551:com.identifier.gamecenter.gctictactoe/u0a10108} (pid=4551, uid=10108) that is not exported from uid 10072 09-17 12:15:52.221: E/AndroidRuntime(4551): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211) 09-17 12:15:52.221: E/AndroidRuntime(4551): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261) 09-17 12:15:52.221: E/AndroidRuntime(4551): at android.app.ActivityThread.access$600(ActivityThread.java:141) 09-17 12:15:52.221: E/AndroidRuntime(4551): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256) 09-17 12:15:52.221: E/AndroidRuntime(4551): at android.os.Handler.dispatchMessage(Handler.java:99) 09-17 12:15:52.221: E/AndroidRuntime(4551): at android.os.Looper.loop(Looper.java:137) 09-17 12:15:52.221: E/AndroidRuntime(4551): at android.app.ActivityThread.main(ActivityThread.java:5103) 09-17 12:15:52.221: E/AndroidRuntime(4551): at java.lang.reflect.Method.invokeNative(Native Method) 09-17 12:15:52.221: E/AndroidRuntime(4551): at java.lang.reflect.Method.invoke(Method.java:525) 09-17 12:15:52.221: E/AndroidRuntime(4551): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 09-17 12:15:52.221: E/AndroidRuntime(4551): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 09-17 12:15:52.221: E/AndroidRuntime(4551): at dalvik.system.NativeStart.main(Native Method) 09-17 12:15:52.221: E/AndroidRuntime(4551): Caused by: java.lang.SecurityException: Permission Denial: opening provider c.identifier.gamecenterapp.contentprovider.MyGamesContentProvider from ProcessRecord{42622078 4551:com.identifier.gamecenter.gctictactoe/u0a10108} (pid=4551, uid=10108) that is not exported from uid 10072 09-17 12:15:52.221: E/AndroidRuntime(4551): at android.os.Parcel.readException(Parcel.java:1431) 09-17 12:15:52.221: E/AndroidRuntime(4551): at android.os.Parcel.readException(Parcel.java:1385) 09-17 12:15:52.221: E/AndroidRuntime(4551): at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:2611) 09-17 12:15:52.221: E/AndroidRuntime(4551): at android.app.ActivityThread.acquireProvider(ActivityThread.java:4515) 09-17 12:15:52.221: E/AndroidRuntime(4551): at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2036) 09-17 12:15:52.221: E/AndroidRuntime(4551): at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1149) 09-17 12:15:52.221: E/AndroidRuntime(4551): at android.content.ContentResolver.query(ContentResolver.java:398) 09-17 12:15:52.221: E/AndroidRuntime(4551): at android.content.ContentResolver.query(ContentResolver.java:357) 09-17 12:15:52.221: E/AndroidRuntime(4551): at ch.ethz.csg.wlanopp.gapi.GameCenterController.getIdByGameTitle(GameCenterController.java:602) 09-17 12:15:52.221: E/AndroidRuntime(4551): at ch.ethz.csg.wlanopp.gapi.GameCenterController.isRegistered(GameCenterController.java:343) 09-17 12:15:52.221: E/AndroidRuntime(4551): at ch.ethz.csg.wlanopp.gapi.GameCenterController.addGame(GameCenterController.java:352) 09-17 12:15:52.221: E/AndroidRuntime(4551): at ch.ethz.csg.gamecenter.gctictactoe.MainActivity.onCreate(MainActivity.java:130) 09-17 12:15:52.221: E/AndroidRuntime(4551): at android.app.Activity.performCreate(Activity.java:5133) 09-17 12:15:52.221: E/AndroidRuntime(4551): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 09-17 12:15:52.221: E/AndroidRuntime(4551): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175) 09-17 12:15:52.221: E/AndroidRuntime(4551): ... 11 more 09-17 12:20:52.487: I/Process(4551): Sending signal. PID: 4551 SIG: 9 

奇怪的是,它工作了一段时间。 错误只在Android 4.3上引发,以前的版本(我们testing4.1)没有这个问题。

感谢您的任何见解如何解决。

在Android 4.3以下,您的提供程序的“已导出”的默认值设置为true。 在Android 4.3中,它被设置为false。

 <provider android:name="com.identifier.gamecenterapp.contentprovider.MyGamesContentProvider" android:authorities="com.identifier.gamecenterapp.contentprovider" android:exported="true"> </provider> 

它会工作。