How to get "Device ID" from Android device under software update settings - java

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/

Related

Android App doesn't have internet connection - No Permissions required

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

Android BLE onScanResult is never called

I have developed a little BLE App for Android which connects with my mobile music Box.
Everything works fine on my phone (Android 9). So I bought a tablet (Android 9) and there onScanResult is never called, but when I search with Android board-function I see the Bluetooth device.
ACCESS_FINE_LOCATION
BLUETOOTH
BLUETOOTH_ADMIN
is set and Location is set to on.
if your bluetooth is on then give runtime permission of , ACCESS_FINE_LOCATION and ACCESS_CORSE_LOCATION and still you are facing this issue then gps on and restart scanning its working fine.
Required permission for BLE,
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
and check gps is enable or not
private fun enableLocation(): Boolean {
val service = activity?.getSystemService(Context.LOCATION_SERVICE) as LocationManager
val enabled = service.isProviderEnabled(LocationManager.GPS_PROVIDER)
return enabled
}
and if return false then
val intent = Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)
startActivity(intent)
for enable your gps progrmatically and if true then scan your device.
ACCESS_FINE_LOCATION could be declared in manifest but it's not treated as granted by default. Have you requested for granting this permission in runtime? If not, request for it in runtime or just go to permissions section in your app settings and grant it manually.

Old app can't get WiFi scan results on android N

I wrote an app that detects wifi networks and when I press on a network it gives me detailed info about that network. Now the problem is that I wrote it 3 years ago when Android KitKat did not require the popup permission from the user and now when I run it on android N and I press scan it neither scans nor gives me the pop-up permission.
I have not programmed android for a long time and I don't know the changes in Android app coding requirements . Any ideas why this happens?
Current permissions used by the app:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<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.READ_PHONE_STATE" />
In order to get WiFi scan results on Marshmallow and later, your app will need to request the ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission, and the Location Mode setting must be enabled as well.
From the documentation for getScanResults():
the list of access points found in the most recent scan. An app must
hold ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission in
order to get valid results
This change was made due to the fact that location can be determined from WiFi scan results.
As an extra security measure, apps now need to request the Location permission in order to see WiFi scan results, and additionally if the user sets their Location Mode to off, no app can see scan results when running in the background.
So, at a bare minimum, add the ACCESS_COARSE_LOCATION permission to your manifest in order to get WiFi scan results:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
If you keep your target API version lower than 23, you can't request permissions at runtime. In this case, your app will continue to request all permissions at install time.
If you update your app to target API version 23 or later, you will need to request all dangerous permissions at runtime. See here for an example of requesting the Location permission at runtime.

android get restful api always timeout

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

Java.lang.SecurityException:SECURE PERMISSION in android?

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.

Categories

Resources