Reputation: 1723
I am sending the push notifications with the help of Urban Airship, and getting the notifications successfully also. But when I am clicking on the notification, it is not opening my app. So what can I do for opening my app ?
and getting the following error in logcate:-
02-10 18:53:44.137: W/xxx - UALib(6840): Activity com.aaa.yyy.SplashActivity@40dcb458 was not manually added during onStart(). Call UAirship.shared().getAnalytics().activityStarted in every activity's onStart() method.
Upvotes: 2
Views: 1886
Reputation: 1723
Yes after doing the Google I got the answer:- We need to create an IntentReceiver.java class as follows:-
public class IntentReceiver extends BroadcastReceiver{
private static final String logTag = "PushSample";
@Override
public void onReceive(Context context, Intent intent) {
Log.i(logTag, "Received intent: " + intent.toString());
String action = intent.getAction();
if (action.equals(PushManager.ACTION_PUSH_RECEIVED)) {
int id = intent.getIntExtra(PushManager.EXTRA_NOTIFICATION_ID, 0);
Log.i(logTag, "Received push notification. Alert: "
+ intent.getStringExtra(PushManager.EXTRA_ALERT)
+ " [NotificationID="+id+"]");
logPushExtras(intent);
}else if (action.equals(PushManager.ACTION_NOTIFICATION_OPENED)) {
Log.i(logTag, "User clicked notification. Message: " + intent.getStringExtra(PushManager.EXTRA_ALERT));
logPushExtras(intent);
Intent launch = new Intent(Intent.ACTION_MAIN);
launch.setClass(UAirship.shared().getApplicationContext(), MainActivity.class);
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
UAirship.shared().getApplicationContext().startActivity(launch);
}else if (action.equals(PushManager.ACTION_REGISTRATION_FINISHED)) {
Log.i(logTag, "Registration complete. APID:" + intent.getStringExtra(PushManager.EXTRA_APID)
+ ". Valid: " + intent.getBooleanExtra(PushManager.EXTRA_REGISTRATION_VALID, false));
}
}
private void logPushExtras(Intent intent) {
Set<String> keys = intent .getExtras().keySet();
for(String key: keys){
List<String> ignoredKeys = (List<String>)Arrays.asList("collapse_key", "from", PushManager.EXTRA_NOTIFICATION_ID,PushManager.EXTRA_PUSH_ID, PushManager.EXTRA_ALERT);
if(ignoredKeys.contains(key)){
continue;
}
Log.i(logTag, "Push Notification Extra: ["+key+" : " + intent.getStringExtra(key) + "]");
} }
}
After that we need to call the following method in PushNotification.java. Here is the code.
public class PushNotification extends Application{
@Override
public void onCreate() {
AirshipConfigOptions options = AirshipConfigOptions.loadDefaultOptions(this);
options.developmentAppKey = "xxx";
options.developmentAppSecret = "yyy";
options.productionAppKey = "zzz";
options.inProduction= false;
UAirship.takeOff(this, options);
PushManager.enablePush();
String apid = PushManager.shared().getAPID();
Logger.info("My Application onCreate - App APID: " + apid);
PushManager.shared().setIntentReceiver(IntentReceiver.class);
}
}
Upvotes: 5
Reputation: 4128
In response to your logcat error:
UALib(6840): Activity com.aaa.yyy.SplashActivity@40dcb458 was not manually added during onStart(). Call UAirship.shared().getAnalytics().activityStarted in every activity's onStart() method.
By default, Urban Airship turns on analyticsEnabled in the AirshipConfigOptions (see documentation).
Prior to Android API 14, you had to manually call activityStarted() in every activity's onStart() method (as the logcat warning suggests or see documentation). If your app’s minSDKVersion >= 14 (Ice Cream Sandwich), you no longer need to modify any of your activities. Make sure to set the minSDKVersion in the airshipconfig.properties in order to prevent any missing instrumented analytic warnings.
If you would like to manually instrument your class, update your Activity’s onStart and onStop methods with the following:
@Override
public void onStart() {
super.onStart();
Analytics.activityStarted(this);
}
@Override
public void onStop() {
super.onStop();
Analytics.activityStopped(this);
}
Note: According to the UA v4 to v5 migration guide the methods to report activity started and stopped are now static (which is the sample code above). If you need to support an older version of UA, then you'd use the sample code from logcat:
UAirship.shared().getAnalytics().activityStarted(this);
Upvotes: 0