最後に、私の問題の解決策が見つかりました。
まず、FCM通知はフラグメントを直接呼び出すことはできません。 click_action
パラメータを使用する必要があります。
第1 たManifest.xmlここ
<activity
android:name=".MainActivity" android:label="@string/app_name" android:screenOrientation="portrait" android:theme="@style/AppTheme.NoActionBar">
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
<intent-filter>
<action android:name="sm.boson.com.smd.MAIN" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
、あなたはaction android:name
intent-filter
セクションに追加し、名前を指定する必要があります。私の場合、私は同じパッケージ名を ".MAIN"(MainActivityのシンボルを表していますが、別の名前を使用することもできます)という名前を使用しました。私Intent
の宣言で
MyFirebaseMessagingService.java
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
String id = remoteMessage.getData().get("tag") ;
String click_action = remoteMessage.getNotification().getClickAction();
Intent intent = new Intent(click_action);
intent.putExtra("id", id);
intent.putExtra("push", "true");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
notificationBuilder.setContentTitle(getResources().getString(R.string.app_name));
notificationBuilder.setContentText(remoteMessage.getNotification().getBody());
notificationBuilder.setAutoCancel(true);
notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
notificationBuilder.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
私は活動にいくつかのパラメータを送信するためにExtra
を追加しました。
MyActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
//ALL THE LOGIC OF YOU ONCREATE EVENT
Intent i = getIntent();
Bundle extras = i.getExtras();
if(extras != null) {
String push = extras.getString("push");
if (push != null) {
Integer id = Integer.parseInt(extras.getString("id"));
goToDetalleDenuncia(id);
}else if ( extras.getString("tag") != null ){
Integer id = Integer.parseInt(extras.getString("tag"));
goToDetalleDenuncia(id);
}else
goToMenu();
}else
goToMenu();
}
まあ、アプリケーションが実行されているとき、あなたは最初if
文でパラメータを取得し、それらを取得することができます。extras.getString("push")
しかし、あなたのアプリケーションがある場合バックグラウンドで実行している(または閉じている)場合は、次のようにパラメータを取得する必要があります。
Integer.parseInt(extras.getString("tag"));
なぜ「タグ」ですか? 私のMyFirebaseMessagingService
で私は "タグ"を取得し、私はExtra
の私の意図のための "ID"キーに入れました。
など私のサーバーからの私のJSON:
{
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"priority" : "normal",
"notification" : {
"body" : "This week's edition is now available.",
"title" : "Mytitle",
"icon" : "new"
},
"data" : {
"tag" : "3.21.15",
}
}
、このように、今私は、バックグラウンドで動作しているとき、それが閉じていたときに、アプリケーションが、実行されているときFCM
を使用して、特定のFragment
を開くことができます。
希望すると、これが役立ちます。
それは私を助けました。ありがとう:* –
あなたのサービスで;)@MahboobehMohammadi – MrMins