如何防止其他Android应用访问我的活动 [英] How do I prevent other android apps from accessing my activities
问题描述
我有一个android应用,其中我在清单中定义了几种不同的活动.其中一些活动具有我使用的意图过滤器(例如ACTION_PICK).由于意图过滤器,这些活动将在其他应用程序请求活动来处理ACTION_PICK时显示.有什么方法可以防止这种情况发生,以便其他应用程序无法访问我的活动?我已经尝试在我的活动中设置android:exported ="false",但这无济于事.
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.
推荐答案
您需要:
*定义权限(仅适用于具有您签名的应用程序)
*定义您的应用程序使用您定义的权限
*需要您想要保护的活动的许可. (请注意不要在主要启动活动中使用它.)
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>
这篇关于如何防止其他Android应用访问我的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!