1

我已经实现了广播接收器来拦截传入的消息,如果找到了我正在寻找的某些文本,则从接收器播放自定义通知。

通知已正确生成,但我存储在原始文件夹中的自定义通知声音并不总是播放。这是我的代码:

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 设备中,customtone播放几秒钟,然后默认 msg 铃声 overshawdowed,即自定义铃声播放 3 秒,然后 sms 铃声开始播放。

无论如何我可以克服这个吗?

4

0 回答 0