Well, I have built an app to store values on a remote database. It works!! I didn't use an emulator for testing instead I used my own phone. Now the problem is that on my phone, it works perfectly...no issues but when I installed it on another phone, the app doesn't connect to the internet.
I have included internet permission in android manifest.xml.
I have tried these but didn't work:
Building apk and installing in the new phone.
Compiling directly to the new phone.
Sending the apk from old phone to new phone via shareit.
Creating a signed apk and installing.
Checked via wifi and mobile data (NOTE: BOTH WIFI AND MOBILE DATA WORKS IN OLD PHONE).
Checked android compatibility: supports up to android 10.
*I added error messages for try...catch blocks in form of toasts for the user to know what's the issue. and the catch exception for no internet returns connection problem. I'm getting that error message.
As I researched, I got to know that internet permission is categorized as normal permission which is not prompted to the user upon installation.
I built a second dummy app: Same issue with it... compiled directly to new phone but didn't work...it works in old phone...
Old phone: Samsung J7 Prime with Android 8.1
New Phone: Samsung J7 Pro with Android 9
Any idea or suggestion will be gladly helpful... Thank you!
in android 9 and above you have to set network Security Config
first of all in res package create xml package and in xml package create new xml resource file with network_security_config name
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
then in manifest in
android:networkSecurityConfig="#xml/network_security_config"
<uses-permission android:name="android.permission.INTERNET" />
Use debug APK instead of signed APK
please add permission on Manifest to give a permission of permission.INTERNET
Related
I have a strange issue. My app is using http to connect to a server. It works fine in many devices. However, in Xiaomi devices which has Android 9, it gives me this error:
Caused by java.io.IOException: Cleartext HTTP traffic to internet.vodafone.com.eg not permitted
at com.android.okhttp.HttpHandler$CleartextURLFilter.checkURLPermitted(HttpHandler.java:142)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:469)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:418)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:549)
at com.google.firebase.perf.network.zzd.getResponseCode(zzd.java:81)
at com.google.firebase.perf.network.zzb.getResponseCode(zzb.java:14)
at com.android.volley.toolbox.HurlStack.executeRequest(HurlStack.java:96)
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:123)
at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:131)
at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:111)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:90)
In the AndroidManifest.xml I have this:
<application
...
android:networkSecurityConfig="#xml/network_security_config"
...
</application>
My network_security_config.xml file:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">thebondnews.com</domain>
</domain-config>
</network-security-config>
Also, I have all the permission to connect to the internet. It works fine in Many devices with android 9 Like Samsung galaxy s9/s9+ and Samsung galaxy s8/s8+ and many others.
The error message was copied from Firebase Crashlatics. What is strange is that my server domain is thebondnews.com but in the log, it says internet.vodafone.com.eg or sometimes notification.etisalat.com.eg and 10.10.10.1. It is like there is kinda redirection in their devices.
Can anyone help me how to solve it? or what shall I do?
Update 1:
Could it be that I am only allowing my domain in network_security_config.xml
and because of the redirection caused by their providers the connection fails?
As Md. Asaduzzaman said in the comments.
The internet package of that user has finished and the operator tries to redirect him to the internet package page.
So it was not an issue with the app. However, some users have a limited internet package with limited access to things like Facebook, WhatsApp, Instagram..etc.
Thus, when my app tries to connect to the server, it is being redirected by the internet provider to block the traffic.
Does anyone know of a way to retrieve the Device ID found under Settings -> About tablet -> System updates -> Software update settings under the Device information header in Android versions 4.x or 5.x?
Agreed with #G.hakim , but additional to that, this API requires android.permission.READ_PHONE_STATE permission.So you need to declare the permission in AndroidManifest.xml if you want to use this api:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
If i'm not wrong you are looking for your mobile phone's device id which you can get using these line of code
TelephonyManager tm = (TelephonyManager)context.GetSystemService(Context.TelephonyService);
deviceId = tm.DeviceId;
Also requires the following permission:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Also after Android Marshmallow Or API 23 you need to ask for permissions on the fly the code reference for that can be found here:
https://blog.xamarin.com/requesting-runtime-permissions-in-android-marshmallow/
I use httpclient(apache) to get a restful API when developing an Android app,just like
HttpGet httpget = new HttpGet("http://9.123.151.73:4414/apiv1/data");
HttpResponse response = httpclient.execute(httpget);
and the xml,I have set the permission:
`<uses-permission android:name="android.permission.INTERNET" />`
but it always timeout.
Then I try these cases:
Open the url in browser,it works
New a simple java project with the same code, it works
Replace the url with other rest API ,such as:
http://api.search.yahoo.co/NewsSearchService/V1/, works
So, could you give me any advices for this problem,I wonder why the rest API can not be used in Android app,what is the mistake?
I beleive it is due to the permission not set to make network connections. Here is what you need to add to your AndroidMainfest.xml file to allow access to the internet:
<manifest xlmns:android...>
...
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>
Here is the permission description:
INTERNET Allows applications to open network sockets.
You can check more about the permission from the link:
Here is how you can set the permission if you are using eclipse:
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), select the "Permissions" tab along the bottom of the editor
(Manifest - Application - Permissions - Instrumentation -
AndroidManifest.xml), then "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
http://developer.android.com/reference/android/Manifest.permission.html
I'm using google api java client for connecting to Google Docs in Android app.
Once in a while i get following exception:
UnknownHostException: www.google.com
Code:
transport = AndroidHttp.newCompatibleTransport();
ClientLogin authenticator = new ClientLogin();
authenticator.authTokenType = "writely";
authenticator.username = username.getText().toString();
authenticator.password = password.getText().toString();
authenticator.transport = transport;
authenticator.authenticate().getAuthorizationHeaderValue();
Device reset clears exception but is it necessary.
I suspected for DNS caching and tried following but didnt work. Im not behind a proxy as far I know.
Security.setProperty("networkaddress.cache.ttl","0");
System.setProperty("networkaddress.cache.ttl","0");
System.setProperty("networkaddress.cache.negative.ttl","0");
System.setProperty("net.eth0.dns1","8.8.8.8");
System.setProperty("net.dns1","8.8.8.8");
Last time it occurred was this morning when one network connection "died", cell auto got second one, tried to do ClientLogin but failed with exception.
Just to make it clear, Im talking about DEVICE (htc desire hd), not emulator.
Thanks in advance.
add this line to your AndroidManifest.xml file, just after the <manifest> tag and before the <application> tag:
<uses-permission android:name="android.permission.INTERNET" />
I run into this daily. I think it is a bug in the emulator. After reset of emulator it works again and it never happened on a real device.
Edit: most definitely a bug in the emulator. See this thread. There are also several posts on StackOverflow regarding those emulator connection issues.
Iam getting this error on my log
07-06 06:22:07.419: ERROR/AndroidRuntime(2618): java.lang.SecurityException: SECURE PERMISSION: Neither user 10070 nor current process has android.permission.WRITE_SECURE_SETTINGS.
I used like this
in activity file
private static final String SECURE_SETTINGS = android.Manifest.permission.WRITE_SECURE_SETTINGS;
mContext.enforceCallingOrSelfPermission(SECURE_SETTINGS,
"BLUETOOTH_ADMIN permission");
in manifest file
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
Why does it give error?
The WRITE_SECURE_SETTINGS permission is not available to apps which aren't part of the firmware because secure settings are designed to be secured against modification by third party apps.
You can only read this settings if your phone doesn't have root access. To enable bluetooth you can use this references http://developer.android.com/guide/topics/wireless/bluetooth.html.
However, this is above sdk5... I'm not really sure if it is a good idea to use bluetooth with sdk3. I also wanted to do an app which uses bluetooth and I had to switch my target level to above 2.0.1 because bluetooth below this sdk is not supported very well.