I started developping an app and I need to use the camera of my phone, and when I use the method Camera.open(), either with cameraId or not, it returns the error "An error occurred while connecting to camera: 0". My AndroidManifest.xml is:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.telecombretagne.holowater">
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.autofocus" />
<uses-feature android:name="android.hardware.flash" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".camera"
android:label="#string/title_activity_camera"
android:theme="#style/AppTheme.NoActionBar"></activity>
</application>
</manifest>
My phone's Android Version is 6.0.1, and it's a BQ Aquaris M5.
Thanks in advance.
Devices that are running Marshmallow requires permission to be set on runtime, here's my answer from another similar question here :)
From https://developer.android.com/training/permissions/requesting.html
Note: Beginning with Android 6.0 (API level 23), users can revoke permissions from any app at any time, even if the app targets a lower API level. You should test your app to verify that it behaves properly when it's missing a needed permission, regardless of what API level your app targets.
Aside from the permissions set in the manifest, you'll need to request/check for permission on runtime. There are sample codes in there you can use, or...
Quick solution,
go to Settings-> Apps->(Your app name)->Permissions and enable the camera permission.
Done, although not recommended for final product
then try your app again. Should be working now :D
try also adding the camera ID, like
Camera.open(Camera.CameraInfo.CAMERA_FACING_BACK);
Related
I have developed an android app that uses the camera2 API. I am able to run this app on my own physical device when I'm debugging, but when I try to publish the app to the google play store, it says that my device isn't compatible - in fact, no devices are compatible with my app.
I have been in contact with google support, and they said that "your app is not compatible with most devices due to a conflict in your app’s manifest because of the following missing device feature: android.hardware.camera2. "
I have noticed that the min-sdk version in my gradle file was set to 15.
So my question is: Will my app become compatible with my devices if I change the min-sdk version to 21, or do I need to rewrite my entire code to use the deprecated camera API instead?
Thanks in advance.
*Edit:
This is my android manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="...">
<uses-feature
android:name="android.hardware.camera2"
android:required="true"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:name=".app.AppController"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<meta-data
android:name="com.google.android.gms.vision.DEPENDENCIES"
android:value="barcode"/>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".ResultsActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".QRScanner"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
There is no such feature as "android.hardware.camera2", so if you require it for your app to be installable on a device, you won't be installable anywhere, since no device anywhere reports that feature.
The camera2 API exists on all devices running Android 5.0 or later, it doesn't have a feature. Remove the feature line, and use the min-sdk line if you don't want to deal with devices too old to support camera2.
some of my customers are having trouble opening their apps after downloading them. here is my last 1 star customer review:
'Only playable in play store using open/uninstall buttons. When select on phone app phone says app not installed. uninstalling.'
I'm getting a lot of 1 star ratings because of this and it's killing me. I also get some 5 star ratings so apparently this issue only affects some users. it works fine with my phone, but won't open on a friend's, unless she opens it from the store. I may have upgraded my targetSdkVersion from 16 to 19 recently.
here is my manifest, slightly edited for privacy, I've read of opening issues on another post being caused by bad manifest settings, but none of the suggestions related to my manifest settings:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mypackage"
android:sharedUserId="com.myshareduserid"
android:versionCode="300"
android:versionName="3" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="19" />
<supports-screens android:largeScreens="true"/>
<supports-screens android:xlargeScreens="true"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_USB" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:largeHeap="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:debuggable="false" android:permission="android.permission.WRITE_EXTERNAL_STORAGE">
<activity
android:name=".MyActivity"
android:label="#string/app_name"
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|
uiMode|screenSize|smallestScreenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|
uiMode|screenSize|smallestScreenSize"/>
</application>
This is just a bug in your client's launcher app.
You cannot do a thing about that.
It might be a badly made custom launcher, or a bug, but it's out of your hands.
If that user has access to a custom recovery, he could wipe dalvik and cache, it always worked for me in that case.
I have built & sign my apk by Eclipse ADT as it is describes (export and sign by creating a new key). But it can't be install on real device while an errors occurs, such as "installer package error". I have no Android device & sent my apk to friends by email. I'm using AVD and everyth is fine with it. Any suggestions? Thanx guys.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.XXXX.YYYY"
android:versionCode="0"
android:versionName="0.9.2" android:installLocation="internalOnly">
<uses-sdk
android:minSdkVersion="13"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:hardwareAccelerated="true"
android:permission="android.permission.INTERNET"
android:allowBackup="true">
<activity
android:name="com.XXXX.YYYY.ActivityMain"
android:label="#string/main_activity_title"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.XXXX.YYYY.ActivityDetails"
android:parentActivityName="com.XXXX.YYYY.ActivityMain"
android:excludeFromRecents="true"
android:configChanges="orientation|screenSize">
</activity>
</application></manifest>
UPD: apk installs good, but the error occurs if choose Open (see screenshot). After that app works fine. But on tablet if try open app it says "App deleted".
UPD2: add supporting API 4+ meta tag for the 2nd activity, but it takes no effect
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.XXXX.YYYY.ActivityMain" />
You probably need to make sure your device and your friend's devices can install apps that are not from the play store.
This is a feature you have to specifically set, or else apps that are outside the play store will not install.
Here is how to set it:
Open settings
Find the Security settings (Pre 4.0 it is under Applications)
Look for a setting that says Unknown sources, or non-market apps
Enable that setting
Everything should work after that!
Here is an article with pictures if you are still confused :)
Your example was missing the closing </manifest> and android:enabled. I'm not sure if the latter would prevent a device from fully installing it but the first one would.
I've also had issues using the full activity names in the past, so you may want to try using simplifying them to see if it helps.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.XXXX.YYYY"
android:versionCode="0"
android:versionName="0.9.2" android:installLocation="internalOnly">
<uses-sdk
android:minSdkVersion="13"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:hardwareAccelerated="true"
android:allowBackup="true">
<activity
android:name=".ActivityMain"
android:label="#string/main_activity_title"
android:enabled="true"
android:permission="android.permission.INTERNET"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ActivityDetails"
android:parentActivityName=".ActivityMain"
android:excludeFromRecents="true"
android:configChanges="orientation|screenSize">
</activity>
</application>
</manifest>
Is "Unknown sources" option under "security" allowed on device?
My problem was a duplicate internet permission request on Manifest! When I remove that from activity app was run normally.
I've been creating an android app and when I export (and sign) it, it always adds a "Development tools (test access to protected storage" permission that I had never set.
This is my manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tdr"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="Escriure"
android:enabled="true" >
</activity>
<activity android:enabled="true" android:name="Llegir"></activity>
</application>
</manifest>
I do need to write and read files from the external storage, but not to use (¿?) development tools. Where is the problem? Thanks!
Android has added a new permission that needs to be added for Jelly Bean. Please read this article, which is copied below for quick reference:
Now, in Jelly Bean, we’re getting the “read external storage”
permission. According to Google:
READ_EXTERNAL_STORAGE
Provides protected read access to external
storage. In Android 4.1 by default all applications still have read
access. This will be changed in a future release to require that
applications explicitly request read access using this permission. If
your application already requests write access, it will automatically
get read access as well. There is a new developer option to turn on
read access restriction, for developers to test their applications
against how Android will behave in the future. So, when you hop into
the development options on your Jelly Bean device, don’t be surprised
to see this new option. We won’t see the permission in Android 4.1.0,
but most likely in 4.1.1, and its intention is to keep your device
more secure.
I have been working on an Android 2.2 app for the past three months, but decided this past week to try to build the app using Android 2.1 SDK. The app ran fine under 2.2 in the emulator, and I was able to build the source as a 2.1 project successfully, but when I try to run the app in the 2.1 emulator, I get the following runtime error:
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.tampamobileapps.testapp/.LoginScreen } from null (pid=-1, uid=-1) requires null
The app is not that complicated and only makes HTTP POST and GET requests. It also supports PayPal payments, but this API worked fine under 2.2. I have googled this error message and have not found any solutions to get rid of the error.
Any ideas?
Edit:
Here's the relevant parts of the Android manifest; the LoginScreen currently does nothing of consequence.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon"
android:debuggable="true"
android:label="#string/app_name"
android:name=".SharedApplicationContext">
<activity android:name=".LoginScreen"
android:label="#string/login_screen_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".LoginScreen"
android:label="#string/app_name">
</activity>
<activity android:name=".MainMenu"
android:label="#string/app_name">
</activity>
</application>
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
</manifest>
You have duplicate activities defined in your manifest for .LoginScreen. Try removing:
<activity android:name=".LoginScreen"
android:label="#string/app_name">
</activity>
You may need to use the android:exported="true" option.
For instance, preference activities in live wallpapers need this set. Hope this helps someone else as I know you have probably already sorted the issue.