Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android中的呼叫通知警报?_Android_Audio_Notifications_Call_Vibration - Fatal编程技术网

android中的呼叫通知警报?

android中的呼叫通知警报?,android,audio,notifications,call,vibration,Android,Audio,Notifications,Call,Vibration,当我拨打电话并显示通知时,屏幕上只会显示图标,手机不会响或振动 这怎么会发生 我的代码: NotificationManager mNotificationManager = (NotificationManager) getSystemService (Context.NOTIFICATION_SERVICE); int icon = R.drawable.icon; CharSequence tickerText = "Hello"; long when =

当我拨打电话并显示通知时,屏幕上只会显示图标,手机不会响或振动

这怎么会发生

我的代码:

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 = new NotificationCompat.Builder(ctx)
            .setContentIntent(pIntent)
            .setContentTitle("Your Notification Title")
            .setContentText("Your Notification Text")
            .setSmallIcon(R.drawable.ic_launcher)
            .setSound(alarmSound)
            .build();