如何防止其他android应用程序访问我的活动

时间:2022-08-25 16:47:51

I have an android app in which I define several different activities in the manifest. Some of these activities have intent-filters that I use (such as ACTION_PICK). These activities, because of the intent-filters, show up when other applications request an activity to handle an ACTION_PICK. Is there some way to prevent this, so that my activities are not accessible to other applications? I've already tried setting android:exported="false" in my activity, but that did nothing.

我有一个android应用程序,在其中我在清单中定义了几个不同的活动。其中一些活动有我使用的意图过滤器(例如ACTION_PICK)。由于意图过滤器的原因,当其他应用程序请求处理ACTION_PICK的活动时,这些活动就会出现。有什么方法可以防止这种情况,使我的活动不能被其他应用程序访问?我已经尝试过在我的活动中设置android: exports =“false”,但是没有。

1 个解决方案

#1


13  

You need to:
* define a permission (which is only available to applications having your signature)
* define that your application uses your defined permission
* require that permission for the activities you want protected. (Be careful to not require it for your main launch activity).

您需要:*定义一个权限(仅对有您签名的应用程序可用)*定义您的应用程序使用您定义的权限*要求您希望保护的活动具有该权限。(注意不要在你的主要发布活动中使用它)。

<!-- define a permission -->
<permission
    android:protectionLevel="signature"
    android:name="com.mypackage.MYPERMISSION"/>

<uses-permission android:name="com.mypackage.MYPERMISSION" />

<!-- define an activity which can only be started through internal code -->
<activity android:name="..."
          android:permission="com.mypackage.MYPERMISSION" >
    ...
</activity>

#1


13  

You need to:
* define a permission (which is only available to applications having your signature)
* define that your application uses your defined permission
* require that permission for the activities you want protected. (Be careful to not require it for your main launch activity).

您需要:*定义一个权限(仅对有您签名的应用程序可用)*定义您的应用程序使用您定义的权限*要求您希望保护的活动具有该权限。(注意不要在你的主要发布活动中使用它)。

<!-- define a permission -->
<permission
    android:protectionLevel="signature"
    android:name="com.mypackage.MYPERMISSION"/>

<uses-permission android:name="com.mypackage.MYPERMISSION" />

<!-- define an activity which can only be started through internal code -->
<activity android:name="..."
          android:permission="com.mypackage.MYPERMISSION" >
    ...
</activity>