Android 如何通过FCM通知打开播放商店?
我想向我的用户发送通知,提醒他们更新应用程序,但我无法更改应用程序代码,因为很明显,问题是应用程序已经过时Android 如何通过FCM通知打开播放商店?,android,firebase,firebase-cloud-messaging,Android,Firebase,Firebase Cloud Messaging,我想向我的用户发送通知,提醒他们更新应用程序,但我无法更改应用程序代码,因为很明显,问题是应用程序已经过时 有没有一种方法可以通过FCM通知打开Play Store,使用clickAction或类似的方法,而不需要对应用程序进行更改?您可以使用FCM打开特定于Play Store的应用程序,您只需在FCM自定义类的onMessageReceived中加入以下逻辑即可 下面是逻辑: public static void openStore(Context context,RemoteMessage
有没有一种方法可以通过FCM通知打开Play Store,使用
clickAction
或类似的方法,而不需要对应用程序进行更改?您可以使用FCM打开特定于Play Store的应用程序,您只需在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());
}
}
你找到解决方案了吗?没有,但不更改应用程序的代码