首页 > 编程知识 正文

remoteview下载,华为怎么关闭手机软件的推送消息

时间:2023-05-05 01:12:25 阅读:109565 作者:3221

我实现这个目标的方法是创建BroadcastReceiver,它控制着点击通知上的按钮。 制作这样的东西。

publicclassnotificationbuttonlistenerextendsbroadcastreceiver {

@Override

公共语音接受(context context,Intent intent ) )。

int action=intent.getint extra (' mode ',-1);

sitch (动作) {

//dosomethingsdependingonactioniftherearemorestufftodo

}

}

}

请不要忘记将broadcast监听器添加到清单文件。

可以创建用于创建和取消通知的帮助类。

公共类通知帮助器{

privatestaticfinalintnotification _ id=5;

权限状态通知管理器=null;

publicstaticvoidshownotification (上下文上下文) {

motificationmanager=(通知管理器) context.getsystemservice (context.notification _ service );

remoteviewscontentview=newremoteviews (context.get package name ),r.layout.custom _ notification _ layout );

content view.setonclickpendingintent (r.id.BTN _ close,closePendingIntent );

intentmmainintent=new intent (context,MainActivity.class );

main intent.setflags (intent.flag _ activity _ single _ top|intent.flag _ activity _ new _ task );

pendingintentmmainpendingintent=pending intent.get activity (上下文,555,mMainIntent,pendingintent.flag_update )

notification compat.builder mbuilder=newnotificationcompat.builder (context )

. setticker('playing ' ) ) ) ) ) )。

. setcontent(contentview ) )。

. setAutoCancel(false )

. setongoing(true ) )。

. setsmallicon (r.drawable.IC _ av _ play ) )。

. setcontentintent (mmainpendingintent;

通知通知=mbuilder.build (;

motificationmanager.notify (notification _ id,notification );

}

publicstaticvoidcancelnotification (

监控管理器!=空) {

mNotificationManager.cancelAll (;

}

}

}

此类由NotificationButtonListener使用,用于通知helper.cancel notification (; 水平。

我希望这个对你有帮助!

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。