getLaunchNotification
Returns the push notification that launched the application.
This method returns the push message data if the app was started by tapping a push notification. Returns null if the app was launched normally or if clearLaunchNotification was called. Example:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Check if app was launched from a push notification
// import android.util.Log;
// import com.pushwoosh.notification.PushMessage;
// import org.json.JSONException;
// import org.json.JSONObject;
PushMessage launchNotification = Pushwoosh.getInstance().getLaunchNotification();
if (launchNotification != null) {
// Extract custom data for deep linking
String customData = launchNotification.getCustomData();
String screen = null;
String productId = null;
String articleId = null;
if (customData != null) {
try {
JSONObject data = new JSONObject(customData);
screen = data.optString("screen");
productId = data.optString("product_id", null);
articleId = data.optString("article_id", null);
} catch (JSONException e) {
Log.e("App", "Failed to parse custom data", e);
}
}
Log.d("App", "Launched from push: " + launchNotification.getMessage());
// Navigate to specific screen based on push data
if ("product_details".equals(screen) && productId != null) {
// Open product details screen
Intent intent = new Intent(this, ProductDetailsActivity.class);
intent.putExtra("product_id", productId);
startActivity(intent);
} else if ("article".equals(screen) && articleId != null) {
// Open article screen
Intent intent = new Intent(this, ArticleActivity.class);
intent.putExtra("article_id", articleId);
startActivity(intent);
} else if ("promotions".equals(screen)) {
// Open promotions screen
startActivity(new Intent(this, PromotionsActivity.class));
}
// Clear to prevent reprocessing
Pushwoosh.getInstance().clearLaunchNotification();
}
}
Content copied to clipboard
Return
Launch notification data or null