我想要點擊通知動作按鈕時執行一些方法。 我在這個網站上搜索過,但一切似乎都是按順序的,我的IntentService沒有被調用。IntentService onHandleEvent()not starting
我的動作,按鍵意圖
Intent off = new Intent();
off.setAction("action");
off.putExtra("test", "off");
PendingIntent pOff = PendingIntent.getService(context, 22, off, 0);
通知生成器
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(/**/)
.setContentTitle(/**/)
.setContentText(/**/)
.addAction(/**/, "Off", pOff)
.setContentIntent(pendingIntent)
.setDefaults(Notification.DEFAULT_SOUND)
.setAutoCancel(true);
意向服務類
public class NotificationServiceClass extends IntentService {
public NotificationServiceClass(String name) {
super(name);
}
public NotificationServiceClass() {
super("NotificationServiceClass");
}
@Override
protected void onHandleIntent(Intent intent) {
Log.i("test", "onHandle");
if (intent.getAction().equals("action")) {
Log.i("test", "action");
Bundle bundle = intent.getExtras();
if (bundle != null) {
Log.i("test", "onHandleBundleNotNull");
if (bundle.containsKey("test")) {
Log.i("test", bundle.getString("test"));
}
}
}
}
}
XML的服務類
<service
android:name=".Manager.NotificationServiceClass"
android:exported="false">
</service>
01宣言
這是一個非常愚蠢的錯誤。 謝謝你指出。 –