我已经使用解析器大约2个月的android,我很高兴。我已经构建了大部分应用程序,只需要完成推送通知。我阅读了解析推送指南,并能够接收和定制它们。
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
ParseObject.registerSubclass(ParseFeedBack.class);
ParseObject.registerSubclass(ParseReportIssue.class);
ParseObject.registerSubclass(ParseOrder.class);
ParseObject.registerSubclass(ParseAddress.class);
Parse.enableLocalDatastore(getApplicationContext());
Parse.initialize(this, "ID", "ID");
ParseInstallation.getCurrentInstallation().saveInBackground();
}}
所以问题是
ParseInstallation.getCurrentInstallation()
留在应用程序类本身?或者将其转移到主要活动并在那里注册,因为我还想识别与之关联的用户,因此需要在我的主要活动中添加ParseInstallation.put("userPointer", ParseUser.getCurrentUser)
。ParseInstallation.put("userPointer", ParseUser.getCurrentUser)
会将B上的安装与用户A关联,因为他最后登录过。因此,如果我向用户A发送有针对性的推送通知,则会在他的以及用户B电话上收到该通知。ParsePushBroadcastReceiver
中,我正在覆盖onPushRecieve
,并在那里构建通知。我没有在通知中放置任何待处理的意图,而是覆盖onPushOpen()
。这是推荐还是我应该在构建器本身中添加待处理的意图,并将onPushOpen()
留空。
public class MyPushReceiver extends ParsePushBroadcastReceiver {
final Integer PRIORITY_MAX=2;
NotificationCompat.Builder builder;
String message;
public MyPushReceiver() {
super();
}
@Override
protected void onPushReceive(Context context, Intent intent) {
super.onPushReceive(context, intent);
builder=new NotificationCompat.Builder(context);
try {
JSONObject jsonObject=new JSONObject(intent.getExtras().getString("com.parse.Data"));
message=jsonObject.getString("alert");
builder.setContentText(message);
builder.setContentTitle(jsonObject.getString("title"));
builder.setPriority(PRIORITY_MAX);
int mNotificationId = 001;
NotificationManager mNotifyMgr =
(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotifyMgr.notify(mNotificationId, builder.build());
Log.d("PUSH ", jsonObject.toString());
Log.d("s", intent.toString());
}catch (JSONException e){
e.printStackTrace();
}
}
@Override
protected void onPushOpen(Context context, Intent intent) {
super.onPushOpen(context, intent);
Toast.makeText(context, "Opening push!", Toast.LENGTH_LONG).show();
Intent i=new Intent(context, MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}