Worklight 6.2 Android Application not launching on

2019-03-03 10:25发布

问题:

I am attempting to get push notifications to work on an Android environment app written in Worklight 6.2. I have gotten the app to receive push notifications, but when I tap on the notification in the status bar, it clears the notification but does not launch the app.

I have looked at the answer here, IBM Worklight 5.0.6.1 - Not getting Push Notifications when phone/app is closed, but changing the app_name string back to the original name of the app, as the accepted answer suggests, does not cause the app to launch. I also tried another one of the comments suggestions to remove embedded spaces from the displayName in the app descriptor, and that also did not work.

I've watched the logcat and do not see any messages to indicate that it failed to find an app to launch. I was hoping something in there would give me a hint as to what it is looking for, but no luck.

Is there another setting somewhere that has gotten out of sync so that clicking the notification does not launch the app? I cannot find anything else myself (probably because it doesn't exist).

Thanks

回答1:

See my explanation in my in answer to following question. It also provides a solution: App not opened when clicking on message in notification area


Copy/paste of the relevant text:

The app_name value in res\values\strings.xml is used internally to create Intent objects. So when the app is closed and the GCMIntentService receives a message, it creates an intent with the action as <packagename>.<app_name> and send it to notification service to show the notification in the notifications bar.

This is the intent name as used in AndroidManifest.xml to indicate that app has to be launched on tapping the notification:

<activity android:name=".PushNotifications" android:label="@string/app_name" android:configChanges="orientation|keyboardHidden|screenSize" android:launchMode="singleTask" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:screenOrientation="sensor"> 
    ....
    <intent-filter> 
        <action android:name="com.PushNotifications.PushNotifications.NOTIFICATION"/>  
        <category android:name="android.intent.category.DEFAULT"/> 
    </intent-filter> 

So now if the app_name is changed to any other string, internally the Intent will be created as com.PushNotifications.<new_name>.
But the AndroidManifest.xml still has for example com.PushNotifications.PushNotifications (in the case of the sample application), so the app is not getting launched as the intent action is different.

To display the application with a different name, follow these steps:

  1. In strings.xml, add an additional new_name_value
  2. In AndroidManifest.xml , modify the label with the new string name

    <application android:label="@string/app_new_name" android:icon="@drawable/icon"> 
    <activity android:name=".PushNotifications" android:label="@string/app_new_name"...