Android通知 *** 作未调用待处理的服务意图

Android通知 *** 作未调用待处理的服务意图,第1张

概述我试图让我的通知有一个按钮,当点击它应该调用我的服务,这是控制音频播放. 这是我的意图通知 Intent intent = new Intent(context, AudioStreamService.class); Random generator = new Random(); PendingIntent i = PendingIntent.getActivity(co 我试图让我的通知有一个按钮,当点击它应该调用我的服务,这是控制音频播放.

这是我的意图通知

Intent intent = new Intent(context,AudioStreamService.class);    Random generator = new Random();    PendingIntent i = PendingIntent.getActivity(context,579,intent,PendingIntent.FLAG_UPDATE_CURRENT);    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context)            .setSmallicon(R.drawable.ic_launcher)            .setContentTitle(Title)            .setContentText(text)            .setPriority(NotificationCompat.PRIORITY_DEFAulT)            .setLargeIcon(picture)            .setTicker(ticker)            .setNumber(number)            .setongoing(true)            .addAction(               R.drawable.ic_action_stat_reply,res.getString(R.string.action_reply),i);    notify(context,builder.build());

这是我服务的开始

public int onStartCommand(Intent intent,int flags,int startID) {    Log.e("APP ID","APP ID - service called ");    if(isPlaying){        stop();    }    else {        play();    }    return Service.START_STICKY;}

从通知中的 *** 作调用时,永远不会触发日志.但该服务由应用程序中的按钮使用,并且工作正常.按以下命令调用日志.

解决方法 使用 :
PendingIntent pendingIntent = PendingIntent.getService(context,PendingIntent.FLAG_UPDATE_CURRENT);

代替 :

PendingIntent pendingIntent = PendingIntent.getActivity(context,PendingIntent.FLAG_UPDATE_CURRENT);

^^这用于从通知中启动活动.

总结

以上是内存溢出为你收集整理的Android通知 *** 作未调用待处理的服务意图全部内容,希望文章能够帮你解决Android通知 *** 作未调用待处理的服务意图所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1137565.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存