我以前的应用程序有很多活动,其中一些被声明为导出为真,以便其他应用可以通过意图过滤器调用它们。他们中的一些人也有特别的许可,这也是在我的活动中设定的。
现在,我正在开发一个应用程序使用单一的活动。因此,我很想知道如何在单个活动设计中处理这个权限问题,因为我只有一个活动。
以前,在多个活动中,我可以很容易地在特定活动中设置权限。我怎么处理这件事?我是个新手。我找了很多东西,但没有找到任何线索。
编辑:
Multiple activities declaration:
<permission
android:name="com.example.permission"
android:protectionLevel="signatureOrSystem"
tools:ignore="SignatureOrSystemPermissions"
/>
// Activity 1: With permission, exported = true
<activity
android:name=".place"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout"
android:exported="true"
android:label="place"
android:permission="com.example.permission" // Sets a permission
android:theme="@style/Theme.AppCompat.DayNight.NoActionBar">
<intent-filter>
<action android:name="com.action.places" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
// Activity 2: With no permission, exported = true
<activity
android:name="userCheck"
android:configChanges="mcc|mnc|keyboard|keyboardHidden|orientation"
android:exported="true"
android:theme="@style/Theme.AppCompat.DayNight.NoActionBar">
<intent-filter>
<action android:name="com.confirm.passowrd" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>现在,我想转移到单一的活动。
// Single activity: exported = true. How can i handle permission for place action?
<activity
android:name="com.example.singleActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<!-- Place -->
<action android:name="com.action.places"/> // How can i handle permission for this action?
<!-- UserCheck -->
<action android:name="com.confirm.passowrd" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>发布于 2021-01-25 11:56:27
如果要在某些情况下限制单个Activity的启动,而不能使用其他情况下的权限,则不能使用基于清单的权限。基于清单的权限控制对特定Activity的访问,无论它是如何启动的.
您可以做的是为您的单个<activity-alias>创建一个Activity。<activity-alias>是一个清单条目,它引用了实际的Activity,但提供了备用的启动选项。可以在<activity-alias>上指定与实际Activity上的权限不同的权限集。您还可以指定不同的launchMode、不同的<intent-filter>等等。
https://stackoverflow.com/questions/65869949
复制相似问题