I am trying to get mobile blue-tooth mac id programmatically.i saw some link and i got this coce.
String macAddress = android.provider.Settings.Secure.getString(context.getContentResolver(), "bluetooth_address");
upto nougat this code is working fine.But i am getting null in OREO(8.0.0) and i gave permission in manifest file.
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
So is there a way to get the bluetooth mac address in OREO?
The blue-tooth mac address is only available to system apps in Android Oreo. Please check this answer for details. Moreover you can also read this article for more information.
Related
I am currently able to get the Bluetooth adapter mac address on devices with sdk from Marshmallow till Oreo.
However, starting Pie, the retrieved mac address is null.
The following method is working only till and including oreo.
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission
android:name="android.permission.LOCAL_MAC_ADDRESS"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="READ_PRIVILEGED_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH" />
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
String macAddress = Settings.Secure.getString(context.getContentResolver(), "bluetooth_address");
return macAddress;
I also tried to access BluetoothAdapter.getDefaultAdapter().getAddress() but it returns a fake Mac address like this "02:00:00:00:00"
I only ask the user for runtime permission for fine location. Should I ask for something else? Is there a way to achieve this on Pie and 10?
N.B: I know such app can not be uploaded to Google Play. I just want to implement this for testing purposes on personal devices.
I am writing an app that needs to send SMS, if device support it, appart from Internet access and bluetooth communication. In the manifest I have these permissions:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.SEND_SMS" />
If I send the app to a 4.4.2 device using USB, everything works well. If I deploy that app on the google play, the same device can not see that app (meaning that it is not compliant with the device).
If I remove this line:
and deploy app on google play again, I can install it on the 4.4.2 device.
My question is:
Why does
<uses-permission android:name="android.permission.SEND_SMS" />
permission works when app is deployd by USB but prevents app from being installed if using google play?
Thanks a lot
Imo
android.telephony.gsm.SmsManager smsManager = android.telephony.gsm.SmsManager.getDefault();
smsManager.sendTextMessage(91xxxxxxxxxx, null, "message", null, null);
Use this code to send text messages which gives you various choices over send the message through all possible messengers.
This code works on every platform.
I'm building a Cordova app that needs to access WiFi on Android and disable the currently connected network in order to prevent automatic disconnection from the network i'm having it connect to (since there is no internet).
The problem is that when testing on Android Oreo 8.0+ I am getting this error in adb logcat and I can't figure out what I need to do to fix this:
E/WifiConfigManager: UID 10315 does not have permission to update configuration "Test SSID"WPA_PSK
E/WifiStateMachine: Failed to disable network
These are the perms listed in manifest:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.OVERRIDE_WIFI_CONFIG" />
<uses-permission android:name="android.permission.INTERNET" />
The OVERRIDE_WIFI_CONFIG perm I found on this post, but that doesn't seem to help in my specific situation: Changing Android hotspot settings
I found this specific error located in this file:
https://android.googlesource.com/platform/frameworks/opt/net/wifi/+/master/service/java/com/android/server/wifi/WifiConfigManager.java#984
Which calls canModifyNetwork which I found here:
https://android.googlesource.com/platform/frameworks/opt/net/wifi/+/master/service/java/com/android/server/wifi/WifiConfigManager.java#651
Can anybody more experienced with Android help me to resolve this issue, and what needs to be done in order to allow my app to disable networks?
Does this mean that apps are not allowed to disable a network if it wasn't created by the app?? Please help I don't know where to go from here!
I did find this post as well, which references 6.0, but is this true that we're basically completely locked out of disabling networks we didn't create? Android 6.0 Cannot add WifiConfiguration if there is already another WifiConfiguration for that SSID
I am not able to answer your question per se, but I can answer this
Does this mean that apps are not allowed to disable a network if it
wasn't created by the app?
That's correct, as according the documentation of the method disableNetwork:
Disable a configured network. The specified network will not be a
candidate for associating. This may result in the asynchronous
delivery of state change events. Applications are not allowed to
disable networks created by other applications.
So if the user has already connected to this network using the Android system, in Oreo you won't be able to disable the network.
Though the method disableNetwork returns true or false in the case of success or failure
I want to get udid of android emulator..How can i get it.Has anyone implemented it before?
Usually you can use TelephonyManager.getDeviceId() to get udid of a device, but if you are using Android emulator, it will return null. Docs here
Update:
You need to require READ_PHONE_STATE permission in your AndroidManifest.xml, i.e., by adding following line in the file:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
I'm trying to receive data from a multicast address, but the call to MulticastSocket.receive() blocks until a timeout takes place.
I did some network sniffing and found out that my device (and the emulator) never send a MulticastSocket.joinGroup request.
I tried running the same Java code from my PC as a standalone application and it worked well. Could it be that the Android platform blocks IGMP join requests?
Has anyone succeeded with Multicast on Android before?
My manifest file contains the following permission:
I am running my application on 2.1 (Both emulator & device).
Any ideas anyone?
Thanks,
Lukas gives the best explanation and examples that I've seen on his blog: http://codeisland.org/2012/udp-multicast-on-android
In summary:
1. You need the permissions:
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
2. You need a lock:
WifiManager wifi = (WifiManager)getSystemService(Context.WIFI_SERVICE);
if (wifi != null){
WifiManager.MulticastLock lock = wifi.createMulticastLock("mylock");
lock.acquire();
}
3. You have to have a device that supports receiving multicast. Or you can follow his work around for rooted devices.
As it seems, there is no proper multicast support in the emulator.
Here's a bug report and related thread. It is being fixed for froyo.
You need to do something like this
WifiManager wifi = (WifiManager)getSystemService( Context.WIFI_SERVICE );
if(wifi != null)
{
MulticastLock mcLock = wifi.createMulticastLock("mylock");
mcLock.acquire();
}
Reference:
http://developer.android.com/reference/android/net/wifi/WifiManager.MulticastLock.html
I read all 2.1 devices not supporting IGMP stack.
IGMP was missing on different HTC, Samsung, and Motorola devices of all android version from 2.1 up to 3.2.
Link in which i read http://www.programmingmobile.com/2012/01/multicast-and-android-big-headache.html