通知不发出声音或振动?

Tj5*_*Tj5 5 java notifications android

我正在制作一个程序,我希望该应用程序发出通知.当通知消失时,仅显示自动收报机文本.没有声音,振动或光线伴随着它.

这是我的代码示例:

int icon = R.drawable.icon;  
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

Context context = getApplicationContext();      

CharSequence contentTitle = "My notification";  
CharSequence contentText = "Countdown Complete!";

Intent intent = new Intent();
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification notification = new Notification(icon, myCountDown.getName() + " is completed!", System.currentTimeMillis());

long[] vibrate = {0,100,200,300};
notification.vibrate = vibrate;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.setLatestEventInfo(context, contentTitle, contentText, pendingIntent);
notificationManager.notify(myCountDown.getId(), notification);
Run Code Online (Sandbox Code Playgroud)

Ant*_*hyn 8

要添加通知灯,您需要添加它(注意.flags,而不是.defaults):

notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.ledARGB=0xffffffff; //color, in this case, white
notification.ledOnMS=1000; //light on in milliseconds
notification.ledOffMS=4000; //light off in milliseconds
Run Code Online (Sandbox Code Playgroud)

对于默认声音:

notification.defaults |= Notification.DEFAULT_SOUND;
Run Code Online (Sandbox Code Playgroud)

对于默认振动模式:

notification.defaults |= Notification.DEFAULT_VIBRATE;
Run Code Online (Sandbox Code Playgroud)

对于振动,正如Dean Thomas所说,你需要获得许可 <uses-permission android:name="android.permission.VIBRATE"/>


Jox*_*aex 1

您是否确保设备没有静音并且实际上有用户选择的通知声音(也不是静音)?

另一件要尝试的事情是:

[Note obj].sound = value
[Note obj].LEDARGB = value
[Note obj].vibrate = value
Run Code Online (Sandbox Code Playgroud)