在设备上收到的GCM通知无法启动该应用程序

时间:2015-01-20 18:40:22

标签: android unity3d google-cloud-messaging

我在Unity3D中使用https://github.com/kobakei/unity-gcm进行GCM通知。我在设备上收到消息。当我点击通知时没有任何反应。我希望应用程序能够启动。这是日志:

V/GCMRegistrar( 8441): Setting the name of retry receiver class tocom.kskkbys.unitygcmplugin.UnityGCMBroadcastReceiver
V/UnityGCMBroadcastReceiver( 8441): getGCMIntentServcieClassName
V/GCMBroadcastReceiver( 8441): GCM IntentService class: com.kskkbys.unitygcmplugin.UnityGCMIntentService
V/GCMBaseIntentService( 8441): Acquiring wakelock
D/ConnectivityService(  845): handleInetConditionHoldEnd: net=0, condition=100, published condition=100
V/GCMBaseIntentService( 8441): Intent service name: GCMIntentService-DynamicSenderIds-1
D/STATUSBAR-NetworkController( 1051): onReceive() - CONNECTIVITY_ACTION, INET_CONDITION_ACTION
V/UnityGCMIntentService( 8441): onMessage
V/UnityGCMIntentService( 8441): ticker: ticker
D/STATUSBAR-NetworkController( 1051): getUpdateDataNetType() - mDataNetType:15
D/STATUSBAR-NetworkController( 1051): updateDataNetType()
D/STATUSBAR-NetworkController( 1051): Nothing, mRoamingIconId = 0
V/UnityGCMIntentService( 8441): foo: bar
V/UnityGCMIntentService( 8441): from: xxxxx
V/UnityGCMIntentService( 8441): content_title: New Friend Request
V/UnityGCMIntentService( 8441): score: 123
V/UnityGCMIntentService( 8441): is_first: true
V/UnityGCMIntentService( 8441): content_text: test
V/UnityGCMIntentService( 8441): collapse_key: do_not_collapse
D/dalvikvm( 8441): Trying to load lib /data/app-lib/com.company.app-23/libmain.so 0x42587730
D/dalvikvm( 8441): Added shared lib /data/app-lib/com.company.app-23/libmain.so 0x42587730
W/dalvikvm( 8441): No implementation found for native Lcom/unity3d/player/UnityPlayer;.UnitySendMessage:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
W/System.err( 8441): java.lang.UnsatisfiedLinkError: Native method not found: com.unity3d.player.UnityPlayer.UnitySendMessage:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
W/System.err( 8441):    at com.unity3d.player.UnityPlayer.UnitySendMessage(Native Method)
W/System.err( 8441):    at com.kskkbys.unitygcmplugin.Util.sendMessage(Util.java:23)
W/System.err( 8441):    at com.kskkbys.unitygcmplugin.UnityGCMIntentService.onMessage(UnityGCMIntentService.java:50)
W/System.err( 8441):    at com.google.android.gcm.GCMBaseIntentService.onHandleIntent(GCMBaseIntentService.java:223)
W/System.err( 8441):    at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
W/System.err( 8441):    at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err( 8441):    at android.os.Looper.loop(Looper.java:136)
W/System.err( 8441):    at android.os.HandlerThread.run(HandlerThread.java:61)
V/UnityGCMNotificationManager( 8441): showNotification
V/GCMBaseIntentService( 8441): Releasing wakelock
W/ContextImpl(  845): 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.addNotification:674 com.android.server.NotificationManagerService$7.run:2157 android.os.Handler.handleCallback:733

W/ContextImpl(  845): 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 
D/STATUSBAR-StatusBarManagerService(  845): sendNotification(3) - 1

修改 的AndroidManifest.xml:

<!-- Android GCM Plugin -->
<receiver android:name="com.kskkbys.unitygcmplugin.UnityGCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" >
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
        <category android:name="com.company.application" />
    </intent-filter>
</receiver>
<service android:name="com.kskkbys.unitygcmplugin.UnityGCMIntentService" />
<!-- Android GCM Plugin -->

</application>

<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"    />


<!-- Android GCM Plugin -->
<permission android:name="com.company.application.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.company.application.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<!-- Android GCM Plugin -->

EDIT2: 这是当我触摸通知图标并期望应用程序启动时logcat中出现的错误。

 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 

2 个答案:

答案 0 :(得分:0)

查看您的logcat,看起来您的NotificationListenerService无法正常工作,因为它可以正常工作。由于您没有提供代码,您可以尝试这些可能的解决方案,以确保收到的广播作为通知正确处理,并点击通知打开相关活动。

  • 您的设备可能存在某种冲突。处理此问题的最佳方法是清理一些空间并从Google Play重新安装该应用。
  • 使用以下函数代替sendBroadcast(Intent intent)。

    void sendBroadcastAsUser(Intent intent,UserHandle用户) 例如,

    context.sendBroadcastAsUser(newIntent,new UserHandle(UserHandle.USER_CURRENT));

  • 确保您在应用清单文件中拥有适当的权限。

    <manifest package="com.example.gcm" ...> 
        <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17"/>
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission         android:name="android.permission.GET_ACCOUNTS" />
        <uses-permission android:name="android.permission.WAKE_LOCK" />
        <uses-permission   android:name="com.google.android.c2dm.permission.RECEIVE" />
    
    <permission android:name="com.example.gcm.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />
    
    <application ...>
        <receiver
            android:name=".GcmBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="com.example.gcm" />
            </intent-filter>
        </receiver>
        <service android:name=".GcmIntentService" />
    </application>
    
    </manifest>
    
  • 按照this文档中的说明了解有关客户端实施的更多信息。

希望这会有所帮助!!

答案 1 :(得分:0)

问题中的logcat错误与不是从通知开始的应用程序没有任何关系。

LeshM @ https://github.com/kobakei/unity-gcm/issues/1

解决了这个问题
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>