Android push notification with parse.com launches app automatically

My problem is that when push comes from the analysis service, sometimes the application opens automatically, as if I clicked on a notification from the notification panel. Maybe someone has already encountered a similar problem?

This is my 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);
}}
+4
source share
1 answer

try it

  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);

With setDefaultPushCallback only when you click on the MainActivity Open notification.

Hope that is helpful.

+1
source

Source: https://habr.com/ru/post/1606126/


All Articles