How to set ringtone in Android from my activity?

后端 未结 9 1562
一个人的身影
一个人的身影 2020-11-22 12:11

I\'m trying to find a way to set a new default ringtone by code from my Android activity.

I have already downloaded the ringtone into a bytearray.

9条回答
  •  野性不改
    2020-11-22 12:29

    I cannot comment the solution because I don't have enough reputation on stack overflow ... I want just add a way to add the audio file into media database without accessing directly to the database and hence avoiding to get duplicates. The solution is based on MediaScannerConnection, this is the code I used:

        String[] files = { audioFullPath };
        MediaScannerConnection.scanFile(
            getApplicationContext(),
            files,
            null,
            new OnScanCompletedListener() {
                @Override
                public void onScanCompleted(String path, Uri uri) {
                    Log.v("myapp", "file " + path + " was scanned seccessfully: " + uri);
                }
            }
        );
    

提交回复
热议问题