我读过一些关于这个问题的其他帖子,我认为我的代码应该鸣响 报警,但事实并非如此。它确实振动,但没有声音。有关如何获得 传达声音的任何建议?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