2017-04-09 7 views
0

ここで質問を検索しましたが、見つかったのは、アプリが実行されていないときの問題です。アプリの実行中にFirebaseは通知を送信しませんか?

  1. アプリは(すべてで動作していない)に殺され
  2. アプリケーションがバックグラウンドで動作している: - 私はFirebaseコンソールからテキスト通知を送信した後、私の場合は

    、アプリケーションが通知を受け取ります(しかし、オープン/隠れていない)。

  3. アプリは開いていますが、携帯電話の画面自体は「オフ」の状態です。 (ハードボタンをクリックして画面をもう一度点灯させてから、開いているこのアプリケーションを見るためにスワイプする必要があります)。

私の質問は次のとおりです。 アプリケーションは(画面がオンになっていると、アプリケーションがアクティブである間に - 私は、画面が消灯させないために画面をタッチ触れる)開いている場合、それは私が勝ったこと正常です通知を受け取りませんか?

ありがとうございます。 Firebaseで

答えて

0

プッシュ通知:

アプリが殺され、バックグラウンドであなたの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) { 

} 
+0

こんにちはプラディープは、あなたの親切な回答ありがとうございました。実際に私はまだバックグラウンドでフォアグラウンドのVSアプリケーションでアプリケーションについて正確に知る必要があります。最初に私は、 "前景のアプリ"は、アプリがユーザーによって使用されていると思っていました....それは開いていて、ユーザーはアプリケーションで "再生中"です。 「アプリはバックグラウンドで」:アプリは使用されていないが、アプリはAndroid搭載端末の「最近開いたプログラム」のリストにある。 「App is Killed」は、「最近開いたプログラム」にあるアプリケーションがユーザーによって消去されることです。 – karma

+0

しかし、私は間違っていたようです。 「App in backround」は、アプリケーションが開いていないこと、そして「最近オープンしたプログラムではありませんが、サービスはまだ実行中です。たとえばWhatsApp .WAが現在ユーザーによって使用されていなくても、 「最近オープンしたプログラム」では、WAサービスはまだバックグラウンドで実行されているので、メッセージが来たら通知を受け取ることができます。 – karma

+0

uがアプリケーションを強制終了したときにFirebaseサービスが呼び出されず、Firebaseサービスが実行されていないときに、アプリケーションが起動しているときに、Firebaseサービスが呼び出されることはありません。 – pradeep