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 デバイスでは、カスタム トーンが数秒間再生された後、デフォルトの msg 着信音が目立たなくなります。つまり、カスタム トーンが 3 秒間再生された後、SMS トーンが再生されます。

とにかく私はこれを克服することができますか?

4

0 に答える 0