Android TelephonyManager doesn't work with android studio simulator? - android

I am using this simple code to retreive some phone device data, but for some reason any time I open the app on the emulator, it pops up a message saying "Unfortunately *APP NAME* has closed" and then it shuts down the app.
this is the code I am using:
TelephonyManager tm=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String IMEINumber=tm.getDeviceId();
I wrote that code just to test the Telephonymanager methods but nothing works except for:
"getPhoneType();"
any ideas what's the problem? maybe it is because I am runing it on my android studio emulator?
the problem it says: getDeviceId: Neither user 10058 nor current process has android.permission.READ_PHONE_STATE though I added a permission in the manifest:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
(above the application part)
thank you for your help

Related

No Bluetooth permissions granted when coding the example app from Android developer

Sorry, that questions sound stupid but drives me crazy.
I'm about implementing an app very similar to the Bluetooth App described in Developer Android.
I don't get required permissions, though.
Yes, I ask for permission twice
a) in my manifest
b) and I check before using BT with
ActivityCompat.requestPermissions(..)
In logcat, see belove, I learn that my app doesn't get Bluetooth permission.
It isn't the first time I write a BT app. LAst time it was fine. But was a while ago.
My mobile (Nexus 5) told me something about Development Mode Active and apps would be routed to Developer Manager to be started as instant app.
I also learned that Bluetooth access is not granted to instant apps at all.
(I understand that.).
Could that be the problem? Does Android Studio produce different apps now. Does it interact in a different manager with the test hardware?
If so, how do I pursuade Android Studio to not produce an instant app?
Thank you so much in advance.
my manifest code
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
Log output:
android.permission.BLUETOOTH: denied
and some lines earlier
I/ActivityManager: START u0 {act=android.content.pm.action.REQUEST_PERMISSIONS pkg=com.android.packageinstaller cmp=com.google.android.instantapps.supervisor/.permissions.GrantPermissionsTrampoline (has extras)} from uid 10029 on display 0
W/Isotope: UID: [10029] PID: [14812] GrantPermissionsTrampoline : Permission not allowed: android.permission.BLUETOOTH
Sorry for bothering you... It was so easy. I have just deactivated that instant apps dev manager on my Android phone.
Voila, my app is an app again and no instant app. It gets all
permissions it need. Anything is fine.
I'm sorry again.

Android Things - Using both virtual keyboard and physical keyboard(barcode scanner) in Pi

I have a USB barcode scanner and I hope the virtual keyboard can still appear in EditText objects even if the barcode scanner has been connected. I can achieve this through the following code:
Settings.Secure.putString(getContentResolver(), "show_ime_with_hard_keyboard", "1");
This program execution requires special system permissions in AndroidManifest.xml:
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
The code runs well and the virtual keyboard can appear when testing. But I could not build my app in Android Things Console because of permission denied.
Failed to load apps Permission denied.
[app-debug.apk] has prohibited permissions:
android.permission.WRITE_SECURE_SETTINGS
Error in Android Things Console
Does anybody know how to build my app as system app of android things or the solution to this problem?

Why do I get "requesting permission to use WLAN. Allow?" prompt window in real mobile phone?

I use the Code A to set the enabled status of WiFi, it works well when I use Android Emulator with both API 26 and API 23 in Android Studio 3.1.3 , and none of prompt window display!
But I get a prompt window "An App is requesting permission to use WLAN. Allow?" in real mobile phone with Android 5.1 when I run the code A.
How can I make the prompt window not to display in real mobile phone? Thanks!
BTW,the real mobile phone is Samsung SM-J5008 with Android 5.1
Prompt Window
I have set the permissions
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
Code A
fun setWiFi(aWiFiDef: WiFiDef): Unit{
val wifiManager =mContext.applicationContext.getSystemService(WIFI_SERVICE) as WifiManager
wifiManager.isWifiEnabled=aWiFiDef.status
}
Android 5.1 does not have such runtime permission, so I assume, that this is a wrongly implemented permission request rational, which is shown even though the app does not need to. You wrote, that you tested with API level 26 and 23, which is Android 6.0 and higher, so these versions already have runtime permissions. Maybe you haven't seen this issue, because you haven't tested on devices below Android 6.0...
Please check if you somewhere call AppCompat.shouldShowRequestPermissionRationale() and if it is surrounded by SDK level checks or at least with a checkSelfPermission as described here: https://developer.android.com/training/permissions/requesting. Test your code in an emulator with Android 5.1 and Android 6.0. Then you should be able to reproduce that issue also on real phones.
You also need to add this to your manifest:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
According to the website below: *App on Marshmallow needs ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission and Location services should be enabled to get wifi scan results. Google probably sees scanning for wifi as a security concern, and wanted to add the location permissions as well.
I would recommend following the blog post below if you are having trouble after adding the ACCESS_COARSE_LOCATION permission to your manifest.
https://www.intentfilter.com/2016/08/programatically-connecting-to-wifi.html
EDIT
For the people down voting, please include a comment explaining why. Was my answer flat out wrong? Did I overlook somthing?
Some more information on google's geolocation service:
Google maintains a huge database for its geolocation service ("Access coarse location" permission). It consists of:
Wifi access point mappings: Wifi MAC address resolve to a geolocation
Cell tower mapping: Cell tower ID's resolve to a geolocation
So it is very possible that this user didn't include this permission and is getting this dialog box.

SMS sending permission on Active Android device

I'm a newbie with android development. So far I have developed an application which uses SMSManager.
I'm testing my application on an active device when it reaches smsManager.sendTextMessage it throws exception of android.premission.SEND_SMS.
I know that I have to get device permission.
My Question is:
Can I send SMS while uploading application right from IDE, or have to install .apk manually?
You must add the following permissions in your Manifest file:
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
If you install the application via debugging/IDE/ADB it will automatically get the permissions you require in your manifest.
So: Yes! When run on the device through the debugger, the application will be able to send test messages.
Bonus information: If you do "stuff" that the application doesn't have the proper permissions for, the debugger will give you exceptions and hints to what is wrong.

Does this Android permission prevent me from getting error reports?

In my application descriptor file there is this line:
<!--Removing the permission android.permission.INTERNET will have the side effect
of preventing you from debugging your application on your device-->
<uses-permission android:name="android.permission.INTERNET"/>
Does this mean I won't be able to debug my application with Flash Builder or does it mean that if my app crashes as a user is running it I won't get error reports in Google App developer center?
Nope and No! This is just a permission it wouldn't affect any of the above. It just allows your application to connect to Internet.
But maybe your application needs Internet just to work properly.
ANR and Crash reporting is integrated into OS, and handled via Play Store services. It has nothing to do with your App's permissions.

Categories

Resources