Mar*_*oba 5 android firebase firebase-cloud-messaging
我想向我的用户发送通知以记住他们更新应用程序,但我无法更改应用程序代码,因为问题显然是该应用程序已过时。
有没有办法通过 FCM 通知、使用clickAction或类似的方式打开 Play 商店,而无需对应用程序进行更改?
您可以使用 FCM 打开特定于 Play 商店的应用程序,您只需将以下逻辑放入 FCM 自定义类的 onMessageReceived 中。
下面是逻辑:
public static void openStore(Context context,RemoteMessage remoteMessage) {
Intent intent;
if (remoteMessage.getData().containsKey("appPackageName")) {
final String appPackageName = remoteMessage.getData().get("appPackageName"); // getPackageName()
try {
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName));
} catch (android.content.ActivityNotFoundException anfe) {
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName));
}
int notificaionId = 1;
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.BigTextStyle bigTextNotiStyle = null;
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int color = ContextCompat.getColor(this, R.color.profileFontColor);
NotificationCompat.Builder mBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.mipmap.ic_notification)
.setContentTitle("" + remoteMessage.getData().get("title"))
.setContentText("" + remoteMessage.getData().get("desc"))
.setStyle(bigTextNotiStyle)
.setAutoCancel(true)
.setColor(color)
.setContentIntent(pIntent)
.setLights(Color.RED, 3000, 3000);
notificationManager.notify(notificaionId, mBuilder.build());
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3088 次 |
| 最近记录: |