2017-07-31 45 views
0

我在使用FCM click_action啓動後臺活動時遇到問題。配置在後臺點擊FCM推

我的宣言:

<activity 
      android:name="com.myoro.MainActivity" 
      android:theme="@style/AppTheme.NoActionBar"/> 

      <activity 
      android:name="com.myoro.ActivityA" 
      android:theme="@style/AppTheme.NoActionBar"> 
      <intent-filter> 
       <action android:name="com.myoro.A" /> 

       <category android:name="android.intent.category.DEFAULT" /> 
      </intent-filter> 
     </activity> 

     <activity 
      android:name="com.myoro.ActivityB" 
      android:theme="@style/AppTheme.NoActionBar"> 
      <intent-filter> 
       <action android:name="com.myoro.B" /> 

       <category android:name="android.intent.category.DEFAULT" /> 
      </intent-filter> 
     </activity> 

我的郵件設置:

data: {{"type" : "A","id" : "a123","click_action": "com.myoro.A"}} 

JAVA:

@Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 
     super.onMessageReceived(remoteMessage); 

     if (remoteMessage.getData().size() > 0) { 


      if (remoteMessage.getData().containsKey("click_action")) { 

       Intent intent = new Intent(remoteMessage.getData().get("click_action"));    
       intent.putExtra("id", remoteMessage.getData().get("id")); 
       startActivity(intent);    
       return; 

      } 

      if (remoteMessage.getData().containsKey("data")) { 

       String data = remoteMessage.getData().get("data"); 
       Gson gson = new Gson(); 
       MyObj myObj = gson.fromJson(data, MyObj.class); 

       if(myObj.getType().equals("A")) { 

        Intent intent = new Intent(context, ActivityA.class);    
        intent.putExtra("id", myObj.getId()); 
        startActivity(intent);   

       } else { 

        Intent intent = new Intent(context, ActivityB.class);    
        intent.putExtra("id", myObj.getId()); 
        startActivity(intent);   

       } 

      } 


     } 

     if (remoteMessage.getNotification() != null) { 

      Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody()); 

     } 

    } 

如果我試圖發送此JSON模式,它總是打開活動主要。我怎麼能操縱fourground和後臺打開ActivityA和ActivityB並需要通過ID?通知點擊...

回答