我已经实施了广播接收器来拦截传入的消息,如果找到我正在查找的某些文本,则从接收器播放自定义通知。
通知是正确生成的,但我存储在原始文件夹中的自定义通知声音不会始终播放。这是我的代码:
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB){
icon = R.drawable.icon;
tickertext = "msg received!!!";
when = System.currentTimeMillis();
Notification notif = new Notification(icon,tickertext,when);
notif.setLatestEventInfo(context,"AppName", sb.substring(0,12), contentIntent);
notif.flags |= Notification.FLAG_AUTO_CANCEL; //Do not clear the notification
notif.defaults |= Notification.DEFAULT_LIGHTS; // LED
notif.defaults |= Notification.DEFAULT_VIBRATE; //Vibration
notif.sound = Uri.parse("android.resource://com.example.Myapp/" + R.raw.customtone);// Sound
manager.notify(1, notif);
}
else{
Uri uri = Uri.parse("android.resource://com.example.MyApp/" + R.raw.customtone);
Notification.Builder builder = new Notification.Builder(context);
builder.setSmallIcon(R.drawable.icon)
.setTicker("msg received!!!")
.setWhen(System.currentTimeMillis())
.setContentTitle("AppName")
.setContentText(sb.substring(0, 12))
.setVibrate(new long[] {1000,1000,1000,1000,1000})
.setLights(Color.RED,0,1)
.setSound(uri)
.setContentIntent(contentIntent)
.setAutoCancel(true);
Notification notif = builder.getNotification();
manager.notify(1, notif);
}
当msg出现时,在 postGingerBread设备中听到了customtone,但在 preGingerbread设备
中没有听到preGingerBread设备中是否存在带有notification.sound属性的问题?
同样在 postGingerBread设备定制播放器播放几秒钟后,默认的msg铃声就会超过,即自定义音调播放3秒,然后sms音开始播放。
无论如何我能克服这个问题吗?