我讀過一些關於這個問題的其他帖子,我認爲我的代碼應該鳴響 報警,但事實並非如此。它確實振動,但沒有聲音。有關如何獲得 傳達聲音的任何建議?Android通知,振動,但沒有聲音
程序的另一部分是能夠播放鈴聲,所以問題似乎是 具體此例程。
這是一個擴展服務
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
if (sound == null) { Log.i("RECEIVER", "SOUND IS NULL"); }
NotificationManager myNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Intent intentMain = new Intent(this.getApplicationContext(), MainActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intentMain, 0);
long[] pattern = {500,500,500,500,500,500,500,500,500};
Notification myNote = new Notification.Builder(this)
.setContentTitle("NotificationDemo")
.setContentText("NotificatinDemo")
.setSmallIcon(R.drawable.ic_launcher)
.setSound(sound)
.setVibrate(pattern)
.setContentIntent(pIntent)
.build();
myNM.notify(1, myNote);
return super.onStartCommand(intent, flags, startId);
}
謝謝,夥計們。這些都沒有奏效。我仍然在振動。我是否需要在應用清單中設置任何內容? – Marlonez 2014-12-07 05:20:52
只是一個猜測:嘗試在發佈通知之前調用'super.onStartCommand()'。也許你需要先初始化服務。 – Jerry101 2015-09-22 04:01:28