I am pretty confused where to add the
uses-feature
tag in the manifest.
I am using the camera in my app. I added permission but I'm confused where to add features in order to use front facing camera. Can you help?
Add this under <manifest> tag, like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lalllala">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-feature android:name="android.hardware.camera" />
<application android:icon="#drawable/icon" android:label="lalla" android:debuggable="true">
</application>
</manifest>
<uses-feature> - Declares a single hardware or software feature that is used by the application.
The purpose of a declaration is to inform any external entity of the set of hardware and software features on which your application depends. The element offers a required attribute that lets you specify whether your application requires and cannot function without the declared feature, or whether it prefers to have the feature but can function without it. Because feature support can vary across Android devices, the element serves an important role in letting an application describe the device-variable features that it uses.
read for more
Below is sample code to access Device Front Camera
public Camera openFrontFacingCamera() {
int cameraCount = 0;
Camera ffCam = null;
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
// Find the total number of cameras available
cameraCount = Camera.getNumberOfCameras();
// Find the ID of the CAMERA_FACING_FRONT & open it
for (int camIdx = 0; camIdx < cameraCount; camIdx++) {
Camera.getCameraInfo(camIdx, cameraInfo);
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
try {
ffCam = Camera.open(camIdx);
} catch (RuntimeException e) {
Log.e(TAG, "Camera failed to open: " + e.getLocalizedMessage());
}
}
}
return ffCam;
}
Need following permissions
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.front" android:required="false" />
For more please read Google android developer API doc Camera, Camera.CameraInfo
Add this under manifest tag:
<!-- Request the camera permission -->
<uses-permission
android:name="android.permission.CAMERA" />
<uses-feature
android:name="android.hardware.camera"
android:required="true" />
write tags order like this
<manifest>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<application>
</application>
</manifest>
Related
With the release of API level 26, my app's core functionality broke, this being, changing the users' hotspot setting within the application.
To get and set this configuration I am using the following functions from the WifiManager hidden api: getWifiApConfiguration and setWifiApConfiguration.
Method getWifiApConfiguration = wifiManager.getClass().getMethod("getWifiApConfiguration");
getWifiApConfiguration.invoke(wifiManager);
This is working with devices prior to Android O, but in this version I get the following error:
App not allowed to read or update stored WiFi Ap config (uid = 10168)
The permissions I have declared in the manifest are:
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_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.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.NETWORK_STACK"/>
<uses-permission android:name="android.permission.TETHER_PRIVILEGED" />
How can I do this with the latest APIs?
As of Android Oreo (26), a new permission check was added to the service implementation of the getWifiApConfiguration() method:
Snippet from WifiServiceImpl.java
/**
* see {#link WifiManager#getWifiApConfiguration()}
* #return soft access point configuration
* #throws SecurityException if the caller does not have permission to retrieve the softap
* config
*/
#Override
public WifiConfiguration getWifiApConfiguration() {
enforceAccessPermission();
int uid = Binder.getCallingUid();
// only allow Settings UI to get the saved SoftApConfig
if (!mWifiPermissionsUtil.checkConfigOverridePermission(uid)) {
// random apps should not be allowed to read the user specified config
throw new SecurityException("App not allowed to read or update stored WiFi Ap config "
+ "(uid = " + uid + ")");
}
mLog.trace("getWifiApConfiguration uid=%").c(uid).flush();
return mWifiStateMachine.syncGetWifiApConfiguration();
}
Digging into the code you will quickly find out that to successfully invoke this method your application must hold the android.permission.OVERRIDE_WIFI_CONFIG permission that is a system level protected permission:
Snippet from framework AndroidManifest.xml
<!-- #SystemApi #hide Allows an application to modify any wifi configuration, even if created
by another application. Once reconfigured the original creator cannot make any further
modifications.
<p>Not for use by third-party applications. -->
<permission android:name="android.permission.OVERRIDE_WIFI_CONFIG"
android:protectionLevel="signature|privileged" />
This means that your application needs to be signed by the platform key or be privileged to use this API.
I'm using this library and trying to retrieve current location coordinates like this:
settings =
new TrackerSettings()
.setUseGPS(false)
.setUseNetwork(true)
.setUsePassive(true)
.setTimeBetweenUpdates(30 * 60 * 1000);
tracker = new LocationTracker(getBaseContext(), settings) {
#Override
public void onLocationFound(Location location) {
// Do some stuff
currentLatDouble = location.getLatitude();
currentLngDouble = location.getLongitude();
}
#Override
public void onTimeout() {
}
};
tracker.startListening();
but, I'm getting this error:
W/LocationTracker: Provider (network)
fr.quentinklein.slt.ProviderError: Provider is not enabled | ProviderError{provider='network'}
Isn't WiFi a network provider or do I need to write some code related to LocationManager too?
Please let me know what is wrong here.
Added the following permission in manifest file
<uses-permission android:name="android.permission.INTERNET" />
Allows applications to open network sockets.
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Allows an app to access approximate location.
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Allows an app to access precise location.
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Allows applications to access information about networks.
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Allows applications to access information about Wi-Fi networks.
Additionally
<uses-feature
android:name="android.hardware.location.network"
android:required="false" />
<uses-feature
android:name="android.hardware.location.gps"
android:required="false" />
Here is what i have tried.
I have implemented Zbar Scanner in android application in which I can scan barocde and get result.
I have implemented this in my android project. now I want to implement scanner which scans images(of course Bar code images) from gallery. I know this can be possible anyhow. check this link. It has barcode image scanning.
I have tried to search it out but failed. Please Help me out.
This is possible now with the new Barcode Scanning Apis available from Google Play Services 7.8 version. It has method to detect barcode passed as a bitmap.
Get path of image from gallery and convert it to bitmap and pass it like below:
Frame frame = new Frame.Builder().setBitmap(bitmap).build();
BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context)
.build();
if(barcode.isOperational()){
SparseArray<Barcode> sparseArray = barcodeDetector.detect(frame);
if(sparseArray != null && sparseArray.size() > 0){
for (int i = 0; i < sparseArray.size(); i++){
Log.d(LOG_TAG, "Value: " + sparseArray.valueAt(i).rawValue + "----" + sparseArray.valueAt(i).displayValue);
Toast.makeText(LOG_TAG, sparseArray.valueAt(i).rawValue, Toast.LENGTH_SHORT).show();
}
}else {
Log.e(LOG_TAG,"SparseArray null or empty");
}
}else{
Log.e(LOG_TAG, "Detector dependencies are not yet downloaded");
}
In your build.gradle file, include the following under dependencies section:
compile 'com.google.android.gms:play-services:7.8.+'
Following Manifest permissions are must:
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Meta data for google play services:
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Meta data for first time install/run time dependencies to be downloaded for getting barcode detector operational.
<meta-data
android:name="com.google.android.gms.vision.DEPENDENCIES"
android:value="barcode" />
For detailed usage of this api, Refer Github Sample, follow Code Lab, Documentation.
I want to access extern usb cameras via v4l on android.
I tried SimpleWebCam. After some slight modifications of the original source codes, i achieved to make it work on a rooted android device. However, on unrooted devices, it keeps complaining about "not have permission to access "/dev/video*". I checked the permission of /dev/video* with "ls -l /dev/video*", and got
crw-rw---- system camera 81, 0 2015-08-18 18:31 video0
I understand that it means /dev/video* are owned by system, and are readable/writable to users in group "camera". So I think if i add
<uses-permission android:name="android.permission.CAMERA" />
in the manifest of my app, the user id of my app will be added to the group "camera", then my app will be allowed to read data from /dev/video*.
But, it still complains about "not have permission to access /dev/video*" now.
i also tried
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
, but still not working.
Do i miss somthing or misunderstand somthing. Any help or discussion will be appreciated.
The codes i used to open device are
int opendevice(int i)
{
struct stat st;
sprintf(dev_name,"/dev/video%d",i);
if (-1 == stat (dev_name, &st)) {
LOGE("Cannot identify '%s': %d, %s", dev_name, errno, strerror (errno));
return ERROR_LOCAL;
}
if (!S_ISCHR (st.st_mode)) {
LOGE("%s is no device", dev_name);
return ERROR_LOCAL;
}
fd = open (dev_name, O_RDWR);// | O_NONBLOCK, 0);
if (-1 == fd) {
LOGE("Cannot open '%s': %d, %s", dev_name, errno, strerror (errno));
return ERROR_LOCAL;
}
return SUCCESS_LOCAL;
}
The return value of open is always -1, with logcat:
Cannot open '/dev/video3': 13, Permission denied
I finally achieve to read images from the external usb camera on unrooted android devices using an opensource project named uvccamera.
Here is the link, https://github.com/saki4510t/UVCCamera
Try to add also
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
in your manifest file:
http://developer.android.com/reference/android/hardware/Camera.html
I've integrated Camera within my app. The below codes are working fine when I'm running on emulator and I've selected webcam as my camera in ADB. But when I'm running on Actual device like Nexus 7 then my app is not able to detect camera. camera is working fine in this tablet independently but not within my app.
CameraActivity.java
//I've imported hardware camera class
import android.hardware.Camera;
import android.hardware.Camera.CameraInfo;
// Some activity code
if (!getPackageManager().
hasSystemFeature(PackageManager.FEATURE_CAMERA)) { // Issue is coming from here.
Toast.makeText(this, "No camera on this device", Toast.LENGTH_LONG)
.show();
} else {
cameraId = findFrontFacingCamera();
if (cameraId < 0) {
Toast.makeText(this, "No front facing camera found.",
Toast.LENGTH_LONG).show();
} else {
camera = Camera.open(cameraId);
}
}
Mainfest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" >
</uses-permission>
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
Make changes here
try to check:
hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)
Instead:
hasSystemFeature(PackageManager.FEATURE_CAMERA)
Nexus 7 having only front-facing camera.
Android camera selection algorithm defaults to the rear camera.