我正在尝试开发一个带有登录并提供 OTP(一次性密码)连接到 Web 服务的应用程序,但在测试时我能够通过模拟器中的 adb shell 启动 Activity ,即使没有登录,即通过使用完全指定的路径和传递 Intent 。这使得该应用程序很容易被其他应用程序打开而无需登录。是否可以保护 Activity 不通过应用程序外部的 Intent 启动。
下面是一段 list 代码。
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".LoginActivity"
android:label="@string/login" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".The1Activity" >
</activity>
<activity android:name=".The2Activity" >
</activity>
最佳答案
您的一天节省时间是 -
android:exported = "false"
Whether or not the activity can be launched by components of other applications — "true" if it can be, and "false" if not. If "false", the activity can be launched only by components of the same application or applications with the same user ID.
关于android Activity 保护免受 Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26879431/