我的问题是,当推送来自解析服务时,有时应用程序会自动打开,就好像我点击通知栏中的通知一样。 也许某人已经遇到过类似的问题?
这是我的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);
}}
答案 0 :(得分: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);
只有在您点击通知MainActivity已打开时才使用setDefaultPushCallback。
希望有用。