【问题标题】:push notification on/off推送通知开/关
【发布时间】:2012-10-10 06:05:34
【问题描述】:

我为我的 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);
            }
        }

【问题讨论】:

  • 您的问题不清楚。你的意思是你想让你的用户选择打开还是关闭它?
  • 根据您的代码,我认为这不是推送通知,而是简单通知。那么你想如何开始/停止通知呢?

标签: android notifications push-notification push server-push


【解决方案1】:

在共享首选项中保存一个值,无论推送消息是打开还是关闭。

然后,每当推送消息到达应用程序时,它将调用 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"));   

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-11
    • 2013-12-20
    • 1970-01-01
    • 1970-01-01
    • 2018-07-05
    • 1970-01-01
    相关资源
    最近更新 更多