如何使用导航组件在单个活动设计权限工作?



我之前的应用程序有许多活动,其中一些被声明为导出为true,以便其他应用程序可以通过意图过滤器调用它们。其中一些还具有特定的权限,这些权限也设置在我的活动中。

现在,我正在开发一个应用程序使用单一的活动。所以,我很想知道如何在单个活动设计中处理此权限问题,因为我只有一个活动。

以前,在多个活动中,我可以很容易地设置特定活动的权限。我在这里怎么处理?我是一个新手。我找了很多,但没有找到任何线索。

编辑:

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>

如果您想在某些情况下限制单个Activity的启动,而不是在其他情况下,则不能使用基于清单的权限。基于清单的权限控制对特定Activity的访问,而不管它是如何启动的。

您可以做的是为单个Activity创建一个<activity-alias><activity-alias>是一个清单条目,它引用了实际的Activity,但提供了其他启动选项。您可以在<activity-alias>上指定与实际Activity上不同的一组权限。您还可以指定不同的launchMode,不同的<intent-filter>等。

最新更新