完整的錯誤還包括:java.lang.IllegalArgumentException異常:contentIntent需要
android.app.RemoteServiceException: Bad notification for startForeground:
我讀過其他類似的帖子here,嘗試了他們的建議,並閱讀他們的鏈接,但用戶的少數還在報告這個錯誤。
概述
的活動是由外部應用程序啓動。此活動啓動自定義語音識別服務。它不使用startForeground:
this.startService(intent);
活動然後調用完成();
該服務啓動自定義語音識別類,並在構造函數中將上下文傳遞給它。在「講話的開始檢測」我顯示如下通知:
String notTitle = "Hello";
String notificationText = "hello there";
notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
myNotification = new Notification(
android.R.drawable.ic_btn_speak_now, notTitle,
System.currentTimeMillis());
myNotification.flags |= Notification.FLAG_AUTO_CANCEL;
Intent intent = new Intent();
intent.setAction("com.android.settings.TTS_SETTINGS");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
myNotification.contentIntent = pendingIntent;
myNotification.setLatestEventInfo(mContext, notTitle,
notificationText, pendingIntent);
notificationManager.notify(MY_NOTIFICATION_ID, myNotification);
通知沒有要求做任何事情的「onClick」,因爲它是一旦用戶停止講話取消。我最初傳遞'null intent',但是,在閱讀了很多帖子之後,我添加了顯示TTS設置的random intent/pendingIntent,只是爲了排除這個問題。
99%的用戶對上述代碼或傳遞null意圖都沒有問題。我需要爲1%解決這個問題,因爲它是我應用程序中非常重要的一部分。
任何建議將非常感激。
感謝您的回答。這個問題實際上變成了我正在使用的外部庫,所以沒有「正確的」答案。如果您更新了答案,並提供了其他任何閱讀此問題的人的待定意圖鏈接,我會將其標記爲完整性的正確答案。乾杯。 – brandall
好吧,我添加了一些鏈接,最後一個是另一個類似的問題鏈接 - 我複製粘貼我的答覆在這裏以及:D。 – Radu
謝謝,這很有用。我標記爲正確。 – brandall