Getcontentresolver () returns null in the service

In the code below, getcontentresolver() is null, but works in the onCreate() Service, but not in the function in the service. What for?

  final Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; final String[] cursor_cols = { MediaStore.Audio.Media._ID, MediaStore.Audio.Media.ARTIST, MediaStore.Audio.Media.ALBUM, MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.DATA }; final String where = MediaStore.Audio.Media.IS_MUSIC + "=1"; cursor = getContentResolver() .query(uri, cursor_cols, where, null, null); 
+4
source share
1 answer

Make sure your USB connection to the device is in PC mode and not USB Mass Storage

if it is in mass storage it will return null

0
source

Source: https://habr.com/ru/post/1390209/


All Articles