Android 点击通知时未打开游戏市场

Android 点击通知时未打开游戏市场,android,firebase,push-notification,notifications,firebase-notifications,Android,Firebase,Push Notification,Notifications,Firebase Notifications,我想打开播放市场时,点击通知,但打开的应用程序。 我使用firebase通知 @Override public void onMessageReceived(RemoteMessage remoteMessage) { showNotification(remoteMessage.getNotification().getBody()); } private void showNotification(String message) {

我想打开播放市场时,点击通知,但打开的应用程序。 我使用firebase通知

@Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        showNotification(remoteMessage.getNotification().getBody());
    }

    private void showNotification(String message) {
        String textFirebaseEn = getResources().getString(R.string.notification_text_firebase_checking);
        if (message.equals(textFirebaseEn)) {
            String localTitle = getResources().getString(R.string.notification_title_firebase);
            String localText = getResources().getString(R.string.notification_text_firebase);
            Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext())
                    .setSmallIcon(R.drawable.avatar_notification)
                    .setContentTitle(localTitle)
                    .setContentText(localText)
                    .setAutoCancel(true)
                    .setSound(defaultSoundUri);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(PLAY_MARKET));

            builder.setContentIntent(PendingIntent.getActivity(getApplicationContext(), 0, intent, 0));
            Notification notification = builder.build();
            NotificationManager manager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
            manager.notify(0, notification);
        }
    }

请告诉我怎么了?

您的代码仅适用于前台通知。如果您在应用程序中并收到通知,当您点击它时,Play Store应该会打开。如果没有,请尝试以下操作:

final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object
try {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe) {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}
答复来自:

如果您还想从后台通知单击打开play store,最好的方法是创建一个新的活动:

<activity android:name="OpenPlayStoreActivity"
        android:screenOrientation="portrait">
    </activity>

您的代码仅适用于前台通知。如果您在应用程序中并收到通知,当您点击它时,Play Store应该会打开。如果没有,请尝试以下操作:

final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object
try {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe) {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}
答复来自:

如果您还想从后台通知单击打开play store,最好的方法是创建一个新的活动:

<activity android:name="OpenPlayStoreActivity"
        android:screenOrientation="portrait">
    </activity>

不要使用直接市场URI创建一个空白活动,并将contentIntent重定向到该空白活动,处理来自该空白活动的播放商店重定向。不要使用直接市场URI创建一个空白活动,并将contentIntent重定向到该空白活动,并处理来自该空白活动的播放商店重定向activity.please,解释一下:在firebase功能的有效负载中,你应该放上“点击操作”:“OpenPlayStoreActivity”。@nicolasasinovich你想只从firebase仪表板发送通知还是在发生事情时发送通知?在这种情况下,只从firebase仪表板发送通知,而不是忽略有有效负载的部分。有效负载与firebase函数一起使用,因此当服务器上发生事件时,您可以自动发送通知。这段视频解释了它的一切,它可能会帮助你:谢谢,最后一个问题,现在我可以在点击通知时打开Play Market,只有在我打开应用程序之前,如果没有打开应用程序,我可以打开Play Market吗?请解释一下这个地方:在firebase功能的有效负载中,你应该放置“点击动作”:“OpenPlayStoreActivity”.@nicolasasinovich您是只想从firebase仪表板发送通知,还是想在发生事情时发送通知?在这种情况下,只想从firebase仪表板发送通知,而不是忽略具有有效负载的部件。有效负载与firebase函数一起使用,因此当服务器上发生事件时,您可以自动发送通知。这段视频解释了关于它的一切,它可能会帮助你们:谢谢,最后一个问题,现在我可以在点击通知时打开Play Market,只有在我打开应用程序之前,如果没有打开应用程序,我可以打开Play Market吗?