Question

so my main problem is starting a new app with an implicit intent. So here is the activity that is supposed to start the nem app:

package course.labs.permissionslab;
public class GoToDangerousActivity extends Activity {

private static final String TAG = "Lab-Permissions";

private static final String DANGEROUS_ACTIVITY_ACTION = "course.labs.permissions.DANGEROUS_ACTIVITY_PERM";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.go_to_dangerous_activity);

    Button startDangerousActivityButton = (Button) findViewById(R.id.start_dangerous_activity_button);
    startDangerousActivityButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            startDangerousActivity();

        }
    });

}

private void startDangerousActivity() {

    Log.i(TAG, "Entered startDangerousActivity()");
    Intent dangerActivation = Intent.createChooser(new Intent(DANGEROUS_ACTIVITY_ACTION), "Choose yo..");
    startActivity(dangerActivation);

}

}

I just added the appChoser so my my app doesnt break instantly. Now by strting the implicit intent "course.labs.permissions.DANGEROUS_ACTIVITY_PERM", what do I need to add to the other apps intent filters?? I will leave a copy of the other apps Manifest.XML to help spot the problem:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="course.labs.dangerousapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="13"
        android:targetSdkVersion="18" />

    <!--
          TODO - Using a permission element,
          define a custom permission with name
              "course.labs.permissions.DANGEROUS_ACTIVITY_PERM" 
          and "dangerous" protection level.
    -->
    <permission 
        android:protectionLevel="dangerous" 
        android:name="course.labs.permissions.DANGEROUS_ACTIVITY_PERM">
    </permission>

    <uses-permission android:name="course.labs.permissions.DANGEROUS_ACTIVITY"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <!-- TODO - enforce the custom permission on this Activity -->

        <activity
            android:name=".DangerousActivity"
            android:label="@string/app_name">

            <!--
                 TODO - add additional intent filter info so that this Activity
                  will respond to an Implicit Intent with the action
                  "course.labs.permissions.DANGEROUS_ACTIVITY"
            -->


            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

            <intent-filter>
                <action android:name="course.labs.permissions.DANGEROUS_ACTIVITY_PERM" />
                <category android:name="android.intent.category.DEFAULT" /> 
            </intent-filter>

        </activity>
    </application>

</manifest>
Was it helpful?

Solution

First of all,

<uses-permission android:name="course.labs.permissions.DANGEROUS_ACTIVITY_PERM"/>

this should be in the app that you want to access this app.

let's say you have app A and you want to open Dangerous App, you put this permission usage to in A's manifest file.

Second :

You also need to tell application about permission. Add this permission to application.

<application
    android:permission="course.labs.permissions.DANGEROUS_ACTIVITY_PERM"
    <!-- your other attributes --> 
>

Third :

Intent filter should link to Activity not the permission string.

      <intent-filter>
            <action android:name="course.labs.permissions.DANGEROUS_ACTIVITY" />
            <category android:name="android.intent.category.DEFAULT" />
      </intent-filter>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top