trying to send intent to other app: error SecurityException: Permission Denial: starting Intent

前端 未结 2 1506
温柔的废话
温柔的废话 2020-12-21 08:30

I\'m trying to send an intent from app A to app B. In the activity of app A I do the following:

Intent i = new Intent();
i.setAction(\"com.example.test2.REQU         


        
相关标签:
2条回答
  • 2020-12-21 09:04

    Change Activity Manifest Tag as below so that it opens the Second App.

    <activity android:name=".Receiving"
            android:label="@string/app_name"
            android:exported="true" >
            <intent-filter>
                <action android:name="com.example.test2.REQUEST_RESPONSE" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    

    The reason it is Crashing is because you set android:exported="false" which mean that other process cannot access this Activity. So you set it to true and do the same it will not crash.

    0 讨论(0)
  • 2020-12-21 09:07

    Its upto you that you have to show the activity of the other app.If you call another app's activity class it will bring that activity class in front but in one of my project I have called BroadCastReceiver that will be working on background..

    This is how you register your receiver in manifest file and give that receiver a URL SCHEME in intent filter

        <receiver android:name="com.example.exampleapp.ExampleReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
    
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.LAUNCHER" />
    
                <data android:scheme="receiver" />
            </intent-filter>
        </receiver>
    

    Now open an Intent from in a app A

        Intent mainIntent = new Intent();
        mainIntent = new Intent(Intent.ACTION_VIEW);
        mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mainIntent.setData(Uri.parse("receiver://123"));
        context.sendBroadcast(mainIntent);
    

    This setData passes the data to other app's like put extra do for passing the data to another class.

    I hope this helps you out :)

    0 讨论(0)
提交回复
热议问题