'Restrict your android activity to be accessible from other activity
I have an Android activity defined in my Manifest:
<activity
android:name=“com.me.myapp.myactivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myapp" />
</intent-filter>
</activity>
I want to restrict this activity to be accessible only to one other activity outside my app, let's call that activity "com.others.theirapp.theiractivity". How do I accomplish this restriction?
I do not have any information about the other app and its activity, the only information I have is its activity name, "com.others.theirapp.theiractivity".
Solution 1:[1]
There is basically two ways to handle this
If other app is invoking you app with
startActivityForResultthen you can usegetCallingPackage()to get and check calling app package nameOther way is that you can pass a unique id in intent from calling activity to you activity and check its matching or not to ensure that its a trusted call (You have to secure this unique id so that other user can't spoof it)
Solution 2:[2]
Permissions applied using the android:permission attribute to the tag in the manifest restrict who can start that Activity. The permission is checked during Context.startActivity() and Activity.startActivityForResult(). If the caller doesn't have the required permission, then a SecurityException occurs.
Solution 3:[3]
In Manifest you can use Exported to false if that helps
<activity
android:name=".UpdateActivity"
android:exported="false"
android:parentActivityName=".HomeActivity"
android:screenOrientation="portrait"/>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pwn |
| Solution 2 | Amirhosein Heydari |
| Solution 3 | Dkathayat1 |
