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.
Related
In my app I play some music and as any other music apps, I should stop music when the user receive a call, so, I use this permission for that:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
I use the permission for control the telephony manager.
I know some tablets devices doesn't have phone feature so for that Google Play Store filtered my app, it considered it as an app compatible only with devices which is contains phone feature.
With some search I edited my code:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-feature android:name="android.hardware.telephony" android:required="false" />
And in MainAcitivty :
if (Build.VERSION.SDK_INT >= 23) {
PackageManager pm = getApplicationContext().getPackageManager();
if (pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
checkPermission();
if (!checkPermission()) {
requestPermission();
}
}
}
My Question: after this edit, will my app show up in tablets store or should I should do something else?
This might be enough, but you should make sure you are following all the Tablet app quality guidelines.
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 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.
java.lang.SecurityException: Permission Denial: starting Intent {
act=android.intent.action.CALL dat=tel:xxxxxxxxxx
cmp=com.android.server.telecom/.components.UserCallActivity } from
ProcessRecord{9a25695 2469:in.preciseit.dialhingoli/u0a59} (pid=2469,
uid=10059) with revoked permission android.permission.CALL_PHONE
here is what i want to ask in Logcat error
I am using call function onClicklistener.
+
please define following permission in menifest file and Try. And then after not work then Read This url for marshmallow runtime permission
<uses-permission android:name="android.permission.CALL_PHONE"/>
Android 6 (SDK 23) allows users to revoke permissions from an app.
Click to read more
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.