Android 6.0 RuntimeException: Fail to connect to camera service - java

An error occurred with my app which ran in Nexus5 (Android6.0).
The error was
java.lang.RuntimeException: Fail to connect to camera service
I had added the permission to the AndroidManifest.xml.
But the app is OK with another phone(Android5.1), and genymotion AVD(Android 4.0).
The key code is below
#Override
public void onResume() {
super.onResume();
try {
mCamera = Camera.open();
}catch (Exception e){
Log.e(TAG,"open camera failed",e);
}
}

Write in your gradle.build targetSdkVersion 22. It is a temporary solution but work.

open Settings -> Apps -> click you app -> Permissions -> open Camera permissions.
you can see:
http://developer.android.com/training/permissions/requesting.html

This happens because, in Android 6.0 the permission model is different. You have to implement the new permission model which asks for the permission on run time. Even if you don't ask it, you can manually enable it in the phone's app setting, but that is not gona work when you publish your app in the play store.
Here is an Article on How to get Run time permissions
Also you can check Nick's answer here for getting multiple permissions

From android 6.0 you can handle the app permission weather you will give or not specific permission for an application.
In your case if you didn't enable camera permission for your app then this issues may arise.
So, you need to enable permission from settings->apps->your_app->enable camera permission.

Add Camera Permission before Opening the Camera:
follow the Link for adding Permissions:
https://developer.android.com/training/permissions/requesting.html

Related

Android: App Can't Be Granted SYSTEM_ALERT_WINDOW,

I am creating an android application that uses WindowManager type: TYPE_APLICATION_OVERLAY so it requires this permission in the manifest file:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
Which already exists in the AndroidManifest.xml.
The problem is that once I launched my app, then go manually to my device's Draw Over Other Apps settings to grant the said permission, my app is not there.
Is there something missing? Or is Draw Over Other Apps settings the correct place to go to grant SYSTEM_ALERT_WINDOW?
My target device is android 11, api level 30.
I've followed exactly this instruction here.
I've tried launching an Intent action Settings.ACTION_MANAGE_OVERLAY_PERMISSION to automatically go the same setting to grant permission but it just go to my device's Draw Over Other Apps settings to which my app is excluded.
Screenshot to Draw Over Other Apps Settings

Xiaomi devices permission to enable apps pop-up windows while running in the background

Xiaomi devices latest update introduced a new permission that prevents my app (custom shortcuts launcher) that works in the background from working untill users enable this permission:
""Display pop-up windows while running in the background"
The question is, how can I show a permission prompt window for this permission, or at least how to redirect users to "other permissions" screen?
To redirect users to the "other permissions" screen use this code
Intent intent = new Intent("miui.intent.action.APP_PERM_EDITOR");
intent.setClassName("com.miui.securitycenter",
"com.miui.permcenter.permissions.PermissionsEditorActivity");
intent.putExtra("extra_pkgname", getPackageName());
startActivity(intent);
Source
Still looking for a way to tell if this option is check or not prgrammatically...
What's more interesting is, how some apps have managed to have this option checked before any user interaction... maybe there is some secret miui permission?...
This permission is added automatically by Google Play and isn't granted on local builds, not even release builds
if you target SDK version 30 and compile with 30, Google Play will give you the permission
compileSdkVersion 30
targetSdkVersion 30
note: I targeted 28 and it didn't work for me

Is there a path in the Emulator that can be programmatically written when the permission is denied?

In the lower Android version, /sdcard/Download can be read and written, but from Android6 when I use code File file = new File("/sdcard/Download/TestResults.xls"); it will throw exception permission denied, I want to find are there a path in emulator that jave code can directly use to create File without asking permission?
Android-M ie, API 23 introduced Runtime Permissions for reducing security flaws in android device, where users can now directly manage app permissions at runtime.
You should to use permission API version above 23.
Refer this Android marshmallow request permission?

How to display permission request with api 14

I need to display request permission (Read external storage) at run time. without the permission my app crash instantly.
In API 14 you don't need to do a request.
Just put in your manifest above <application> section:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Requesting permissions at run time is not supported with API level 14, it isn't supported until API level 23.
If you're running your app from Android Studio on a device or emulator where the app is already installed, your app will not ask for permission when it runs. If you inadvertently remove the permission you will need to manually grant the permission through the Application Manager on the device or emulator.
To prevent the initial crash, you could wrap the offending call in a permissions check.
if (ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.READ_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
// READ DATA
}
Hope this helps!

How to use code to open android.permission.SYSTEM_ALERT_WINDOW permission

In my app, I need to use android.permission.SYSTEM_ALERT_WINDOW permission. Now I know to go to setting to open it. But some of the application is automatically opened. I want to know how to do it
If i got it right, you want to ask the user for some permissions on app launch. There's a great library to help you do that in Android :
Github link for the Permission dispatcher library
You can also check these libraries :
App-Runtime-Permissions-Android
Assent
MarshmallowPermissionManager
Every app that requests the SYSTEM_ALERT_WINDOW permission and that is installed through the Play Store (version 6.0.5 or higher is required), will have granted the permission automatically.
If instead the app is sideloaded, the permission is not automatically granted. You can try to download and install the Evernote APK from apkmirror.com. As you can see you need to manually grant the permission in Settings -> Apps -> Draw over other apps.
It is a new behaviour introduced in Marshmallow 6.0.1.
If you want the app to be sideloaded, you show manually show a prompt and direct the user to enable Draw over other apps permissions from the settings. Have a look at Requesting permissions

Categories