Android使用parse.com推送通知,自动启动应用程序
我的问题是,当推送来自解析服务时,有时应用程序会自动打开,就像我单击通知栏中的通知一样。 也许有人已经面临类似的问题了 这是我的客户经理:Android使用parse.com推送通知,自动启动应用程序,android,parse-platform,push-notification,push,Android,Parse Platform,Push Notification,Push,我的问题是,当推送来自解析服务时,有时应用程序会自动打开,就像我单击通知栏中的通知一样。 也许有人已经面临类似的问题了 这是我的客户经理: public class CustomPushReceiver extends ParsePushBroadcastReceiver { private final String TAG = CustomPushReceiver.class.getSimpleName(); private Intent parseIntent; public Cust
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);
}}
试试这个
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时,仅当您单击打开的notification Main活动时
希望有用。谢谢,但现在当我单击通知时它不会打开,只有在后台打开应用程序时才会打开。好的,我删除了这行“Parse.setLogLevel(Parse.LOG_LEVEL_INFO);”,现在它看起来工作正常,我将继续测试,谢谢。