1

My previous app has many activities and some of them are declared as exported true, so that other apps can call them through intent filter. Some of them also has specific permission which also sets in my activities.

Now, i am developing a app using single activity. So, i am curious to know how can i handle this permission issue in single activity design, as i have only one activity.

Previously, in multiple activities i can easily set permission in specific activity. How can i handle this here? I am a newbie. I searched a lot but did not find any clue.

Edit:

    Multiple activities declaration:

    <permission
      android:name="com.example.permission"
      android:protectionLevel="signatureOrSystem"
      tools:ignore="SignatureOrSystemPermissions" 
    />

    // Activity 1: With permission, exported = true
    <activity
        android:name=".place"
        android:configChanges="keyboardHidden|orientation|screenSize|screenLayout"
        android:exported="true"
        android:label="place"
        android:permission="com.example.permission" // Sets a permission
        android:theme="@style/Theme.AppCompat.DayNight.NoActionBar">
        <intent-filter>

            <action android:name="com.action.places" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

    // Activity 2: With no permission, exported = true

      <activity
        android:name="userCheck"
        android:configChanges="mcc|mnc|keyboard|keyboardHidden|orientation"
        android:exported="true"
        android:theme="@style/Theme.AppCompat.DayNight.NoActionBar">
        <intent-filter>
            <action android:name="com.confirm.passowrd" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
     </activity>

Now, i want to move to single activity.

   // Single activity: exported = true. How can i handle permission for place action?
    <activity
        android:name="com.example.singleActivity"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <!-- Place -->
            <action android:name="com.action.places"/> // How can i handle permission for this action?

            <!-- UserCheck -->
            <action android:name="com.confirm.passowrd" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
   
David Wasser
  • 93,459
  • 16
  • 209
  • 274
Mohsin
  • 55
  • 1
  • 6
  • I don't really understand your question. If your app has only one `Activity` then you need to request all your permissions from that `Activity`. Or are you asking about your own custom permissions needed to access your activities? Please edit your question and give us an example of what you are having trouble with. – David Wasser Jan 24 '21 at 16:01
  • @DavidWasser Please check now – Mohsin Jan 25 '21 at 05:10

1 Answers1

1

You can't use manifest-based permissions if you want to restrict a single Activity from being launched in some cases but not others. The manifest-based permission controls access to the specific Activity, no matter how it is being launched.

What you could do is create an <activity-alias> for your single Activity. An <activity-alias> is a manifest entry that references an actual Activity, but provides alternate launch options. You can specify a different set of permissions on the <activity-alias> than the ones you have on the actual Activity. You can also specify different launchMode, different <intent-filter>, etc.

David Wasser
  • 93,459
  • 16
  • 209
  • 274
  • I have faced another issue in single activity design. Would you please help me? https://stackoverflow.com/questions/65625479/how-to-work-with-preference-in-single-activity-design-using-navigation-component – Mohsin Jan 25 '21 at 15:13
  • I am facing an issue with permission for actvity-alias. Would you please check this ? https://stackoverflow.com/questions/65889015/how-to-start-activity-alias-of-another-app-which-has-permission – Mohsin Jan 25 '21 at 16:55