我为我的Android应用程序集成了推送通知,我想为任何Android手机/标签打开/关闭推送通知,任何人都可以帮助我...
protected void onPostExecute(BlogInfo result){
if(result.IsNew && result.Blog != null){
NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.logo, "THE BUTCHER BARKS", System.currentTimeMillis());
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_ALL;
Intent intent = new Intent(Service.this, Bark.class);
PendingIntent pendingIntent = PendingIntent.getActivity(GuruService.this, 0, intent, 0);
notification.setLatestEventInfo(getApplicationContext(), "BARKS", result.Blog.Title, pendingIntent);
manager.notify(1, notification);
}
}
答案 0 :(得分:2)
在共享首选项中保存一个值,无论是将消息设为ON还是OFF。
然后每当推送消息到达应用程序时,它将调用GCMIntentService中的onMessage方法。然后在onMessage中写入条件。
protected void onMessage(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
if(preference.getPushStatus().equals("ON"))
Log.d("onMessage",arg1.getExtras().getString("message"));
}