android - 推送通知开/关

标签 android notifications push-notification push server-push

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

最佳答案

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

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

}

关于android - 推送通知开/关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12812960/

相关文章:

android - 从 Android Studio Gradle 构建为 AWS Device Farm 生成 UIAutomator 测试 JAR

android - ListView 中的 YouTubeThumbnailView

iphone - 听iPhone通知吗?

java - 推送通知在 Android 中不起作用,代号一

iphone - 使用单点触控的推送通知服务

android - Lollipop 应用程序的透明导航栏?

Android Paypal SDK 错误 : Merchant does not Accept payments of this type

android - Xamarin - Oreo (API 26) Firebase Cloud Messaging 后台通知未显示在通知抽屉中

java - 无法显示生日提醒

react-native - React Native - 如何在 React Native 应用程序中使用 WebView 显示我的网站的通知(适用于 Android)