我想向用户发送通知以记住他们更新应用,但我无法更改应用代码,因为显然问题是该应用已过时。
有没有办法通过FCM通知,使用clickAction
或类似内容打开Play商店,而无需对应用进行更改?
答案 0 :(得分:1)
不会在不更改代码的情况下做到这一点。你必须像在这里一样覆盖onMessageReceived(如何在Firebase的后台处理应用程序时的通知),然后在此处设置它的URL(通过通知打开浏览器链接并不工作)。参考https://stackoverflow.com/a/42339262/9252060
答案 1 :(得分:0)
您可以使用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());
}
}