为什么我的手机每隔五分钟就发出的微博别人看不到通知的声音德佑看不到通知信息

通知提醒对很多需要推送的应用来说是必不可少的,但是有的推送需要声音或者震动,也有的因为开会的话想要一个静音的,那么我们应该如何设置的,于是我就研究了一下,首先我们就要获取到手机系统声音的当前设置,代码如下
AudioManager am = (AudioManager) context
.getSystemService(Context.AUDIO_SERVICE)
final int ringerMode = am.getRingerMode()
ringerMode为手机的系统声音设置的状态值,0位静音,1为震动,2为响铃,下面就是通知的设置
mNotificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE)
mNotification = new Notification()
Intent intent = new Intent(context, SplashActivity.class)
intent.putExtra("notification_main_flag", 3)
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
PendingIntent mPendingIntent = PendingIntent.getActivity(context, 0,
intent, 0)
mNotification.icon = R.drawable.ic_launcher1
mNotification.contentIntent = mPendingIntent
CharSequence contentTitle = getTime()
mNotification.setLatestEventInfo(context, contentTitle, data,
mPendingIntent)
AudioManager am = (AudioManager) context
.getSystemService(Context.AUDIO_SERVICE)
final int ringerMode = am.getRingerMode()
if (ringerMode == MUTE) {
if (ringerMode == VIBRATE) {
mNotification.defaults |= Notification.DEFAULT_VIBRATE
long v1[] = { 0, 100, 200, 300 }
mNotification.vibrate = v1
if (ringerMode == SOUND) {
mNotification.defaults |= Notification.DEFAULT_SOUND
mNotification.flags |= Notification.FLAG_AUTO_CANCEL
mNotificationManager.cancel(NOTIFICATION_ID)
mNotificationManager.notify(NOTIFICATION_ID, mNotification)
如果还有什么不懂得地方,欢迎留言,或者加Android技术交流群 或Android交流群 为你解决
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:42727次
排名:千里之外
原创:42篇
评论:61条
Android技术交流群 (已满)
Android交流群
(6)(3)(3)(2)(1)(4)(1)(3)(1)(1)(10)(3)(1)(3)(1)(1)

我要回帖

更多关于 发出微博别人看不到 的文章

 

随机推荐