java – 基于应用程序安装顺序的Android自定义权限失败

在Google Play上发布我的应用程式问题.我有一个免费的应用程序,它利用了一个自定义的权限.此权限允许访问付费应用.这些付费应用程序可以作为“钥匙”,并在免费应用程序中解锁功能.基本上,免费的应用程序将尝试开始其中一个付费应用程序的意图.付费应用程序会做一些事情,并返回说免费应用程序是否应该解锁功能.

根据应用安装顺序出现问题.如果免费的应用程序首先安装了付费应用程序,则免费应用程序无法启动意图.返回权限拒绝.如果首先安装付费应用程序,然后免费应用程序,免费的应用程序可以启动意图没有问题.重新启动设备和/或强制停止应用程序无法解决问题.我附加了相关代码.有事告诉我我在做错事

>免费应用清单(相关代码):

...
<uses-permission android:name="com.company.license.PERMISSION" />
...

>免费应用程式代码检查意图(相关代码):

Intent KeyApp = new Intent("com.company.license.action.AUTH_1");
KeyApp.putExtra("com.company.license.challenge",1);

//If free app is installed first,an exception is thrown for not having the proper permission. If paid app is installed first,no exception is thrown
try {
    startActivityForResult(KeyApp,COMMING_FROM_KEYAPP);
} catch (Exception e) {
    cancelStartUp();
}

>付费应用清单(相关代码):

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.company.installer.1"
...
<permission
    android:name="com.company.license.PERMISSION"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:protectionLevel="normal" >
</permission>

<application
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoDisplay" >

    <activity
        android:name="com.company.license.auth"
        android:configChanges="keyboardHidden|orientation"
        android:exported="true"
        android:permission="com.company.license.PERMISSION"
        android:theme="@style/Theme.Transparent" >
        <intent-filter>
            <action android:name="com.company.license.action.AUTH_1" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

    <activity
        android:name="com.company.installer.redirect"
        android:configChanges="keyboardHidden|orientation"
        android:exported="true"
        android:theme="@style/Theme.Transparent" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

解决方法

将< permission>元素.另外,由于这是特定于您的两个应用程序,我将使用android:protectionLevel =“签名”而不是正常的 – 这意味着用户将永远不需要批准该权限,没有其他人将能够请求该权限.而且,这个配方将允许以任何顺序进行安装.

更新:请注意,使用自定义权限打开potential vulnerabilities,due to Android’s “first one in wins” approach.

更新#2:现在是no longer supported as of Android 5.0,因为两个应用程序不能都具有相同的< permission>元素,除非它们由相同的签名密钥签名.

以上是来客网为你收集整理的java – 基于应用程序安装顺序的Android自定义权限失败全部内容,希望文章能够帮你解决java – 基于应用程序安装顺序的Android自定义权限失败所遇到的程序开发问题。

如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。