Turn off permissions media plugin

  • 1
  • Question
  • Updated 4 years ago
  • Answered
I use the phonegap media plugin for playing a mp3 livestream.
The media plugin requires a lot of permissions by default.
Can i run this plugin with less permissions? I only need internet connection.
When i set no permissions in the config.xml Phonegap Build automatically overwrite that rule and set all permissions.
Or can i edit the config of the plugin? Or edit the permissions after build?

thank you
Photo of Sven Eulderink

Sven Eulderink

  • 5 Posts
  • 1 Reply Like
  • sad

Posted 6 years ago

  • 1
Photo of John Weidner

John Weidner, Champion

  • 435 Posts
  • 80 Reply Likes
You can selectively remove android permissions that a plugin might add by adding code like the following to your config.xml:

<gap:config-file platform="android" parent="/manifest" mode="delete">

<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
</gap:config-file>


I use the media plugin just for playing sounds. I use the above configuration to remove the four permissions that the media plugin adds that are not necessary for my app since I'm only playing audio.
Photo of Sven Eulderink

Sven Eulderink

  • 5 Posts
  • 1 Reply Like
Awesome! Spended days for a solution like this!
Very thanks! Works perfect!
Photo of Dan S

Dan S

  • 7 Posts
  • 0 Reply Likes
John, I've placed your code in my config and keep getting a malformed config error when uploading to pgb. Any ideas?
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Perhaps a typo.
You can validate your config.xml online at W3C's XML validator. It will show you the error(s).
Photo of John Weidner

John Weidner, Champion

  • 435 Posts
  • 80 Reply Likes
Make sure that you also have
xmlns:gap = "http://phonegap.com/ns/1.0" specified in your widget element at the top of your config.xml file.
Photo of Dan S

Dan S

  • 7 Posts
  • 0 Reply Likes
That code is there and I also validated my xml with no errors. I've tried the code both in and out of the widget, but get errors with both.
(Edited)
Photo of Dan S

Dan S

  • 7 Posts
  • 0 Reply Likes
Here is a copy of my config.xml if you would like to take a look:

http://pastebin.com/T8qUisnW
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
How can you have validated with no errors? The namespace for android: is missing.
Photo of Dan S

Dan S

  • 7 Posts
  • 0 Reply Likes
I meant that the XML in general was validated with no obvious errors using W3C's validator. Sorry for the confusion.

But you are right. Not having the namespace for android was the cause of the problem. Thanks a ton.
Photo of Rafael Dipold

Rafael Dipold

  • 1 Post
  • 0 Reply Likes
This should work when building from CLI?
Photo of Víctor Rodríguez

Víctor Rodríguez

  • 1 Post
  • 0 Reply Likes
John, you missed declare this namespace in the first line xmlns:android="http://schemas.android.com/apk/res/an..."
Photo of Sean Morrow

Sean Morrow

  • 5 Posts
  • 0 Reply Likes
I got my app to build with no issues with all recommendations above - but the pesky media plugin permissions are still in the platforms/android/AndroidManifest.xml. I have succeeded in removing them by unpacking the APK, modifying AndroidManifest.xml and rebuilding but this is a pain for the workflow. Is there any reason why the permissions linger on? Does it have something to do with the "Manifest merger disabled. Using project manifest only." statement during the phonegap app build? Any help would be greatly appreciated...!
Photo of John Weidner

John Weidner, Champion

  • 435 Posts
  • 80 Reply Likes
Are you using PhoneGap Build or the command line tools?
Photo of Sean Morrow

Sean Morrow

  • 5 Posts
  • 0 Reply Likes
Thanks john - command line of course ;)
Photo of John Weidner

John Weidner, Champion

  • 435 Posts
  • 80 Reply Likes
This forum is for "PhoneGap Build" which is Adobe's cloud based service. I think that would explain why the gap:config-file item wasn't working for you.
Photo of Scott Hochberg

Scott Hochberg

  • 25 Posts
  • 0 Reply Likes
Hi,
Thanks for this. It's very helpful.

I found, I think, that for this to work to remove permissions added by a plug-in, the code that you are adding to the config.xml must come somewhere after the line that adds the plugin. Otherwise, it doesn't seem to work (which sounds like it makes sense if PGB is following the config.xml sequentially).

I am looking for a slightly different variation. I want to change the permissions to optional (the plugin adds it as required). I am able to remove it, using

But if I add it back using:

I get it back as required, not optional. I'm thinking my syntax is incorrect for the "required" parameter?

Again, thanks.

Scott