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

我试图让我的通知一个按钮,当点击它应该调用我的服务,这是控制音频播放.

这是我的意图通知

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性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...