I am trying to access HTTP link using HttpURLConnection in Android to download a file, but I am getting this warning in LogCat:
WARN/System.err(223): java.net.SocketException: Permission denied (maybe missing INTERNET permission)
I have added android.Manifest.permission to my application but it's still giving the same exception.
Assuming you do not have permissions set from your LogCat error description, here is my contents for my AndroidManifest.xml file that has access to the internet:
<manifest xlmns:android...>
...
<uses-permission android:name="android.permission.INTERNET" />
<application ...
</manifest>
Other than that, you should be fine to download a file from the internet.
Permission name is CASE-SENSITIVE
In case somebody will struggle with same issue, it is case sensitive statement, so wrong case means your application won't get the permission.
WRONG
<uses-permission android:name="ANDROID.PERMISSION.INTERNET" />
CORRECT
<uses-permission android:name="android.permission.INTERNET" />
This issue may happen ie. on autocomplete in IDE
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.photoeffect"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="com.example.towntour.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar" >
<activity
android:name="com.photoeffect.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
If you are using the Eclipse ADT plugin for your development, open AndroidManifest.xml in the Android Manifest Editor (should be the default action for opening AndroidManifest.xml from the project files list).
Afterwards, select the Permissions tab along the bottom of the editor (Manifest - Application - Permissions - Instrumentation - AndroidManifest.xml), then click Add... a Uses Permission and select the desired permission from the dropdown on the right, or just copy-paste in the necessary one (such as the android.permission.INTERNET permission you required).
Copy the following line to your application manifest file and paste before the <application> tag.
<uses-permission android:name="android.permission.INTERNET"/>
Placing the permission below the <application/> tag will work, but will give you warning. So take care to place it before the <application/> tag declaration.
FOR FLUTTER DEVELOPERS.
Go to
android/app/main/AndroidManifest.xml
Outside the
application tag
but inside the
manifest tag
Add
<uses-permission android:name="android.permission.INTERNET" />
Add the below line in your application tag:
android:usesCleartextTraffic="true"
To be look like below code :
<application
....
android:usesCleartextTraffic="true"
....>
And add the following tags above of application
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
to be like that :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.themarona.app">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
When using eclipse, Follow these steps
Double click on the manifest to show it on the editor
Click on the permissions tab below the manifest editor
Click on Add button
on the dialog that appears Click uses permission. (Ussually the last item on the list)
Notice the view that appears on the rigth side Select "android.permission.INTERNET"
Then a series of Ok and finally save.
Hope this helps
I am late but i want to complete the answer.
An permission is added in manifest.xml like
<uses-permission android:name="android.permission.INTERNET"/>
This is enough for standard permissions where no permission is prompted to the user. However, it is not enough to add permission only to manifest if it is a dangerous permission. See android doc. Like Camera, Storage permissions.
<uses-permission android:name="android.permission.CAMERA"/>
You will need to ask permission from user. I use RxPermission library that is widely used library for asking permission. Because it is long code which we have to write to ask permission.
RxPermissions rxPermissions = new RxPermissions(this); // where this is an Activity instance // Must be done during an initialization phase like onCreate
rxPermissions
.request(Manifest.permission.CAMERA)
.subscribe(granted -> {
if (granted) { // Always true pre-M
// I can control the camera now
} else {
// Oups permission denied
}
});
Add this library to your app
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.tbruyelle:rxpermissions:0.10.1'
implementation 'com.jakewharton.rxbinding2:rxbinding:2.1.1'
}
That may be also interesting in context of adding INTERNET permission to your application:
Google has also given each app Internet access, effectively removing the Internet access permission. Oh, sure, Android developers still have to declare they want Internet access when putting together the app. But users can no longer see the Internet access permission when installing an app and current apps that don’t have Internet access can now gain Internet access with an automatic update without prompting you.
Source: http://www.howtogeek.com/190863/androids-app-permissions-were-just-simplified-now-theyre-much-less-secure/
Bottom line is that you still have to add INTERNET permission in manifest file but application will be updated on user's devices without asking them for new permission.
You have to use both Network and Access Network State in manifest file while you are trying load or access to the internet through android emulator.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
If you are giving only .INTERNET permission, it won't access to the internet.
** For Activity Recognition like Foot Step Counter
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
** For Internet
<uses-permission android:name="android.permission.INTERNET" />
** For Call Phone
<uses-permission android:name="android.permission.CALL_PHONE" />
[![enter image description here][1]][1]
If you're using Android Studio, hover over the code that requires the permission and click "Add Permission .."
Then you can check the changes in AndroidManifest.xml with git.
Related
Our app was currently removed from google play for having the SMS permission. We already removed the permission and uploaded a new apk but the status of the project is still removed. Do we have to wait for them to review, it or is there any other necessary steps/action needed for the project to be back on Google Play?
Fillup google docs for permission.
Make sure your SMS permission is given in manifest and give the pop up in user level.
Contact google developers as soon as possible.
See this
May be any of the 3rd party library you are using in your project is already using those permissions. And when you build your project it merged all the AndroidManifest file in a single Merged Manifest file. This is the reason you are getting this warning because your final manifest has any of those permission(s).
Solution 1: After build your project,
Open your project's AndroidManifest file.
Open the Merged Manifest tab in the bottom.
Search for any of those permission. (example- READ_SMS)
If you get any, now it's time to remove them. Check the example
Example: If you see READ_SMS permission in Merged Manifest file, so now open your project's AndroidManifest file and add the line written below to remove that permission from your project-
<uses-permission android:name="android.permission.READ_SMS" tools:node="remove" />
Add the above permission line in your AndroidManifest file, and that's it. It will remove the Permission from the Merged Manifest file and your issue will be resolved.
AndroidManifest file
<?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.example.myapp">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_SMS" tools:node="remove" />
<application
android:name=".MyApp"
android:allowBackup="false"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:ignore="GoogleAppIndexingWarning"
tools:replace="android:allowBackup">
<activity
android:name=".SplashActivity"
android:screenOrientation="portrait"
android:theme="#style/FullscreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Solution 2: Replace/Remove those 3rd Party library which are using these permissions.
Solution 3: For safe side you can add these lines in your AndroidManifest file.
<uses-permission
android:name="android.permission.RECEIVE_SMS"
tools:node="remove" />
<uses-permission
android:name="android.permission.READ_SMS"
tools:node="remove" />
<uses-permission
android:name="android.permission.SEND_SMS"
tools:node="remove" />
<uses-permission
android:name="android.permission.WRITE_SMS"
tools:node="remove" />
<uses-permission
android:name="android.permission.RECEIVE_WAP_PUSH"
tools:node="remove" />
<uses-permission
android:name="android.permission.RECEIVE_MMS"
tools:node="remove" />
<uses-permission
android:name="android.permission.READ_CALL_LOG"
tools:node="remove" />
<uses-permission
android:name="android.permission.WRITE_CALL_LOG"
tools:node="remove" />
<uses-permission
android:name="android.permission.PROCESS_OUTGOING_CALLS"
tools:node="remove" />
these lines will remove all the restricted permission(s) according to Permission Policy if any used.
Hope it will be helpful.
The issue happened with our apk as well, we removed the alpha,beta and internal test channel apks with updated apks without any violation of policy and they restored the production apk for us.
We wrote all permission codes between suitable tags. But when i install the program there is no ask about permissions.
Where is my fault?
this my manifest.xml file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.berker.notkayit">
<uses-sdk
android:minSdkVersion="21"
android:targetSdkVersion="24" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Writing permissions in Manifest file won't ask permissions on runtime. In order to show permissions, you need to write code in your application instances. Refer this link https://developer.android.com/training/permissions/requesting.html
are u testing the app in marshmallow or above device means it won't ask for permission during installation but it will permission during run time have u added the runtime permission codes
It dependences on your devices, if you device Android version is below 6.0, then you way is ok, however, if you device version is 6.0 and above then you need add runtime permission, check this link https://github.com/googlesamples/easypermissions
I know it may be silly question and I have referred all the similar question before but unfortunately I could resolve this issue. Most probably it is problem in my Manifest.xml file.
When I am trying to access location, app is crashing
here is my manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.tt.test" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".sTest"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.test.tt.test.sService">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </service>
<service android:name="com.test.tt.test.sServiceRequest" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
</application>
when I run it throw this error
java.lang.SecurityException: Neither user 11029 nor current process has android.permission.ACCESS_COARSE_LOCATION.
Similar with other permissions. I can not see any mistake in my manifest file. Help appreciated
If you are running on a device on Android Marshmallow and above:
If the device is running Android 6.0 or higher and if the app's target SDK is 23 or higher, the app not just have to list the permissions in the manifest but also must request each dangerous permission it needs while the app is running.
More info:
http://developer.android.com/training/permissions/requesting.html
and
http://developer.android.com/guide/topics/security/permissions.html#normal-dangerous
This means you have some wrong information or malformed info in your menifest file and that is the reason none of your Permission is not identified by your app. Just make sure you have cleaned ANDROIDMANIFEST file with any malformed data.
It will work and all permission should be outside Application tag
move the uses-permission outside application just below the manifest tag
Moving permission section solved my problem with "Neither user or current process has android.permission.READ_PHONE_STATE". Thank you so much to everyone in this forum.
In reference to others, my changes are bellow:
Original:
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-feature
android:name="android.hardware.nfc"
android:required="true" />
<activity android:name=".NfcRead"></activity>
</application>
Change:
<uses-permission android:name="android.permission.NFC" />
<uses-feature
android:name="android.hardware.nfc"
android:required="true" />
<activity android:name=".NfcRead"></activity>
</application>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
This exception is related to the runtime permission system in Android 6 and above. The Location permission comes under dangerous permission [check here], so you must have to fulfill below 2 minimum requirements to handle these permissions:
Declared below 2 permission in manifest (These permissions must be outside application tag)
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION " />
Check for the granted permission at runtime using checkSelfPermission() and request permissions using requestPermissions() if not already granted.
If you have already done both of the above then and still getting error then check below:
You App's targetSdkVersion (should be >=23) [If the application's targetSdkVersion is set to less than 23. It will be assumed that application is not tested with new permission system yet and will switch to the same old behavior: user has to accept every single permission at install time and they will be all granted once installed].
Check if you have any thing wrong with you manifest file. You might have malformed manifest file.
Check if you are calling any function, that works on location data, before the user Accept/revoked runtime location permission dialog?
Clean you app (Clean build) and re-run.
Hope this may help :-)
I know it may be silly question and I have referred all the similar question before but unfortunately I could resolve this issue. Most probably it is problem in my Manifest.xml file.
When I am trying to access location, app is crashing
here is my manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.tt.test" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".sTest"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.test.tt.test.sService">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </service>
<service android:name="com.test.tt.test.sServiceRequest" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
</application>
when I run it throw this error
java.lang.SecurityException: Neither user 11029 nor current process has android.permission.ACCESS_COARSE_LOCATION.
Similar with other permissions. I can not see any mistake in my manifest file. Help appreciated
If you are running on a device on Android Marshmallow and above:
If the device is running Android 6.0 or higher and if the app's target SDK is 23 or higher, the app not just have to list the permissions in the manifest but also must request each dangerous permission it needs while the app is running.
More info:
http://developer.android.com/training/permissions/requesting.html
and
http://developer.android.com/guide/topics/security/permissions.html#normal-dangerous
This means you have some wrong information or malformed info in your menifest file and that is the reason none of your Permission is not identified by your app. Just make sure you have cleaned ANDROIDMANIFEST file with any malformed data.
It will work and all permission should be outside Application tag
move the uses-permission outside application just below the manifest tag
Moving permission section solved my problem with "Neither user or current process has android.permission.READ_PHONE_STATE". Thank you so much to everyone in this forum.
In reference to others, my changes are bellow:
Original:
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-feature
android:name="android.hardware.nfc"
android:required="true" />
<activity android:name=".NfcRead"></activity>
</application>
Change:
<uses-permission android:name="android.permission.NFC" />
<uses-feature
android:name="android.hardware.nfc"
android:required="true" />
<activity android:name=".NfcRead"></activity>
</application>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
This exception is related to the runtime permission system in Android 6 and above. The Location permission comes under dangerous permission [check here], so you must have to fulfill below 2 minimum requirements to handle these permissions:
Declared below 2 permission in manifest (These permissions must be outside application tag)
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION " />
Check for the granted permission at runtime using checkSelfPermission() and request permissions using requestPermissions() if not already granted.
If you have already done both of the above then and still getting error then check below:
You App's targetSdkVersion (should be >=23) [If the application's targetSdkVersion is set to less than 23. It will be assumed that application is not tested with new permission system yet and will switch to the same old behavior: user has to accept every single permission at install time and they will be all granted once installed].
Check if you have any thing wrong with you manifest file. You might have malformed manifest file.
Check if you are calling any function, that works on location data, before the user Accept/revoked runtime location permission dialog?
Clean you app (Clean build) and re-run.
Hope this may help :-)
I'm working on a simple app that browses through the user's contacts. Unfortunately I keep getting the following error:
java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.HtcContactsProvider2 uri content://com.android.contacts/contacts from pid=27455, uid=10171 requires android.permission.READ_CONTACTS
My manifest file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.helloMaps"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<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_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application android:icon="#drawable/icon"
android:label="#string/app_name"
android:debuggable="true">
<uses-library android:name="com.google.android.maps" />
<activity android:name=".MapsActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I'm trying to look at my contacts by:
Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
I've tried to add <uses-permission android:name="android.permission.READ_CONTACTS" /> or android:permission="android.permission.READ_CONTACTS" to <application> or <activity>, but both didn't work.
I'm running out of options, does anybody know what I'm missing here?
the <uses-permission> should be contained in the <manifest> element. See Structure of the Manifest File. So trying putting it into <application> or <activity>, won't work. Desperation move: try to move <uses-sdk> before <application>
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
Also if you can test without the other permissions, remove them.
EDIT: Can you please check if this is your TOP line in your manifest file:
<?xml version="1.0" encoding="utf-8"?>
I was totally stuck on this until I read this article about how permissions are handled starting with SDK 23. The critical hint:
If the application's targetSdkVersion is set to less than 23. It will be assumed that application is not tested with new permission system yet and will switch to the same old behavior: user has to accept every single permission at install time and they will be all granted once installed !
I opened up my gradle.build file and changed targetSdkVersion 23 to targetSdkVersion 22, and now everything works great! I'll eventually find time to build in the new permissions system and switch back to targetSdkVersion 23, which is probably the more correct answer. This is a temporary shortcut.
None of the above helped. The solution is quite simple.
you'll need a runtime permission request.
with or without placing the permission in your manifest, You will need to request that permission from the User on-the-fly.
if( getApplicationContext().checkSelfPermission( Manifest.permission.READ_CONTACTS ) != PackageManager.PERMISSION_GRANTED )
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.READ_CONTACTS}, resultValue);
only then after the approval you will be able to query the contacts phone number/name etc.
Try this in your on create method
ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.READ_CONTACTS},1);
I had the same problem and none of the solutions I read helped to resolve it until I added the WRITE_EXTERNAL_STORAGE permission along with the READ_CONTACTS permission.
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
I ran into this issue today and none of the above fixes worked for me.
What the issue ended up being had to do with my Eclipse. What I had written in the manifest.xml and what was in the Permissions tab weren't the same. I had the READ_CONTACTS permission in my manifest.xml, but READ_PROFILE was in it's place under my permission's tab.
I know this is an old thread, but hopefully if someone has the same issue I did they'll stumble across this.
Thanks!