Android通知操作未调用挂起的服务意图

Android通知操作未调用挂起的服务意图,android,android-intent,android-service,android-notifications,Android,Android Intent,Android Service,Android Notifications,我试图让我的持续通知有一个按钮,当点击它应该调用我的服务,这是控制音频播放 这是我的意向通知 Intent intent = new Intent(context, AudioStreamService.class); Random generator = new Random(); PendingIntent i = PendingIntent.getActivity(context, 579, intent,PendingIntent.FLAG_UPD

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

这是我的意向通知

        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;
}
从通知中的操作调用日志时,不会触发日志。但该服务由应用程序中的一个按钮使用,运行良好。日志将作为下面的do命令调用。

使用:

PendingIntent pendingIntent = PendingIntent.getService(context, 579, intent,PendingIntent.FLAG_UPDATE_CURRENT);
而不是:

PendingIntent pendingIntent = PendingIntent.getActivity(context, 579, intent,PendingIntent.FLAG_UPDATE_CURRENT);
^^这用于从通知启动活动