プッシュ通知:
アプリが殺され、バックグラウンドであなたのonMessageReceived
メソッドが呼び出されることはありません。通知はドキュメントに従ってシステムトレイに表示されます。デフォルトのランチャークラスから通知を取り出すことができます。
<application
android:name=".AppController"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".view.SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Myランチャークラスはスプラッシュスクリーンです。アプリが強制終了されると、バンドルから通知データを取得できます。
SplashScreen.Java
public class SplashScreen extends AppCompatActivity {
String messageBody, notificationtype, id, title;
Context mContext;
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
mContext = SplashScreen.this;
if (getIntent().getExtras() != null && this.getIntent().getExtras().containsKey("title")) {
Bundle b = getIntent().getExtras();
String someData = b.getString("title");
String id = b.getString("id");
String notificationtype = b.getString("notification_type");
String message = b.getString("message");
// Log.e("firebaseid", id);
// Log.e("firebase", someData);
// Log.e("firebase", notificationtype);
Intent i = new Intent(SplashScreen.this, NotificationMessage.class);
i.putExtra("title", someData);
i.putExtra("id", id);
i.putExtra("notificationtype", notificationtype);
i.putExtra("messageBody", message);
startActivity(i);
finish();
}
}
あなたのアプリがアクティブであり、フォアグラウンド、あなたのonMessageReceieved
が呼ばれるプッシュ通知を受け取ることになります。
MyFirebaseMessagingService.Java
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
String notificationtype, id, title, message, messagebody;
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
//Displaying data in log
// String message = remoteMessage.getNotification().getBody().toString();
messagebody = remoteMessage.getData().toString();
// sendNotification(message);
notificationtype=remoteMessage.getData().get("notification_type");
id=remoteMessage.getData().get("id");
title=remoteMessage.getData().get("title");
message=remoteMessage.getData().get("message");
}
private void showNotification(String messageBody, String notificationtype, String title, String id) {
}
こんにちはプラディープは、あなたの親切な回答ありがとうございました。実際に私はまだバックグラウンドでフォアグラウンドのVSアプリケーションでアプリケーションについて正確に知る必要があります。最初に私は、 "前景のアプリ"は、アプリがユーザーによって使用されていると思っていました....それは開いていて、ユーザーはアプリケーションで "再生中"です。 「アプリはバックグラウンドで」:アプリは使用されていないが、アプリはAndroid搭載端末の「最近開いたプログラム」のリストにある。 「App is Killed」は、「最近開いたプログラム」にあるアプリケーションがユーザーによって消去されることです。 – karma
しかし、私は間違っていたようです。 「App in backround」は、アプリケーションが開いていないこと、そして「最近オープンしたプログラムではありませんが、サービスはまだ実行中です。たとえばWhatsApp .WAが現在ユーザーによって使用されていなくても、 「最近オープンしたプログラム」では、WAサービスはまだバックグラウンドで実行されているので、メッセージが来たら通知を受け取ることができます。 – karma
uがアプリケーションを強制終了したときにFirebaseサービスが呼び出されず、Firebaseサービスが実行されていないときに、アプリケーションが起動しているときに、Firebaseサービスが呼び出されることはありません。 – pradeep