- Home /
This question was
closed Nov 11, 2017 at 11:06 PM by
Amitbuc for the following reason:
Other
Unity can't receive information from Intent *urgent
Hi, I really hope someone here is familiar with this issue... I've created a simple unity project, It should receive a string from an Intent (for example - share a message/text/link from another app to this app, and get the shared string in Unity) I've created the .jar, extended UnityPlayerActivity, and overrided the AndroidManifest, but the app keep crashing when a text/string is shared to the app. I debugged the java file, and it gets the string from the intent, and then crashes for some reason. And on top of that, the error I get doesn't provide any useful information to work on.
Error
11-04 22:38:56.451: A/DEBUG(24464): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
11-04 22:38:56.452: A/DEBUG(24464): Build fingerprint: 'samsung/nobleltejv/noblelte:7.0/NRD90M/N920CXXU3CQG3:user/release-keys'
11-04 22:38:56.452: A/DEBUG(24464): Revision: '9'
11-04 22:38:56.452: A/DEBUG(24464): ABI: 'arm'
11-04 22:38:56.452: A/DEBUG(24464): pid: 24232, tid: 24461, name: UnityMain >>> asoscompare.clever.com.libraryunity2 <<<
11-04 22:38:56.452: A/DEBUG(24464): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
11-04 22:38:56.452: A/DEBUG(24464): r0 00000000 r1 c8f80b18 r2 00000000 r3 00000005
11-04 22:38:56.452: A/DEBUG(24464): r4 c246e008 r5 cc87dcd0 r6 cc87d310 r7 cc87dcd0
11-04 22:38:56.452: A/DEBUG(24464): r8 00d4aff0 r9 00000001 sl cc87d2e8 fp cc87d310
11-04 22:38:56.452: A/DEBUG(24464): ip cc735e6c sp c8f7f760 lr cb9f02b0 pc cbb313a4 cpsr 400f0010
11-04 22:38:56.454: A/DEBUG(24464): backtrace:
11-04 22:38:56.464: A/DEBUG(24464): #00 pc 005b43a4 /data/app/asoscompare.clever.com.libraryunity2-1/lib/arm/libunity.so
11-04 22:38:56.464: A/DEBUG(24464): #01 pc 005b4720 /data/app/asoscompare.clever.com.libraryunity2-1/lib/arm/libunity.so
11-04 22:38:56.464: A/DEBUG(24464): #02 pc 005bf998 /data/app/asoscompare.clever.com.libraryunity2-1/lib/arm/libunity.so
11-04 22:38:56.464: A/DEBUG(24464): #03 pc 0001947b /data/app/asoscompare.clever.com.libraryunity2-1/oat/arm/base.odex (offset 0x18000)
MainActivity.Java:
public class MainActivity extends UnityPlayerActivity {
protected void onCreate(Bundle savedInstanceState) {
// call UnityPlayerActivity.onCreate()
super.onCreate(savedInstanceState);
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
if ("text/plain".equals(type)) {
handleSendText(intent); // Handle text being sent
}
}
}
void handleSendText(Intent intent) {
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText != null) {
UnityPlayer.UnitySendMessage("AccessManager","OnAccessToken", "hi");
}
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="asoscompare.clever.com.libraryunity2" xmlns:tools="http://schemas.android.com/tools" android:versionName="1.0" android:versionCode="1" android:installLocation="preferExternal">
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
<application android:theme="@StyLe/UnityThemeSelector" android:icon="@drawable/app_icon" android:label="@String/app_name" android:debuggable="false" android:isGame="true" android:banner="@drawable/app_banner">
<activity
android:name=".MainActivity"
android:label="@String/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
<meta-data android:name="unity.build-id" android:value="bfcf807c-0086-4c30-8b6e-5b42ad571eb7" />
<meta-data android:name="unity.splash-mode" android:value="0" />
<meta-data android:name="unity.splash-enable" android:value="True" />
<meta-data android:name="android.max_aspect" android:value="2.1" />
</application>
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="25" />
<uses-feature android:glEsVersion="0x00020000" />
<uses-feature android:name="android.hardware.vulkan" android:required="false" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
</manifest>
AccessManager.cs:
public class AccessManager : MonoBehaviour
{
public void OnAccessToken(string accessToken)
{
// The app crashes before getting here! (it doesn't get here)
Debug.Log("Unity Message Received!!!! :" + accessToken);
}
}
Comment