0

通知をタップしてアプリを開いたときにPlay Marketを開きます。 火災報知を使用しています。開かれていない場合は、通知をタップしてマーケットを再生

@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); 
     } 
    } 

何か間違って教えてください。

+1

代わりにURIが空白のアクティビティを作成し、その空白の活動にcontentIntentをリダイレクトし、その空白の活動からあなたのプレイストアのリダイレクトを処理し、直接市場を使用します。 – Kunu

答えて

1

あなたのコードは、フォアグラウンド通知のためにのみ機能します。アプリの中にいて、通知を受け取った場合、それをタップするとPlayストアが開きます。あなたはまた、バックグラウンド通知クリックからPlayストアを開きたい場合は、それを行うための最善の方法は、新しいアクティビティを作成することですHow to open the Google Play Store directly from my Android application?

:から

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))); 
} 

回答:それはない場合は、これを試してください

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

firebase関数のペイロードには、"click_action": "OpenPlayStoreActivity"を置く必要があります。

そして、あなたのOpenPlayStoreActivity中:

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     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))); 
     } 
} 
+0

してください、この場所を説明してください:firebase関数のペイロードには、 "click_action"を置く必要があります: "OpenPlayStoreActivity"。 –

+0

@nicolasasinovich firebaseダッシュボードからのみ通知を送信するか、何か起こったときに通知を送信しますか? –

+0

この場合 - firebaseダッシュボードからのみ –

関連する問題