android activity protection from intent

1.5k views Asked by At

I'm trying to develop an app with login and providing OTP(one time password) with connection to a web service, but while testing I was able to starting the activities through adb shell in the emulator even without logging in, i.e. by using fully specified path and passing intents. this leaves the app venerable to be opened by other apps with out logging in. is it possible to protect the activities from starting through intents outside the app.

below is the piece of manifest code.

    <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>
1

There are 1 answers

0
Darpan On

Your day saver is -

android:exported = "false"

Documentation says -

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.