kobakei / unity-gcm

Unity plugin for Google Cloud Messaging (GCM)
59 stars 34 forks source link

Native method not found: com.unity3d.player.UnityPlayer.UnitySendMessage #1

Open otsuga opened 11 years ago

otsuga commented 11 years ago

First thanks for this asset!

When i receive a message when the application is closed im getting this error on logcat.

E/AndroidRuntime(3480): Caused by: java.lang.UnsatisfiedLinkError: Native method not found: com.unity3d.player.UnityPlayer.UnitySendMessage:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;) 08-08 16:20:45.005: E/AndroidRuntime(3480): at com.kskkbys.unitygcmplugin.Util.sendMessage(Util.java:22) 08-08 16:20:45.005: E/AndroidRuntime(3480): at com.kskkbys.unitygcmplugin.Util.sendMessage(Util.java:22) 08-08 16:20:45.005: E/AndroidRuntime(3480): at com.kskkbys.unitygcmplugin.UnityGCMIntentService.onMessage(UnityGCMIntentService.java:50)

kobakei commented 11 years ago

@otsuga Thank you for your reporting issue. The issue has been fixed by this commit https://github.com/kskkbys/unity-gcm/commit/002b7c8056b189b38c6ce32ddcc2ba9520ac6906 Please try the latest version of master branch.

otsuga commented 11 years ago

Thanks for the fix Keisuke.

But when the application is closed and I send a gcm push nothing happens now. I was expecting to appear the toast message, but nothing happens.

The warning in the logcat is:

08-09 10:06:04.655: W/dalvikvm(14723): No implementation found for native Lcom/unity3d/player/UnityPlayer;.UnitySendMessage:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V 08-09 10:06:04.655: W/System.err(14723): java.lang.UnsatisfiedLinkError: Native method not found: com.unity3d.player.UnityPlayer.UnitySendMessage:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V 08-09 10:06:04.655: W/System.err(14723): at com.unity3d.player.UnityPlayer.UnitySendMessage(Native Method) 08-09 10:06:04.655: W/System.err(14723): at com.kskkbys.unitygcmplugin.Util.sendMessage(Util.java:23) 08-09 10:06:04.655: W/System.err(14723): at com.kskkbys.unitygcmplugin.UnityGCMIntentService.onMessage(UnityGCMIntentService.java:50) 08-09 10:06:04.655: W/System.err(14723): at com.google.android.gcm.GCMBaseIntentService.onHandleIntent(GCMBaseIntentService.java:223) 08-09 10:06:04.655: W/System.err(14723): at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65) 08-09 10:06:04.655: W/System.err(14723): at android.os.Handler.dispatchMessage(Handler.java:99) 08-09 10:06:04.655: W/System.err(14723): at android.os.Looper.loop(Looper.java:213) 08-09 10:06:04.655: W/System.err(14723): at android.os.HandlerThread.run(HandlerThread.java:60)

kobakei commented 11 years ago

Maybe this issue is caused by that Unity's DLL has not been loaded when GCM is received. To fix this issue, UnitySendMessage should be postponed until DLL will be loaded.

ghost commented 10 years ago

Hi, Thanks for sharing such nice plugin for unity. I've been using this plugin for last few days but not able send figure out how to send GCM. The following code is suppose to be used for GCM notification,

require 'gcm'

API_KEY = "INPUT_YOUR_API_KEY";

REGISTRATION_ID = "INPUT_YOUR_REGISTRATION_ID";

gcm = GCM.new(API_KEY) registration_ids = [REGISTRATION_ID] # an array of one or more client registration IDs options = { data: { score: 123, is_first: true, foo: "bar",

For notification view on status bar

ticker: "Ticker text",
content_title: "Content Title",
content_text: "Content Text"

}, collapse_key: "updated_score" } response = gcm.send_notification(registration_ids, options)

how to use above code snippet in unity C#? thanks

alienhaxor commented 9 years ago

I also get an error like this. No idea what causes it. I posted the logcat to SO.

I receive the notification to the device but the app does not start.

http://stackoverflow.com/questions/28052802/gcm-notification-received-on-device-does-not-start-the-application

LeshM commented 9 years ago

I found out that the gcm plugin is setting a specific unity activity as the pending intent of the notification. As soon as I added the activity to my AndroidManifest.xml it worked!

These are the activities I defined:

<activity android:name="com.unity3d.player.UnityPlayerProxyActivity"
          android:launchMode="singleTask"
          android:label="@string/app_name"
          android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>
<activity android:name="com.unity3d.player.UnityPlayerActivity"
          android:launchMode="singleTask"
          android:label="@string/app_name"
          android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
</activity>
<activity android:name="com.unity3d.player.UnityPlayerNativeActivity"
          android:launchMode="singleTask"
          android:label="@string/app_name"
          android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
  <meta-data android:name="android.app.lib_name" android:value="unity" />
  <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
  <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
alienhaxor commented 9 years ago

@LeshM: How did you find out about the specific unity activity?

LeshM commented 9 years ago

I dug into the java code :)

alienhaxor commented 9 years ago

The only relevant activity I can find is

private static final String SERVICE_NAME = "com.kskkbys.unitygcmplugin.UnityGCMIntentService";

in UnityGCMBroadcastReceiver.java.

I have that in my AndroidManifest.xml as : service android:name="com.kskkbys.unitygcmplugin.UnityGCMIntentService" /

edit: I should probably create a different issue because my problem is the following error: Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1505 com.android.server.StatusBarManagerService.sendNotification:985 com.android.server.StatusBarManagerService.removeNotification:710 com.android.server.NotificationManagerService.cancelNotificationLocked:2469 com.android.server.NotificationManagerService.access$5100:162

LeshM commented 9 years ago

Here: // Intent Intent intent = new Intent(context, UnityPlayerProxyActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(context, REQUEST_CODE_UNITY_ACTIVITY, intent, PendingIntent.FLAG_UPDATE_CURRENT);

https://github.com/kobakei/unity-gcm/blob/master/source/UnityGcmPlugin/src/com/kskkbys/unitygcmplugin/UnityGCMNotificationManager.java

alienhaxor commented 9 years ago

@LeshM I defined the missing activities based on the ones you posted here. Now the app starts when I tap the notification. Your help was invaluable. Thank you.

I noticed that the errors in logcat are still present. This issue didn't seem to have anything to do with the erros.

LeshM commented 9 years ago

Glad I could help ^_^

Skatola commented 9 years ago

Excuse me... Cancerballs what did u exactly? I have the same problem, notification does not start the app... but i don't understand what i have to do for let it work : ( Seems like LeshM give you a java string and solved this problem...where i have to copy that? Sorry i'm a novice unity developer and really need your help : )

alienhaxor commented 9 years ago

@Skatola See LeshM's comment for activities to be defined in the android manifesto.

Skatola commented 9 years ago

@cancerballs Thank you for your reply : ) I have no experience in java and i have trouble to edit the manifest myself, u find the missing activities tnx to LeshM's post, but what exactly have u added in your manifest? I simply don't understand what that string means, i barely know c# for unity basic scripting : ) Really appreciate your help, thank you

Skatola commented 9 years ago

ok new problem : D with the new activities the app start when the notification is tapped, but if the app is already started or it's in background it crash and start again...any solution? :\

pgilmorepf commented 7 years ago

Sorry, this is somewhat unrelated, but this is the only place I've found this: REQUEST_CODE_UNITY_ACTIVITY = 1001; and PendingIntent.getActivity(intent, REQUEST_CODE_UNITY_ACTIVITY, ...

Why? What's magical about 1001? That value doesn't show up anywhere else (Like the Unity Documentation), and I can't find any other explanation about why that works, it just does.