Notification sound from URI parse does not work

前端 未结 3 612
深忆病人
深忆病人 2021-01-15 19:23

There are at least 7 questions on Stackoverflow related to this, I have tried every single suggestion and solution multiple times and none of them have worked. Here is my la

3条回答
  •  没有蜡笔的小新
    2021-01-15 20:05

    If this one work for you. Please vote up..........

    Just put your sound file in Res\raw\siren.mp3 folder ::

    Then put this code..This will definitely work for you.

    For Custom Sound ::

     notification.sound = Uri.parse("android.resource://"
                + context.getPackageName() + "/" + R.raw.siren);
    

    For Default Sound ::

    notification.defaults |= Notification.DEFAULT_SOUND;
    

    For Custom Vibrate ::

      long[] vibrate = { 0, 100, 200, 300 };
         notification.vibrate = vibrate;
    

    For Default Vibrate ::

    notification.defaults |= Notification.DEFAULT_VIBRATE;
    

提交回复
热议问题