Internet access with Android M - java

I'm trying to do HTTP requests in Anrdoid M. But every time I get the error:
java.lang.SecurityException: Permission denied (missing INTERNET permission?)
As far as I know every app has the Internet permission by default in Android M. So why does this error occur?
I also tried adding the permission to my manifest and to get a runtime permission, but both without success.
<?xml version="1.0" encoding="utf-8"?>
<application
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

As far as I know every APp has INTERNET permission by default in Android M
No, they do not.
So why does this error occur?
Apparently, you do not have the <uses-permission> element, or it is in the wrong spot.
and to get a runtime permission
The INTERNET permission is not dangerous and so does not require with the runtime permission system.

You must write the permission outside the application tag
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
To
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
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>

As for the specific android.permission.INTERNET permission, it is still mandatory for apps that will access the Internet. If a developer were to publish an app without defining it in the Android manifest, an exception will be thrown the first time a connection attempt is made, and the app will possibly crash. This is no different than before.
So you can check in your manifest the permition for internet and network state
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

You must have the Internet permission in order to get access to the internet.
Use <uses-permission android:name="android.permission.INTERNET"/>
where I showed.

Related

App is not compatible with TVs on closed testing in the Google Play. This item is not compatible with your device

I'm developing an app for Android TV and TV-boxes.
My problem is that Android TV devices are available for installing my app from Google Play for internal testing, but NOT available for closed testing (but it still can be installed on the smartphones).
Screenshot: Google Play install dialog
My app starting from StartScreenActivity (it's splash screen).
The QUERY_ALL_PACKAGES is required for my app and declared.
AndroidManifest.xml:
<?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.INTERNET" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />
<uses-feature
android:name="android.software.leanback"
android:required="false" />
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:banner="#mipmap/appbanner">
<activity
android:name=".ui.presentation.StartScreenActivity"
android:exported="true"
android:launchMode="singleTask"
android:screenOrientation="landscape"
android:theme="#style/SplashTheme">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.presentation.MainActivity"
android:windowSoftInputMode="adjustPan"
android:screenOrientation="landscape"
android:exported="false">
</activity>
</application>
</manifest>
On the internal testing it works like expected, but no one can to install an app to TV on the close testing. Setting the android.software.leanback as required not helped - it just making all others devices not available for install.
What am I doing wrong? Please advise.
It was non-obvious, but all you need is to add Android TV form factor to the Google Play Console:
Release -> Advanced Settings -> Form Factors -> Add
How to add the form factor to the Play Console
I waited over 24 hours before my application was approved.
Now all TV devices are available.

Android App ist running on Device in USB-Debug-Mode but not after APK-Install

I am very new In Android Development and developed a "Time Stamp Clock - App" which reads NFC-Tags.
Everything fine, it is running on Device via USB-Debug-Mode without Errors as expected. When I build APK and install on the same Device, the installing is without errors, but after that, the open-button is grayed out and inactive and there is no desktop-icon to launch. In the APPS Overview it is displayed, but not able to open.
Can someone tell me, what can i do, to figure it out, what is going wrong there?
EDIT:
Manifest:
<?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.comidoszeiterfassung">
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-sdk android:minSdkVersion="21"
android:targetSdkVersion="30"></uses-sdk>
<application
android:name=".myGLOBAL"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.ComidosZeiterfassung"
tools:ignore="Instantiatable">
<activity
android:name=".ui.login.MainActivity"
android:label="#string/title_activity_main"
android:theme="#style/Theme.ComidosZeiterfassung.NoActionBar"
android:exported="true">
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<data android:mimeType="text/plain" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ui.login.LoginActivity"
android:label="#string/app_name"
android:exported="true">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
</application>
</manifest>
It is a simple structure in the app. LoginActivity as Start-Activity and a TabbedActivity for the NFC-Stuff.

always get java.lang.SecurityException: Permission Denial trying to read the data from external storage

I am creating the media viewer app for android.When my app is running on mobile is works great, but when I run my app on tablet it crashes.I always get such exception:
java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/audio/media from pid=26136, uid=10096 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
here is my code:
SortedSet<String> dirList=new TreeSet<String>();
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String[] projection = {MediaStore.Audio.AudioColumns.DATA};
Cursor cursor = null;
if (uri != null)
cursor= context.getContentResolver().query(uri,projection,null,null,null);
if (cursor != null && cursor.moveToFirst()) {
do {
String tempDir = cursor.getString(0);
tempDir = tempDir.substring(0, tempDir.lastIndexOf("/"));
try {
dirList.add(tempDir);
} catch(Exception e) {
e.printStackTrace();
}
} while (cursor.moveToNext());
directories = new String[dirList.size()];
dirList.toArray(directories);
directories=mediaFilter.filterMediaFiles(directories);
if(!isInstalled){
isInstalled=true;
installAudioDetails();
}
return true;
}
}
manifest code:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.vasylpaliy.mediaview">
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<application
android:allowBackup="true"
android:largeHeap="true"
android:icon="#drawable/gallery_icon"
android:label="#string/app_name"
android:theme="#style/SelectTheme">
<activity
android:name=".MainActivity"
android:theme="#style/ImageTheme"
android:label="#string/photos">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ImageSelecter"
android:parentActivityName=".MainActivity"
android:label="#string/photos"
android:theme="#style/SelectTheme">
<intent-filter>
<action android:name="android.intent.action.ImageSelecter" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Settings"
android:label="Setting"
android:parentActivityName="com.example.vasylpaliy.mediaview.ImageSelecter">
<intent-filter>
<action android:name="android.intent.action.FullScreenImage" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AudioList"
android:theme="#style/AudioListTheme"
android:label="#string/audio_list">
</activity>
<activity
android:name=".AudioAction"
android:icon="#drawable/red_music"
android:configChanges="keyboardHidden|orientation"
android:theme="#style/AudioPlayerTheme"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:parentActivityName="com.example.vasylpaliy.mediaview.AudioList"
android:label="#string/audio_view">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<data android:mimeType="audio/*"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity
android:name=".ImageSlider"
android:theme="#style/ImageSlider"
android:parentActivityName=".ImageSelecter"
android:label="Image">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
<activity
android:name="com.audioplayer.AudioPlayer"
android:theme="#style/AudioPlayerTheme">
</activity>
<service
android:name="com.audioplayer.AudioService">
</service>
</application>
</manifest>
set permission on AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Home"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".cst_cell_album_list"
android:label="#string/title_activity_cst_cell_album_list" >
</activity>
<service android:enabled="true" android:name="com.vvs.root.memusic.PlayerService" />
<receiver android:name="com.vvs.root.memusic.PlayerService$MyReceiver" >
</receiver>
</application>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
By the looks of it you have set up the permissions correctly in your manifest. This crash might only happen on Android-M API23. The reason for that is READ_EXTERNAL_STORAGE is considered a Dangerous permission. So even though you have declared it in the Manifest, you need make sure to get the user to accept this permission at runtime. How to do this? Read here: http://developer.android.com/training/permissions/requesting.html
This is the right way to do it, but if you want to take the short way around, you could set the targetSdkVersion to 22 or lower. This will ensure that even when running on the M version, all permissions are granted. But still the user can manually turn off these permissions. So that's the downfall.
Note: This lesson describes how you implement permissions requests on
apps that target API level 23 or higher, and are running on a device
that's running Android 6.0 (API level 23) or higher. If the device or
the app's targetSdkVersion is 22 or lower, the system prompts the user
to grant all dangerous permissions when they install or update the
app.

How to fix INSTALL_PARSE_FAILED_MANIFEST_MALFORMED in my android application

Hi I am trying to experiment with gcm but unable to make it work. Don't know where I am messing with it, below is the error I am getting. I am trying to deploy my application directly on device and debug from there but when ever I try to deploy it gives this error
Waiting for device.
Target device: HT24LW108632
Uploading file
local path: D:\Data\Android\AndroidTest\out\production\AndroidTest\AndroidTest.apk
remote path: /data/local/tmp/Android.Test
Installing Android.Test
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/Android.Test"
pkg: /data/local/tmp/Android.Test
Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED]
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="Android.Test"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="14"/>
<permission
android:name="Android.Test.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="Android.Test.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<application android:label="#string/app_name" android:icon="#drawable/ic_launcher">
<activity android:name="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>
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="Android.Test" />
</intent-filter>
</receiver>
<service android:name=".GCMIntentService" />
</application>
</manifest>
My Device is HTC OneX
Android Version: 4.03
HTC Sense Version: 4.0
Software number: 1.29.110.11
HTC SDK API Level: 4.12
HTC Extension version: HTCExtension_403_1_GA_7
Please guide as I am new fish in Android Sea.
Edit-1:
I have noticed that if I comment this below line then application does deploy and execute but obviously I cant go forward without below mentioned permission ... please help....
<permission android:name="Android.Test.permission.C2D_MESSAGE" android:protectionLevel="signature" />
Change name package with Caps letters to little letters.
Change your
android:name="MainActivity"
TO
android:name=".MainActivity"
OR add the fully qualified package name in lowercase before your class name
android:name="thepackage.MainActivity"
Do change all the attributes named as android:name inside the activity tags as I suggested.
Instead of:
<permission android:name="android.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
to:
<uses-permission android:name="android.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
Try that.
<activity android:name="MainActivity"
should be formed like
<activity android:name="com.company.appname"
to do this without errors go to package (right click) > android tools > rename app package
try to write activity name follow by "."
Instead of
<activity android:name="MainActivity"
android:label="#string/app_name">
use
<activity android:name=".MainActivity"
android:label="#string/app_name">
I met this same issue in android studio
what solve this is to let company domain to be all small letters,
There's issue about this: http://code.google.com/p/android/issues/detail?id=37658
Capital letters can't be used in package names within permissions. You got (same as me) into difficult situation when you have deployed application with package name like this and you need to use GCM.
I tried to use some kind of short form of permission:
<permission android:name=".permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name=".permission.C2D_MESSAGE" />
I also defined service in the same way. It had to be in application package.
It worked on Android 4.3. Probably on 4.2 also. I know that on 4.0.3 it didn't.
make sure your package name is in small letters...
worked for me
write the java package name and all folders name in lowercase, it will work fine...
In my case I was mentioned the package name in small letters only. But for few of the activities I named it with partial name i.e android:name=".ContactUs" . After I solved it by prefixing full package name before all the activity name, service name and broadcast provider name in Manifest file.
Working code
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="vcan.doit.com">
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.DesignDemo">
<activity
android:name="vcan.doit.com.LoginActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="vcan.doit.com.MainActivity"
android:theme="#style/Theme.DesignDemo" />
<activity
android:name="vcan.doit.com.CheeseDetailActivity"
android:parentActivityName="vcan.doit.com.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="vcan.doit.com.MainActivity" />
</activity>
<service android:name="vcan.doit.com.PushNotification.MyAndroidFirebaseMsgService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name="vcan.doit.com.PushNotification.MyAndroidFirebaseInstanceIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<activity
android:name="vcan.doit.com.AboutUs"
android:label="#string/abt_us"
android:parentActivityName="vcan.doit.com.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="vcan.doit.com.MainActivity" />
</activity>
<activity
android:name="vcan.doit.com.ContactUs"
android:label="#string/contact_us"
android:parentActivityName="vcan.doit.com.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="vcan.doit.com.MainActivity" />
</activity>
<activity android:name="vcan.doit.com.WriteToUs"
android:label="#string/write_us"
android:parentActivityName="vcan.doit.com.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="vcan.doit.com.MainActivity" />
</activity>
</application>
I had this problem. My device memory was full. I solved my problem with freeing device memory.
For Android 12 (Android ", API Level 31) you can find this same error because of behavioural changes.
To get rid of it you must add android:exported="true" (or false*) to any <activity>, <activity-alias>,<service>, or <receiver> components that have <intent-filter>s declared in the app’s AndroidManifest.xml file.
* More info: Related official documentation

Android receive sms only works in emulator (onReceive not called?)

Iam coding a little gps tracker wo sends me the gps coordinates when it receives a sms.
It works with 2 emulators and I get the message with the gps coordinates.
Then I tried it on my HTC Desire and send myself an sms.
But nothing happend!
Normally when the onReceive is called it shows a message with toast and sends an sms with gps coordinates but nothing is happening ;-/
Here the manifest:
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".GPSActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".SmsReceiver" android:enabled="true">
<intent-filter>
<action android:name=
"android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
any ideas?
Ps.: The code is in my last thread HERE
THANKS!

Categories