私は問題があると私はMyFireBaseMessagingServiceクラスプッシュ通知()メソッド
にshowNotification方法で定義されて活動を開始しようとすると、おそらく多くの人がよく起こります重要:私は共有設定、IntroActivity(スプラッシュ)と私のaplicationが初期ちょうど1時間
フローを示しているconfigコン:をIntroActivity(スプラッシュ)- (ナビゲーションドロワーメニューのデフォルトのフラグメントオプションで)> MainActivity
2回目の実行アプリケーション:(ナビゲーションドロワーメニューのデフォルトのフラグメントオプションで)MainActivity
私はあなたに私のコードを示し、私は本当にあなたの助けに感謝する必要があるので、私はあなたに詳細を必要とする場合は、この問題を解決する必要があります。
I(正流れ)
ケース私は、バックグラウンドでアプリケーションを持っているとき、私は上部のバーに通知をクリックした後、通知は、タスクバーに表示され、アプリケーションが指定された中で開かれていますアクティビティ詳細情報NoticiaEventoActivity正しい情報。
ケースII(問題の流れ)
しかし、私は、アプリケーションを閉じて、それを終了するとき、通知がタスクバーに表示されますが、私はそれをクリックすると、アプリケーションがMainActivityで開かれていますではなく、私は
を望んでどのように最初のインスタンスでDetailNoticiaEventoActivity活動を示しますケースIII(問題フロー)アプリケーションがバックグラウンドで、通知がMainActivityに私をリダイレクトしているにもかかわらず、時には
のAndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pe.edu.usmp.fiausmp">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<!-- SPLASH ACTIVITY -->
<activity
android:name="pe.edu.usmp.fiausmp.Activities.IntroActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- END SPLASH ACTIVITY -->
<!-- MAINACTIVITY WITH NAV DRAWER -->
<activity android:name="pe.edu.usmp.fiausmp.Activities.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!-- END MAINACTIVITY WITH NAV DRAWER -->
<!-- ACTIVITY SHOWED BY NOTIFICATION METHOD -->
<activity android:name="pe.edu.usmp.fiausmp.Activities.DetalleNoticiaEventoActivity"
android:theme="@style/AppTheme.NoActionBar"
android:configChanges="orientation|keyboardHidden|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!-- END ACTIVITY SHOWED BY NOTIFICATION METHOD -->
<!-- FIREBASE CLASS-->
<service android:name="pe.edu.usmp.fiausmp.Listeners.MyFireBaseMessagingService">
<intent-filter>
<action android:name= "com.google.firebase.MESSAGING_EVENT"></action>
</intent-filter>
</service>
<service android:name="pe.edu.usmp.fiausmp.Listeners.MyFirebaseInstanceIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"></action>
</intent-filter>
</service>
<!-- END FIREBASE CLASS-->
</application>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"
/>
</manifest>
MyFireBaseMessagin gService - showNotificationMethodは()
これは、私は私の完全なクラスを意図して活動を開始し、これでPendindIntentに設定されています。私はどのデバイスでも通知通知のためにgetNotification()を使用し、Ticker、BigTextStyle、Soundなどのカスタム情報にはgetData()を使用します。
注:コメント行は、あなたが
public class MyFireBaseMessagingService extends FirebaseMessagingService{
private static final String TAG = "FIA USMP";
int contador = 0;
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if (remoteMessage == null){
return;
}
Log.e(TAG, "From: " + remoteMessage.getFrom());
Log.e(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
Log.e(TAG, "Notification Message Data: " + remoteMessage.getData());
if (remoteMessage.getData().size() > 0){
JSONObject json = new JSONObject(remoteMessage.getData());
sendNotification(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody(), json);
}
}
//This method is only generating push notification
private void sendNotification(String title, String messageBody, JSONObject json) {
int cod_not_eve = 0;
String cod_mod = "";
String titulo = "";
String resumen = "";
String detalle = "";
try {
cod_not_eve = Integer.parseInt(json.getString("cod_not_eve"));
cod_mod = json.getString("cod_mod");
titulo = json.getString("titulo");
resumen = json.getString("resumen");
detalle = json.getString("detalle");
}catch (JSONException e){
Log.e(TAG, "JSONException: " + e.getMessage());
}catch (Exception e){
Log.e(TAG, "Exception2: " + e.getMessage());
}
Intent intent = new Intent(this, DetalleNoticiaEventoActivity.class);
//intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
//intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("cod_not_eve", cod_not_eve);
intent.putExtra("cod_mod", cod_mod);
//PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
// PendingIntent.FLAG_ONE_SHOT);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
//PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
// PendingIntent.FLAG_UPDATE_CURRENT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
//.setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.mipmap.ic_launcher))
.setContentTitle(title)
.setContentText(messageBody)
//.setStyle(new NotificationCompat.BigTextStyle().bigText(detalle))
.setAutoCancel(true)
//.setVibrate(new long[] {0, 1000, 200,1000 })
//.setLights(Color.parseColor("#00BCD4"), 500, 500)
//.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
//.setTicker(titulo);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(contador, notificationBuilder.build());
Log.d("","MyFireBaseMessagingService.sendNotification.contador"+contador);
contador++;
}
}
本書の意見や提案でテストソリューションはintent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)を追加してみ反映しています。他の2つを削除します。 –
どのようにサーバーで通知を送信しますか?寒いうちにサーバーコードを追加しますか? –
'IntroActivity'を除く' 'から ''を削除してください。 'PendingIntent.FLAG_ONE_SHOT'を使わないでください。 –