gpt4 book ai didi

android - 推送通知开/关

转载 作者:行者123 更新时间:2023-11-29 21:57:40 26 4
gpt4 key购买 nike

我为我的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com