Android,使用 parse.com 推送通知,自动启动应用
Android, Push notification using parse.com, launches the app automatically
我的问题是,当推送来自解析服务时,有时应用程序会自动打开,就好像我点击了通知栏中的通知一样。
也许有人已经遇到过类似的问题?
这是我的 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);
}}
试试这个
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 Opened 时使用 setDefaultPushCallback。
希望有用。
我的问题是,当推送来自解析服务时,有时应用程序会自动打开,就好像我点击了通知栏中的通知一样。 也许有人已经遇到过类似的问题?
这是我的 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);
}}
试试这个
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 Opened 时使用 setDefaultPushCallback。
希望有用。