本文介绍了Android通知不做声音或振动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int icon = R.drawable.icon;
Context context = getApplicationContext();
CharSequence contentTitle = "My notification";
CharSequence contentText = "Countdown Complete!";
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent();
Notification notification = new Notification(icon, "is completed!", System.currentTimeMillis());
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(context, contentTitle, contentText, pendingIntent);
long[] vibrate = {0,100,200,300};
notification.vibrate = vibrate;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.defaults |= Notification.DEFAULT_SOUND;
notificationManager.notify(myCountDown.getId(), notification);

在我的Andr​​oid应用程序本code和我得到的通知,但没有任何声音或振动。

This code in my android application and i get the notification but no sound or vibration.

我已经在多个手机所有声音和振动在设置中打开并进行测试。我也确信,我所要求使用的振动许可,Android清单,但我仍然只能得到通知...

I've tested on multiple phones all with sound and vibration turned on and up in settings. I've also made sure that i'm asking to use the vibration permission in the android manifest but i still only get the notification...

我也试过:

notification.defaults = Notification.DEFAULT_ALL;

notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.defaults |= Notification.DEFAULT_SOUND;

我如何获得声音和振动在我的通知?

How do I get sound and vibration in my notifications?

推荐答案

不要忘了启用铃声和通知振动设置。进入设置 - >声音。检查声音的振动。

Don't forget to enable the vibration setting for ringtone and notifications. Go to Settings -> Sound. Check "Sound an vibration".

这篇关于Android通知不做声音或振动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 20:34
查看更多