Set Notification Sound from Assets folder

前端 未结 6 744
北海茫月
北海茫月 2021-02-05 05:46

I am attaching the sound files in the assets folder for play sound in the notification but I am not able to play sound from the assets folder.

I have setting page from w

6条回答
  •  半阙折子戏
    2021-02-05 06:04

    ContentProvider is the way to go. I don't think there is a need to copy files to the data directory like @Dharmendra suggests. You can access the asset folder directly though the ContentProvider

    public AssetFileDescriptor openAssetFile(Uri uri, String mode)
            throws FileNotFoundException {
        String filePart = Sound.getSoundFileName(uri);
    
        try {
            return getContext().getResources().getAssets().openFd(filePart + ".ogg");
        }catch(IOException e) {
            Log.d(TAG, "fail " + e.getMessage());
    
        }
        return null;
    }
    

提交回复
热议问题