小编Tj5*_*Tj5的帖子

通知不发出声音或振动?

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

这是我的代码示例:

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)

java notifications android

5
推荐指数
2
解决办法
4045
查看次数

标签 统计

android ×1

java ×1

notifications ×1