【问题标题】:How to open Play Store via a FCM notification?如何通过 FCM 通知打开 Play 商店?
【发布时间】:2018-01-26 03:44:33
【问题描述】:

我想向我的用户发送通知以提醒他们更新应用程序,但我无法更改应用程序代码,因为很明显问题是应用程序已过时。

有没有办法通过 FCM 通知打开 Play 商店,使用 clickAction 或类似的东西,而不需要对应用程序进行更改?

【问题讨论】:

  • 你找到解决办法了吗?
  • 不更改应用程序代码就不行

标签: android firebase firebase-cloud-messaging


【解决方案1】:

您可以使用 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());
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-05
    • 2013-02-15
    • 2022-09-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多