4

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.REQUEST_RESPONSE");
i.putExtra("info", "bla bla bla");
startActivityForResult(i, 0);

In app B I have the following activity in the manifest:

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

and this in the activity's onCreate:

Intent intent = getIntent();
if (intent.getAction().equals("com.example.test2.REQUEST_RESPONSE")) {
    Log.e("Received", "Intent received thank you!");
}

With this I receive the following error:

01-18 12:30:44.950: E/AndroidRuntime(31200): FATAL EXCEPTION: main
01-18 12:30:44.950: E/AndroidRuntime(31200): java.lang.RuntimeException: Unable to     resume activity {com.example.test/com.example.test.MainActivity}:     java.lang.SecurityException: Permission Denial: starting Intent { act=example.test2.REQUEST_RESPONSE cmp=example.test2/.Receiving (has extras) } from ProcessRecord{41ae02d8 31200:com.example.test/u0a10107} (pid=31200, uid=10107) not exported from uid 10115
01-18 12:30:44.950: E/AndroidRuntime(31200):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2742)
01-18 12:30:44.950: E/AndroidRuntime(31200):    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2771)
01-18 12:30:44.950: E/AndroidRuntime(31200):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2235)
01-18 12:30:44.950: E/AndroidRuntime(31200):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-18 12:30:44.950: E/AndroidRuntime(31200):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-18 12:30:44.950: E/AndroidRuntime(31200):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-18 12:30:44.950: E/AndroidRuntime(31200):    at android.os.Looper.loop(Looper.java:137)
01-18 12:30:44.950: E/AndroidRuntime(31200):    at android.app.ActivityThread.main(ActivityThread.java:5039)
01-18 12:30:44.950: E/AndroidRuntime(31200):    at java.lang.reflect.Method.invokeNative(Native Method)
01-18 12:30:44.950: E/AndroidRuntime(31200):    at java.lang.reflect.Method.invoke(Method.java:511)
01-18 12:30:44.950: E/AndroidRuntime(31200):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-18 12:30:44.950: E/AndroidRuntime(31200):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-18 12:30:44.950: E/AndroidRuntime(31200):    at dalvik.system.NativeStart.main(Native Method)
01-18 12:30:44.950: E/AndroidRuntime(31200): Caused by: java.lang.SecurityException: Permission Denial: starting Intent { act=com.example.test2.REQUEST_RESPONSE cmp=com.example.test2/.Receiving (has extras) } from ProcessRecord{41ae02d8 31200:com.example.test/u0a10107} (pid=31200, uid=10107) not exported from uid 10115
01-18 12:30:44.950: E/AndroidRuntime(31200):    at android.os.Parcel.readException(Parcel.java:1425)
01-18 12:30:44.950: E/AndroidRuntime(31200):    at android.os.Parcel.readException(Parcel.java:1379)
01-18 12:30:44.950: E/AndroidRuntime(31200):    at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1870)
01-18 12:30:44.950: E/AndroidRuntime(31200):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1412)
01-18 12:30:44.950: E/AndroidRuntime(31200):    at android.app.Activity.startActivityForResult(Activity.java:3370)
01-18 12:30:44.950: E/AndroidRuntime(31200):    at android.app.Activity.startActivityForResult(Activity.java:3331)
01-18 12:30:44.950: E/AndroidRuntime(31200):    at com.example.test.MainActivity.onResume(MainActivity.java:125)
01-18 12:30:44.950: E/AndroidRuntime(31200):    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1185)
01-18 12:30:44.950: E/AndroidRuntime(31200):    at android.app.Activity.performResume(Activity.java:5182)
01-18 12:30:44.950: E/AndroidRuntime(31200):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2732)
01-18 12:30:44.950: E/AndroidRuntime(31200):    ... 12 more

If I remove the category from the intent filter I get this error instead:

01-18 12:21:03.059: E/AndroidRuntime(30865): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.test2.REQUEST_RESPONSE (has extras) }

Any ideas?

Sahil Mahajan Mj
  • 11,033
  • 8
  • 53
  • 100
just_user
  • 11,769
  • 19
  • 90
  • 135
  • 2
    Just a thought, Are you handling the results properly.? and why dont you use **Intent i =new Intent(this, NextActivity.class)**.? why is exported tag **false**.? – Sahil Mahajan Mj Jan 18 '13 at 12:24
  • Doesn't Intent i = new Intent(this, NextActivity.class) mean the class has to be in the same app? If so its exactly what i dont want. – just_user Jan 18 '13 at 12:53
  • first thing I havent downvoted. Second, stop humiliating someone, who is trying to help you out. If asking something for one to clarfiy doubts to solve your problem is just you dont want, then its okay. – Sahil Mahajan Mj Jan 18 '13 at 12:59
  • Sorry, you're right! About your intent suggestion am I right if it means the class has to be in the same app? I'm trying to get my head around this! – just_user Jan 18 '13 at 13:03

2 Answers2

13

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.

TNR
  • 5,839
  • 3
  • 33
  • 62
  • Thanks Nagaraj436 that did it! But I keep getting a warning when I dont have exported false, permission something. – just_user Jan 18 '13 at 12:52
0

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 :)

Anas Reza
  • 646
  • 2
  • 9
  • 28