- Home /
How to handle an intent from another Android App in Unity?
I have an Android app, in which I send a message via a Intent.Action_SEND
filter. I've tried many things but I always get the error: No Activity found to handle Intent
. What am I doing wrong?
Android app code, proven to work on another Android app:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setPackage(appName);
sendIntent.putExtra("TABSINT_DATA_JSON_STRING", data);
sendIntent.setType("text/plain");
sendIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activityContext.startActivity(sendIntent);
I created a Receiver.java script in Unity to handle the intent:
package com.company.pkg;
import ...;
public class Receiver extends Activity {
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
String action = intent.getAction();
Log.d(TAG,"Java Receiver intent action: "+action);
}
}
I added the .Receiver activity in my AndroidManifest.xml
<intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LEANBACK_LAUNCHER" /> </intent-filter> <meta-data android:name="unityplayer.UnityActivity" android:value="true" /> </activity> <activity android:name="com.company.pkg.Receiver" android:label="@string/Receiver" android:parentActivityName="com.unity3d.player.UnityPlayerActivity" android:launchMode="singleTask"> <intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="text/plain"/> </intent-filter> </activity> ... </application> ...
@Antique @Zyosoft @Onizuka101 @angusmf
hi man! I'm stuck with the same problem tried a lot of options like making a separate plugin and also making a C# script still couldn't solve it let me know if you have got it. cheers!!
$$anonymous$$y problem was in the Android$$anonymous$$anifest. I had to put the manifest in the correct folder (Assets/Plugins/Android) for Unity to merge it.
Answer by hexagonius · Nov 09, 2018 at 09:39 PM
is this something for you? the answer is von Zyosoft:
https://answers.unity.com/questions/1327186/how-to-get-intent-data-for-unity-to-use.html
Thank you for your answer @hexagonius. I am trying to get the intent in java ins$$anonymous$$d of in C# to have more flexibility on the Native layer, so the answer you refer to is not quite it. There are other answers on the web using that strategy.
$$anonymous$$y problem was in the Android$$anonymous$$anifest. I fixed it: I had to put the manifest in the correct folder (Assets/Plugins/Android) for Unity to merge it. Thanks anyways!