2
嗨, 我處於通話到達時需要顯示通知的情況。爲此,我正在使用廣播接收器。代碼是在廣播接收器中顯示通知
public class MyPhoneStateListener extends PhoneStateListener {
public Context context;
@Override
public void onCallStateChanged(int state, String incomingNumber) {
// TODO Auto-generated method stub
super.onCallStateChanged(state, incomingNumber);
switch(state){
case TelephonyManager.CALL_STATE_IDLE:
NotificationManager notifier = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
//Get the icon for the notification
int icon = R.drawable.icon;
Notification notification = new Notification(icon,"Simple Notification",System.currentTimeMillis());
//Setup the Intent to open this Activity when clicked
Intent toLaunch = new Intent(context, main.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, toLaunch, 0);
//Set the Notification Info
notification.setLatestEventInfo(context, "Hi!!", "This is a simple notification", contentIntent);
//Setting Notification Flags
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.flags |= Notification.FLAG_INSISTENT;
// notification.sound = Uri.withAppendedPath(Audio.Media.INTERNAL_CONTENT_URI, "6");
//Send the notification
notifier.notify(0x007, notification);
Log.d("CALL", "IDLE");
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.d("DEBUG", "OFFHOOK");
break;
case TelephonyManager.CALL_STATE_RINGING:
Log.d("DEBUG", "RINGING");
break;
}
}
}
現在的問題是聲音通知沒有播放,但通知正在正確顯示。請問任何人都可以點亮它,爲什麼通知聲音不被播放?
不工作...我認爲這是一個android的錯誤..我應該在那裏報告嗎? – 2011-05-31 12:25:52