android - 在android中的调用通知警报?

标签 android audio notifications call vibration

调用电话并显示通知时,只是图标出现在栏中,电话不响铃或振动。

这怎么可能发生?

我的代码:

NotificationManager mNotificationManager = (NotificationManager) getSystemService (Context.NOTIFICATION_SERVICE);

     int icon = R.drawable.icon;
     CharSequence tickerText = "Hello";
     long when = System.currentTimeMillis ();

     Notification notification = new Notification (icon, tickerText, when);

     Context context = getApplicationContext ();
     CharSequence contentTitle = "My notification";
     CharSequence contentText = "My Message";
     Intent notificationIntent = new Intent (this, NotificationClic.class);
     PendingIntent contentIntent = PendingIntent.getActivity (this, 0, notificationIntent, 0);

     notification.setLatestEventInfo (context, contentTitle, contentText, contentIntent);
     notification.defaults = Notification.DEFAULT_SOUND;
     notification.flags | = Notification.FLAG_AUTO_CANCEL;

     mNotificationManager.notify (1, notification);

非常感谢帮助

最佳答案

试试这个

Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
notification.setSound(sound);

您需要使用 NotificationBuilder建立您的Notification对象,然后分配参数。这是一个基本示例:
Notification notification = new NotificationCompat.Builder(ctx)
            .setContentIntent(pIntent)
            .setContentTitle("Your Notification Title")
            .setContentText("Your Notification Text")
            .setSmallIcon(R.drawable.ic_launcher)
            .setSound(alarmSound)
            .build();

关于android - 在android中的调用通知警报?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18580786/

相关文章:

android - 搜索 Android 存储中所有音乐文件(或特定扩展名)的 Activity

java - 无法创建自定义 Canvas View 的多个实例,并且无法将输入值传递给 Canvas 函数 -Android

android - 取消android中所有使用闹钟服务的pendingIntent

iPhone 推送通知无法连接到 SSL 服务器

android - 如何在没有关闭先前 Activity 的情况下从通知中打开对话框样式的 Activity ?

android - ImageView幻灯片动画

android - Firebase 数据库从子节点 B 中指定的子节点 A 检索对象

audio - 将音频背景视频与ffmpeg的原始视频合并

audio - 电晕:重新创建场景后,音频不会再开始播放

c++ - 在短时傅里叶变换中获取特定频率的值