In native android application if I need to declare that my application is going to use any permissions first of all I need to add them to AndroidManifest.xml file, like here
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.co.ar">
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
...
And this way I can just open application settings on the phone and see what permissions this application is using.
In unity I don't see a way to declare permissions that application is going to use. I found out according to this documentation
https://docs.unity3d.com/2020.1/Documentation/Manual/android-manifest.html
There is LibraryManifest.xml that responsible for permissions, I found this file and add there permissions I need, but because of this file is generated so every time I make new build it rewrites.
Player Settings -> Tab (Android) -> Publishing Settings -> Check Custom Main Manifest -> Edit "AndroidManifest.xml" in Assets/Plugins/Android
There is LibraryManifest.xml that responsible for permissions, I found
this file and add there permissions I need, but because of this file
is generated so every time I make new build it rewrites.
There by the way an asset that can do this android permissions
I hope you find this useful
Related
In the Xamarin.Forms application we are developing, called "myApp", targeting Android devices only, we need to be able to read from (and possibly write to) the text file
storage/emulated/0/Android/data/com.myApp.configuration/myAppStuff.txt
which in the Windows 10 development platform appears as
This PC\DEVICE TYPE\Internal shared storage\Android\data\com.myApp.configuration\
In the AndroidManifest.xml file for the project, we have included
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" ... >
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" tools:remove="android:maxSdkVersion"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:remove="android:maxSdkVersion"/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" tools:remove="android:maxSdkVersion"/>
</manifest>
This is confirmed in Visual Studio 2022 by navigating to
Project > myApp.Android Properties > Android Manifest > Required permissions:
and observing the required permissions are asserted.
When the application is first started in the debug mode, in MainActivity.cs
AndroidX.Core.App.ActivityCompat.CheckSelfPermission(this, Android.Manifest.Permission.ReadExternalStorage)
returns "false", so we invoke
AndroidX.Core.App.ActivityCompat.RequestPermissions(this, new string[] { Android.Manifest.Permission.ReadExternalStorage, Android.Manifest.Permission.WriteExternalStorage, Android.Manifest.Permission.ManageExternalStorage }, 0)
Android shows a (non-modal) dialog
for which we select "ALLOW".
Later, the code
File.Exists("/storage/emulated/0/Android/data/com.myApp.configuration/myAppStuff.txt")
returns "true"
but the code
mystreamreader = new StreamReader("/storage/emulated/0/Android/data/com.myApp.configuration/myAppStuff.txt");
throws the exception with Message value of
"Access to the path \"/storage/emulated/0/Android/data/com.myApp.configuration/myAppStuff.txt\" is denied."
A later check shows that the code
AndroidX.Core.App.ActivityCompat.CheckSelfPermission(this, Android.Manifest.Permission.ManageExternalStorage)
returns the value "false".
Why?
I can't reproduce your problem. But you said:
we need to be able to read from (and possibly write to) the text file
So I created a sample to read and write the text file:
In my AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0"
package="com.companyname.app21">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="33" />
<application android:label="App21.Android" android:theme="#style/MainTheme"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
Please make sure the package's value in your AndroidManifest.xml file is com.myApp.configuration.
And the code about create, read and write the file:
FileStream filestream = new FileStream("/storage/emulated/0/Android/data/com.companyname.app21/test.txt",
FileMode.OpenOrCreate,
FileAccess.ReadWrite,
FileShare.ReadWrite);
// create the text file
File.WriteAllText("/storage/emulated/0/Android/data/com.companyname.app21/test.txt", "this is content");
// write the text file
var content = File.ReadAllText("/storage/emulated/0/Android/data/com.companyname.app21/test.txt");
//read the text file
Which Android version? As of Android13, EXTERNAL_STORAGE is basically gone. CheckSelfPermission for it will auto-answer false, just as if you answered "No and do not ask again" before. They want you to move to different APIs, e.g. ask a Document Picker to get arbitrary files or be a Document Provider to provide them.
The documentation says to add permission to the manifest in order to get all installed applications on the device starting from Android 11 and above, I added but underlines in red and writes
A declaration should generally be used instead of QUERY_ALL_PACKAGES; see https://g.co/dev/packagevisibility for details
What am I doing wrong?
<manifest ...>
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
...
</manifest>
Today i was updating one of my Apps, i was in process of migrating project to android permission and integrating admob and vungle ads sdk, I forgot to add permissions inside manifest file and I exported the apk. But apk was perfectly showing ads inside app and it showed network permissions before installing the apk.So the permissions are not mandatory to add inside android studio?
Below are the permissions which i forgot to add
<!-- permissions to download and cache video ads for playback -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
There are no other permissions in my app.So do i need to add it there?
It seems like Read/Write external storage and Read phone state permissions are automatically added to the manifest on building the android apk. Are these necessary for all React Native android apps? Is there any way to remove these permissions?
Looking at the build/output/logs/manifest-merger-debug-report.txt I see:
android:uses-permission#android.permission.READ_EXTERNAL_STORAGE
IMPLIED from `/***/android/app/src/main/AndroidManifest.xml:1:1-22:12 reason: org.webkit.android_jsc` requested WRITE_EXTERNAL_STORAGE
It feels weird that I'll see these permissions being requested if I install the app from the Play store if I'm not using them.
I have an answer.
AndroidManifest.xml
Add this to manifest which should be line 1
xmlns:tools="http://schemas.android.com/tools"
It should look like this
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="YOUR PACKAGE NAME">
Now you can remove the permissions with this
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="remove" />
So my permissions for a simple app are
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" tools:node="remove" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="remove" />
Don't remove SYSTEM.ALERT.WINDOW, you will have problems in development.
I am compiling a project that does not explicitly request the READ_PHONE_STATE permission, but when I compile I am seeing the permission in my compiled Android Manifest file. I'm assuming some library that's being pulled in is adding it explicitly or forgot to set its minimum SDK version (which would add it).
The only thing I have to go on is that in the final manifest, the permissions I requested myself look like this:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
And the READ_PHONE_STATE looks like this:
<android:uses-permission android:name="android.permission.READ_PHONE_STATE" />
Does the android prefix mean anything?
Is there any way to narrow down which library is adding this permission?
You can exactly see if a (or because of) library adds some extra Permission to your manifest. Check at file generated (see below) during build process and look for the unwanted permission within the file!
Go to your project folder and look for this path:
[ProjectFolder]/build/outputs/logs/manifest-merger---report.txt
open the file and search for the permission
In my case I found these lines at the
uses-permission#android.permission.READ_PHONE_STATE IMPLIED from
C:\..\...\AppFolder\src\..\AndroidManifest.xml:2:1-14:12 reason:
com.some.evil.library has a targetSdkVersion < 4
This generated file show the output of the merge process described here in Android Developers site.
I would look at:
Android Library Manifest vs. App Manifest
This isn't really a duplicate so I won't flag, however I think he covers the topic fairly well in his answer to that question.
After that and assuming you can't figure it out, I would do the following:
Locate your gradle cache
Crack open the artifacts of each of your dependences (rename to .zip and extract is the easiest way to do this)
check if they have manifests included and see whats in the,