安卓系统,使用parse.com进行推送通知,会自动启动应用程序。

4

我的问题是当来自Parse服务的推送到达时,有时应用程序会自动打开,就好像我点击了通知栏中的通知一样。

也许有人已经遇到过类似的问题?

这是我的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个回答

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才会打开。

希望会对您有所帮助。


谢谢,但现在当我点击通知时它不会打开,只有当应用程序在后台打开时才能打开。 - Webdma
好的,我移除了这行代码“Parse.setLogLevel(Parse.LOG_LEVEL_INFO);”,现在看起来正常运行了,我会继续测试,谢谢。 - Webdma

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接