10

我有以下问题。我们创建了一个游戏中心应用程序,它提供了一个框架来创建临时 wifi 游戏并管理此类游戏的高分/遭遇。

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

<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 上引发,以前的版本(例如我们测试 4.1)没有此问题。

感谢您提供有关如何解决此问题的任何见解。

4

1 回答 1

40

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

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

它会起作用。

于 2013-09-17T15:17:59.800 回答