Notification sound not played. Permission Denial
Custom notify sound not working. Sound from internal storage, file owner not my app.
Code:
Uri sound = Uri.parse(account.notifySound);
// "account.notifySound" contains path to audio file, obtained from ringtone picker
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_new_message)
.setContentTitle(messageTitle)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(sound)
.setContentIntent(pendingIntent);
if (account.notifyLedColor > 0) notificationBuilder.setLights(MainActivity.ledColorsList[account.notifyLedColor - 1], 100, 50);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(tag, 0, notificationBuilder.build());
Error:
java.lang.SecurityException: Permission Denial: reading com.android.fileexplorer.provider.FileExplorerFileProvider uri content://com.android.fileexplorer.myprovider/external_files/zedge/notification_sound/Marbles.mp3 from pid=1874, uid=1000 requires the provider be exported, or grantUriPermission()
at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:616)
at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:483)
at android.content.ContentProvider$Transport.enforceFilePermission(ContentProvider.java:474)
at android.content.ContentProvider$Transport.openTypedAssetFile(ContentProvider.java:419)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:313)
at android.os.Binder.execTransact(Binder.java:569)
2018-11-11 16:08:20.613 756-15193/? E/MediaPlayerService: Couldn't open fd for content://com.android.fileexplorer.myprovider/external_files/zedge/notification_sound/Marbles.mp3
2018-11-11 16:08:20.613 1874-23378/? E/MediaPlayer: Unable to create media player
minSdkVersion 21
How to fix it?
UPD:
I added after "Uri sound = Uri.parse(account.notifySound);":
grantUriPermission("com.android.systemui", sound, Intent.FLAG_GRANT_READ_URI_PERMISSION);
And got an error:
java.lang.SecurityException: Uid 10204 does not have permission to uri 0 @ content://com.android.fileexplorer.myprovider/external_files/zedge/notification_sound/Marbles.mp3
UPD2:
Ringtone chooser opened multiple sound explorer, eg "Music", "Themes", again "Music" - another sound explorer, different on first "Music" ...
And when i select sound in "Music", picked soundUri = :
content://com.android.fileexplorer.myprovider/external_files/zedge/notification_sound/Snapchat_Tone-04a0409e-68c4-4294-beb3-bb137b8d5886.mp3
When select sound in "Themes" picked uri:
file:///storage/emulated/0/MIUI/.ringtone/Snapchat_Tone-04a0409e-68c4-4294-beb3-bb137b8d5886.mp3
This sound plays when it Uri begins with "file:///" (sound explorer "Themes") and got error when Uri begins "content://" (sound explorer "Music").
Although some other files play when choosing in "Music" with Uri begins "content://..."
android notifications
add a comment |
Custom notify sound not working. Sound from internal storage, file owner not my app.
Code:
Uri sound = Uri.parse(account.notifySound);
// "account.notifySound" contains path to audio file, obtained from ringtone picker
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_new_message)
.setContentTitle(messageTitle)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(sound)
.setContentIntent(pendingIntent);
if (account.notifyLedColor > 0) notificationBuilder.setLights(MainActivity.ledColorsList[account.notifyLedColor - 1], 100, 50);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(tag, 0, notificationBuilder.build());
Error:
java.lang.SecurityException: Permission Denial: reading com.android.fileexplorer.provider.FileExplorerFileProvider uri content://com.android.fileexplorer.myprovider/external_files/zedge/notification_sound/Marbles.mp3 from pid=1874, uid=1000 requires the provider be exported, or grantUriPermission()
at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:616)
at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:483)
at android.content.ContentProvider$Transport.enforceFilePermission(ContentProvider.java:474)
at android.content.ContentProvider$Transport.openTypedAssetFile(ContentProvider.java:419)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:313)
at android.os.Binder.execTransact(Binder.java:569)
2018-11-11 16:08:20.613 756-15193/? E/MediaPlayerService: Couldn't open fd for content://com.android.fileexplorer.myprovider/external_files/zedge/notification_sound/Marbles.mp3
2018-11-11 16:08:20.613 1874-23378/? E/MediaPlayer: Unable to create media player
minSdkVersion 21
How to fix it?
UPD:
I added after "Uri sound = Uri.parse(account.notifySound);":
grantUriPermission("com.android.systemui", sound, Intent.FLAG_GRANT_READ_URI_PERMISSION);
And got an error:
java.lang.SecurityException: Uid 10204 does not have permission to uri 0 @ content://com.android.fileexplorer.myprovider/external_files/zedge/notification_sound/Marbles.mp3
UPD2:
Ringtone chooser opened multiple sound explorer, eg "Music", "Themes", again "Music" - another sound explorer, different on first "Music" ...
And when i select sound in "Music", picked soundUri = :
content://com.android.fileexplorer.myprovider/external_files/zedge/notification_sound/Snapchat_Tone-04a0409e-68c4-4294-beb3-bb137b8d5886.mp3
When select sound in "Themes" picked uri:
file:///storage/emulated/0/MIUI/.ringtone/Snapchat_Tone-04a0409e-68c4-4294-beb3-bb137b8d5886.mp3
This sound plays when it Uri begins with "file:///" (sound explorer "Themes") and got error when Uri begins "content://" (sound explorer "Music").
Although some other files play when choosing in "Music" with Uri begins "content://..."
android notifications
add a comment |
Custom notify sound not working. Sound from internal storage, file owner not my app.
Code:
Uri sound = Uri.parse(account.notifySound);
// "account.notifySound" contains path to audio file, obtained from ringtone picker
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_new_message)
.setContentTitle(messageTitle)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(sound)
.setContentIntent(pendingIntent);
if (account.notifyLedColor > 0) notificationBuilder.setLights(MainActivity.ledColorsList[account.notifyLedColor - 1], 100, 50);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(tag, 0, notificationBuilder.build());
Error:
java.lang.SecurityException: Permission Denial: reading com.android.fileexplorer.provider.FileExplorerFileProvider uri content://com.android.fileexplorer.myprovider/external_files/zedge/notification_sound/Marbles.mp3 from pid=1874, uid=1000 requires the provider be exported, or grantUriPermission()
at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:616)
at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:483)
at android.content.ContentProvider$Transport.enforceFilePermission(ContentProvider.java:474)
at android.content.ContentProvider$Transport.openTypedAssetFile(ContentProvider.java:419)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:313)
at android.os.Binder.execTransact(Binder.java:569)
2018-11-11 16:08:20.613 756-15193/? E/MediaPlayerService: Couldn't open fd for content://com.android.fileexplorer.myprovider/external_files/zedge/notification_sound/Marbles.mp3
2018-11-11 16:08:20.613 1874-23378/? E/MediaPlayer: Unable to create media player
minSdkVersion 21
How to fix it?
UPD:
I added after "Uri sound = Uri.parse(account.notifySound);":
grantUriPermission("com.android.systemui", sound, Intent.FLAG_GRANT_READ_URI_PERMISSION);
And got an error:
java.lang.SecurityException: Uid 10204 does not have permission to uri 0 @ content://com.android.fileexplorer.myprovider/external_files/zedge/notification_sound/Marbles.mp3
UPD2:
Ringtone chooser opened multiple sound explorer, eg "Music", "Themes", again "Music" - another sound explorer, different on first "Music" ...
And when i select sound in "Music", picked soundUri = :
content://com.android.fileexplorer.myprovider/external_files/zedge/notification_sound/Snapchat_Tone-04a0409e-68c4-4294-beb3-bb137b8d5886.mp3
When select sound in "Themes" picked uri:
file:///storage/emulated/0/MIUI/.ringtone/Snapchat_Tone-04a0409e-68c4-4294-beb3-bb137b8d5886.mp3
This sound plays when it Uri begins with "file:///" (sound explorer "Themes") and got error when Uri begins "content://" (sound explorer "Music").
Although some other files play when choosing in "Music" with Uri begins "content://..."
android notifications
Custom notify sound not working. Sound from internal storage, file owner not my app.
Code:
Uri sound = Uri.parse(account.notifySound);
// "account.notifySound" contains path to audio file, obtained from ringtone picker
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_new_message)
.setContentTitle(messageTitle)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(sound)
.setContentIntent(pendingIntent);
if (account.notifyLedColor > 0) notificationBuilder.setLights(MainActivity.ledColorsList[account.notifyLedColor - 1], 100, 50);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(tag, 0, notificationBuilder.build());
Error:
java.lang.SecurityException: Permission Denial: reading com.android.fileexplorer.provider.FileExplorerFileProvider uri content://com.android.fileexplorer.myprovider/external_files/zedge/notification_sound/Marbles.mp3 from pid=1874, uid=1000 requires the provider be exported, or grantUriPermission()
at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:616)
at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:483)
at android.content.ContentProvider$Transport.enforceFilePermission(ContentProvider.java:474)
at android.content.ContentProvider$Transport.openTypedAssetFile(ContentProvider.java:419)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:313)
at android.os.Binder.execTransact(Binder.java:569)
2018-11-11 16:08:20.613 756-15193/? E/MediaPlayerService: Couldn't open fd for content://com.android.fileexplorer.myprovider/external_files/zedge/notification_sound/Marbles.mp3
2018-11-11 16:08:20.613 1874-23378/? E/MediaPlayer: Unable to create media player
minSdkVersion 21
How to fix it?
UPD:
I added after "Uri sound = Uri.parse(account.notifySound);":
grantUriPermission("com.android.systemui", sound, Intent.FLAG_GRANT_READ_URI_PERMISSION);
And got an error:
java.lang.SecurityException: Uid 10204 does not have permission to uri 0 @ content://com.android.fileexplorer.myprovider/external_files/zedge/notification_sound/Marbles.mp3
UPD2:
Ringtone chooser opened multiple sound explorer, eg "Music", "Themes", again "Music" - another sound explorer, different on first "Music" ...
And when i select sound in "Music", picked soundUri = :
content://com.android.fileexplorer.myprovider/external_files/zedge/notification_sound/Snapchat_Tone-04a0409e-68c4-4294-beb3-bb137b8d5886.mp3
When select sound in "Themes" picked uri:
file:///storage/emulated/0/MIUI/.ringtone/Snapchat_Tone-04a0409e-68c4-4294-beb3-bb137b8d5886.mp3
This sound plays when it Uri begins with "file:///" (sound explorer "Themes") and got error when Uri begins "content://" (sound explorer "Music").
Although some other files play when choosing in "Music" with Uri begins "content://..."
android notifications
android notifications
edited Nov 11 at 12:35
asked Nov 11 at 9:19
Serg
387
387
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
As compiler said:
requires the provider be exported, or grantUriPermission()
You could try this:
grantUriPermission("com.android.systemui", sound,
Intent.FLAG_GRANT_READ_URI_PERMISSION);
where sound
is the Uri
that you are using with setSound().
If you can not sure which packages should grant permission, below helper functional would loop search:
public static void grantUriPermission(Activity ctx, Intent intent, Uri uri, int permissionFlags) {
List<ResolveInfo> resolvedIntentActivities = ctx.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolvedIntentInfo : resolvedIntentActivities) {
String packageName = resolvedIntentInfo.activityInfo.packageName;
ctx.grantUriPermission(packageName, uri, permissionFlags);
}
}
I added grantUriPermission and got error. I updated my question
– Serg
Nov 11 at 10:37
Question update 2
– Serg
Nov 11 at 12:36
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247348%2fnotification-sound-not-played-permission-denial%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As compiler said:
requires the provider be exported, or grantUriPermission()
You could try this:
grantUriPermission("com.android.systemui", sound,
Intent.FLAG_GRANT_READ_URI_PERMISSION);
where sound
is the Uri
that you are using with setSound().
If you can not sure which packages should grant permission, below helper functional would loop search:
public static void grantUriPermission(Activity ctx, Intent intent, Uri uri, int permissionFlags) {
List<ResolveInfo> resolvedIntentActivities = ctx.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolvedIntentInfo : resolvedIntentActivities) {
String packageName = resolvedIntentInfo.activityInfo.packageName;
ctx.grantUriPermission(packageName, uri, permissionFlags);
}
}
I added grantUriPermission and got error. I updated my question
– Serg
Nov 11 at 10:37
Question update 2
– Serg
Nov 11 at 12:36
add a comment |
As compiler said:
requires the provider be exported, or grantUriPermission()
You could try this:
grantUriPermission("com.android.systemui", sound,
Intent.FLAG_GRANT_READ_URI_PERMISSION);
where sound
is the Uri
that you are using with setSound().
If you can not sure which packages should grant permission, below helper functional would loop search:
public static void grantUriPermission(Activity ctx, Intent intent, Uri uri, int permissionFlags) {
List<ResolveInfo> resolvedIntentActivities = ctx.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolvedIntentInfo : resolvedIntentActivities) {
String packageName = resolvedIntentInfo.activityInfo.packageName;
ctx.grantUriPermission(packageName, uri, permissionFlags);
}
}
I added grantUriPermission and got error. I updated my question
– Serg
Nov 11 at 10:37
Question update 2
– Serg
Nov 11 at 12:36
add a comment |
As compiler said:
requires the provider be exported, or grantUriPermission()
You could try this:
grantUriPermission("com.android.systemui", sound,
Intent.FLAG_GRANT_READ_URI_PERMISSION);
where sound
is the Uri
that you are using with setSound().
If you can not sure which packages should grant permission, below helper functional would loop search:
public static void grantUriPermission(Activity ctx, Intent intent, Uri uri, int permissionFlags) {
List<ResolveInfo> resolvedIntentActivities = ctx.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolvedIntentInfo : resolvedIntentActivities) {
String packageName = resolvedIntentInfo.activityInfo.packageName;
ctx.grantUriPermission(packageName, uri, permissionFlags);
}
}
As compiler said:
requires the provider be exported, or grantUriPermission()
You could try this:
grantUriPermission("com.android.systemui", sound,
Intent.FLAG_GRANT_READ_URI_PERMISSION);
where sound
is the Uri
that you are using with setSound().
If you can not sure which packages should grant permission, below helper functional would loop search:
public static void grantUriPermission(Activity ctx, Intent intent, Uri uri, int permissionFlags) {
List<ResolveInfo> resolvedIntentActivities = ctx.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolvedIntentInfo : resolvedIntentActivities) {
String packageName = resolvedIntentInfo.activityInfo.packageName;
ctx.grantUriPermission(packageName, uri, permissionFlags);
}
}
edited Nov 11 at 10:07
answered Nov 11 at 9:58
navylover
3,32021118
3,32021118
I added grantUriPermission and got error. I updated my question
– Serg
Nov 11 at 10:37
Question update 2
– Serg
Nov 11 at 12:36
add a comment |
I added grantUriPermission and got error. I updated my question
– Serg
Nov 11 at 10:37
Question update 2
– Serg
Nov 11 at 12:36
I added grantUriPermission and got error. I updated my question
– Serg
Nov 11 at 10:37
I added grantUriPermission and got error. I updated my question
– Serg
Nov 11 at 10:37
Question update 2
– Serg
Nov 11 at 12:36
Question update 2
– Serg
Nov 11 at 12:36
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247348%2fnotification-sound-not-played-permission-denial%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown