2015-09-06 225 views
4

我的問題是,當推送來自分析服務時,有時應用程序會自動打開,就像我點擊通知欄中的通知一樣。 也許有人已經面臨類似的問題?Android,使用parse.com推送通知,自動啓動應用程序

這是我CustomReseiver:

public class CustomPushReceiver extends ParsePushBroadcastReceiver { 
private final String TAG = CustomPushReceiver.class.getSimpleName(); 


private Intent parseIntent; 

public CustomPushReceiver() { 
    super(); 
} 

@Override 
protected void onPushReceive(Context context, Intent intent) { 
    super.onPushReceive(context, intent); 

    if (intent == null) 
     return; 

    try { 
     JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data")); 
     Log.e(Constans.LOG_TAG, "Push received: " + json); 
     parseIntent = intent; 
     // Toast.makeText(ParseApplication.get(), json.getString("alert"), Toast.LENGTH_SHORT).show(); 
     if(ProfileBriefsFragment.profileBriefsContext instanceof Profile_SideBar_Activity){ 
      ((Profile_SideBar_Activity)ProfileBriefsFragment.profileBriefsContext).pushReceived(json); 
     } 
     CurrentUser.getInstance().setHaveNewNotidication(true); 
     Notification_center_Activity.updateNotifications(); 
    } catch (JSONException e) { 
     Log.e(TAG, "Push message json exception: " + e.getMessage()); 
    } 
} 

@Override 
protected void onPushDismiss(Context context, Intent intent) { 
    super.onPushDismiss(context, intent); 
} 

@Override 
public void onPushOpen(Context context, Intent intent) { 
    Intent i = new Intent(context, NewHomeActivity.class); 
    i.putExtras(intent.getExtras()); 
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    context.startActivity(i); 
} 
public interface OnPushReceived{ 
    void pushReceived(JSONObject json); 
}} 

回答

1

試試這個

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) { 
      // Initialize Parse 
      Parse.initialize(this, "your id from parse"); 


      ParseInstallation.getCurrentInstallation().saveInBackground(); 
      Parse.setLogLevel(Parse.LOG_LEVEL_INFO); 

     } 


    PushService.setDefaultPushCallback(this, MainActivity.class, R.drawable.ic_notification); 

隨着setDefaultPushCallback只有當你點擊打開通知MainActivity。

希望有用。

+0

謝謝,但現在它不會打開時,我單擊通知,只有當應用程序在後臺打開。 – Webdma

+0

好吧,我刪除了這一行「Parse.setLogLevel(Parse.LOG_LEVEL_INFO);」,現在它看起來像正常工作,我會繼續測試,謝謝。 – Webdma

+0

歡迎您,祝你好運 –

相關問題