0

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

这怎么可能发生?

我的代码:

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);

非常感谢帮助

4

1 回答 1

0

尝试这个

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();
于 2013-09-02T22:38:16.530 回答