Is there a way to keep meta-data in the Android manifest private to the package?

前端 未结 2 1120
长发绾君心
长发绾君心 2020-12-20 19:29

I want to use meta-data in the Android manifest to customize the behavior of a service.



        
2条回答
  •  猫巷女王i
    2020-12-20 20:00

    After doing some tests I confirmed that all meta-data fields are visible to all packages, as CommonsWare said. However, I also discovered that you can keep the content of the value private, by using android:resource instead of android:value. When you use android:resource only the integer id of the resource is returned from the PackageManager, and therefore only your package will have access to the actual resource value.

    Update: It turns out that CommonsWare was right again. After investigating further, all resources and assets are publicly visible to ALL packages installed on the device. No permissions are required.

    PackageManager pm = getPackageManager();
    PackageInfo info = pm.getPackageInfo("test.package", PackageManager.GET_META_DATA|PackageManager.GET_SERVICES);
    int resourceId = info.services[0].metaData.getInt("sampleName");
    String resourceValue = pm.getResourcesForApplication("test.package").getString(resourceId);
    

提交回复
热议问题