MediaStore.ACTION_IMAGE_CAPTURE Output is 0 Bytes - android

I am having issues capturing photos on a CAT S42 running Android 11. My code worked fine on older phones so I suspect it is an Android version thing. The following code creates the JPG file but it is always zero bytes:
private void startCamera() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (intent.resolveActivity(getPackageManager()) != null) {
File mNewPhoto = new File(getFilesDir(), "data-input-image.jpg");
mNewPhoto.delete();
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mNewPhoto));
startActivityForResult(intent, 1);
}
}
I've been experimenting with using different save locations and permissions but I can't fix it.
I've got these permissions in my manifest:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.READ_SYNC_STATS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />

Do not use Uri.fromFile() to get an uri.
Instead use FileProvider.getUriForFile().

AndroidManifest.xml
<application>
...
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths" />
</provider>
</application>
file_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths>
<files-path
name="files"
path="." />
<external-path
name="external"
path="." />
</paths>
Java code
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
String filename = getExternalFilesDir(Environment.DIRECTORY_PICTURES).getPath() + "/wallpaper.jpg";
Uri fileProvider = FileProvider.getUriForFile(this, getPackageName() + ".fileProvider", new File(filename));
cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, fileProvider);
Intent chooserIntent = Intent.createChooser(cameraIntent, "Image Chooser");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Parcelable[]{cameraIntent});
chooserIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivityForResult(chooserIntent, 1);

Related

Error while analyzing package during apk installation in app

I want to have the abilities to update my app from my application, so I can download my apk file ( each of them are signed ). And when the installation want to start:
First of all: I have preparation of installation popup which appear
Then: another popup appear and told me "A problem occurred while parsing the package"
My error is like this:
So my app, didn't update. Could you help me please ?
I use Xamarin Forms but especially for Android.
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.MyCompany.clamexdroid" android:installLocation="preferExternal">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="31" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<application android:label="ClamexDroid" android:theme="#style/MainTheme" android:icon="#mipmap/ic_launcher">
</application>
<queries>
<intent>
<action android:name="android.media.action.IMAGE_CAPTURE" />
</intent>
</queries>
</manifest>
My function when I click on my update Button
private async Task update()
{
this.popupIsVisible = false;
this.IsBusy = true;
string uri = "myLink.apk";
HttpClient cli = new HttpClient();
await cli.DownloadBasicFile(uri, DependencyService.Get<IDeviceDependency>().GetExternalAPKPath());
DependencyService.Get<IDeviceDependency>().InstallApk();
this.IsBusy = false;
}
And my InstallApk() function ( I'm sure that the file is downloaded )
public void InstallApk()
{
Intent promptInstall = new Intent(Intent.ActionView).SetDataAndType(
Android.Net.Uri.Parse($"content:///{this.GetExternalAPKPath()}"),"application/vnd.android.package-archive");
promptInstall.SetFlags(ActivityFlags.NewTask);
promptInstall.AddFlags(ActivityFlags.GrantReadUriPermission);
Android.App.Application.Context.StartActivity(promptInstall);
}
public string GetExternalAPKPath()
{
try
{
return Path.Combine(Android.App.Application.Context.GetExternalFilesDir("").AbsolutePath, "com.MyCompany.clamexdroid.apk");
}
catch (Exception e) { Console.WriteLine(e.Message); }
return "";
}
At first, you can check the apk file you had downloaded has any damage. And then you can try to the following steps to install the apk:
1.Add the provider in the AndroidManifest.xml, such as:
<application android:allowBackup="true" android:icon="#drawable/androidicon" android:label="#string/app_name" android:supportsRtl="true" android:theme="#style/AppTheme">
<provider android:name="androidx.core.content.FileProvider" android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="#xml/provider_paths" />
</provider>
</application>
2.Create the provider_paths.xml in the folder named xml below the values folder in the android part.
<paths >
<external-path
name="external_files"
path="." />
</paths>
3.Use the following code to install the apk:
var path = Path.Combine(Android.App.Application.Context.GetExternalFilesDir("").AbsolutePath, "com.MyCompany.clamexdroid.apk");
Java.IO.File file = new Java.IO.File(path);
Intent install = new Intent(Intent.ActionView);
Android.Net.Uri apkURI = FileProvider.GetUriForFile(this, this.ApplicationContext.PackageName + ".provider", file);
install.SetDataAndType(apkURI, "application/vnd.android.package-archive");
install.AddFlags(ActivityFlags.NewTask);
install.AddFlags(ActivityFlags.GrantReadUriPermission);
StartActivity(install);

Install application in Android N programmatically

I want to install an apk in my application and I'm using this method but all the time I get the errors listed below:
Code
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/test.apk");
Uri fileUri = Uri.fromFile(file);
if (Build.VERSION.SDK_INT >= 24) {
fileUri = FileProvider.getUriForFile(DLActivity.this, "codenevisha.com.apps.bartarinapp.provider",file);
}
Intent intent = new Intent(Intent.ACTION_VIEW, fileUri);
intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
intent.setDataAndType(fileUri, "application/vnd.android" + ".package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
And this is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="codenevisha.com.apps.bartarinapp">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:name=".utils.G"
android:allowBackup="true"
android:icon="#mipmap/logo_chabok"
android:label="#string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="codenevisha.com.apps.bartarinapp.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/paths"/>
</provider>
<activity
android:name=".activity.ActivitySplash"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".activity.DLActivity">
</activity>
</application>
</manifest>
I used this path.xml file:
<external-files-path
name="share"
path="."/>
But when I run my application get this error:
Process: codenevisha.com.apps.bartarinapp, PID: 21392
java.lang.RuntimeException: Unable to start activity ComponentInfo{codenevisha.com.apps.bartarinapp/codenevisha.com.apps.bartarinapp.activity.DLActivity}: java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/0/test.apk
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2984)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
Caused by: java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/0/test.apk
at android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:711)
at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:400)
at codenevisha.com.apps.bartarinapp.activity.DLActivity.onCreate(DLActivity.java:46)
at android.app.Activity.performCreate(Activity.java:6955)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
Why is this error happening?
Your FileProvider is misconfigured. Your FileProvider metadata needs an <external-path> element, and you do not have one. See the documentation.
I tested the below code.
Add below permission in Menifest
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Below code for installing package
//// TODO: 1/16/18 Check the external storage permission
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/test.apk");
Uri fileUri = Uri.fromFile(file);
if (Build.VERSION.SDK_INT >= 24) {
String packageId = getApplicationContext().getPackageName();
fileUri = FileProvider.getUriForFile(MainActivity.this, packageId + ".files", file);
}
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
intent.setDataAndType(fileUri, "application/vnd.android" + ".package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
Provider in Menifest
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.files"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths" />
</provider>
file_paths.xml
<paths>
<external-path name="external" path="/"/>
Per the Android documentation on EXTRA_NOT_UNKNOWN_SOURCE:
For this to work you must start the installer with startActivityForResult().

camera app crashing at camera.open [duplicate]

This question already has answers here:
How to fix "Fail to connect to camera service" exception in Android emulator
(7 answers)
Closed 1 year ago.
i am developing an android app which has an flash option which is set to auto mode,but it crashes at camera.open.I have used intent to open camera
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
int result = context.checkCallingOrSelfPermission(Manifest.permission.CAMERA);
int result2 = context.checkCallingOrSelfPermission(Manifest.permission.FLASHLIGHT);
if((result==PackageManager.PERMISSION_GRANTED) && (result2==PackageManager.PERMISSION_GRANTED)) {
cam = Camera.open();
Camera.Parameters p = cam.getParameters();
p.setFlashMode(Camera.Parameters.FLASH_MODE_ON);
cam.setParameters(p);
cam.startPreview();
}
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
startActivityForResult(cameraIntent,CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
}});
HERE IS LOGCAT
04-10 15:44:58.928 13248-13248/com.t4u.aapam E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.t4u.aapam, PID: 13248
java.lang.RuntimeException: Fail to connect to camera service
at android.hardware.Camera.<init>(Camera.java:529)
at android.hardware.Camera.open(Camera.java:379)
at com.t4u.aapam.ListViewDisplay$1.onItemClick(ListViewDisplay.java:402)
at android.widget.AdapterView.performItemClick(AdapterView.java:305)
at android.widget.AbsListView.performItemClick(AbsListView.java:1148)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3059)
at android.widget.AbsListView$3.run(AbsListView.java:3866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
here is my manifest file.i have added camera permission and flashlight permisssion.I have also added camera hardware permisssion
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.t4u.aapam">
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="com.telematics4u.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<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_PHONE_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.flash"
android:required="false" />
<application
android:name="com.t4u.aapam.App"
android:allowBackup="true"
android:icon="#drawable/launcher_logo"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
I may be wrong(because I don't see your Manifest.xml file) but there are two solutions I can see
1) The camera cannot be connected to because it is already being used by a different application
You cannot fix that. If the camera is occupied, you can't open it.
2) You haven't requested the Camera-permission.
This can be solved. In your manifest:
<uses-permission android:name="android.permission.CAMERA"/>
And if you are targeting android 6 you have to request the permission at runtime. For that, see this link.
EDIT:
Make sure you add all of these. This will give your app access to the camera and flashlight in software and hardware.
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera.flash"/>
Using these without requiring them makes the app not work if the device (against all odds) doesn't have a camera
you should use all these permissions
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.flash"
android:required="false" />
Maybe this can help but i am not sure
<permission android:name="android.permission.FLASHLIGHT"
android:permissionGroup="android.permission-
group.HARDWARE_CONTROLS"
android:protectionLevel="normal"/>

NullPointerException while trying to create a new intent in WakefulBroadcastReceiver after reboot

I have written a subclass of WakefulBroadcastReceiver that receives the "android.intent.action.BOOT_COMPLETED" action when user device is rebooted.It is working fine in my Nexus device but not on some other devices like Samsung, Verizon etc. For those devices, I am getting a NullPointerException in onReceive() at this line Intent service = new Intent(context, MyAlarmOnBootService.class); as
java.lang.RuntimeException: Unable to start receiver com.android.myapp.receiver.MyWakefulAlarmOnBootReceiver: java.lang.NullPointerException
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2244)
at android.app.ActivityThread.access$1500(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1279)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4854)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.os.Bundle.putAll(Bundle.java:303)
at android.content.Intent.putExtras(Intent.java:5762)
at com.android.myapp.receiver.MyWakefulAlarmOnBootReceiver.onReceive(MyWakefulAlarmOnBootReceiver.java:30)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2237)
... 10 more
This is my receiver class:
public class MyWakefulAlarmOnBootReceiver extends
WakefulBroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Log.d("MyApp", "receiver started after reboot");
Intent service = new Intent(context, MyAlarmOnBootService.class);//this is the line where I am getting NPE.
service.putExtras(intent.getExtras());
startWakefulService(context, service);
}
}
My Manifest file (only the parts related are shown in this file):
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="25" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<receiver android:name=".receiver.MyWakefulAlarmOnBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service
android:name=".service.MyAlarmOnBootService"
android:enabled="true" />
...
Is this related to Smart Manager app of Samsung that kills apps and alarms? If yes, how is my receiver fired? Is there some problem in the context parameter in onReceive()? Please help me. It is working fine on my Nexus 5.
Intent service = new Intent(context, MyAlarmOnBootService.class);//this is the line where I am getting NPE.
actually this is not the line. the exception raised from next line
service.putExtras(intent.getExtras());
you created new intent which has no extras, and you pass it as a parameter to putExtra() this is where you are wrong.

Android permission dialog not displaying

I have found a few other questions about this issue but none of the answers have solved it for me. I'm trying to request the fine location permission, but there is no dialog shown. Here's what I'm doing:
int permissionCheck = ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION);
if(permissionCheck == PackageManager.PERMISSION_GRANTED) {
Log.d("Location","Location permission already granted"); // Not logged
// Do other stuff
}
else {
Log.d("Location", "Requesting location permission"); // This is logged
ActivityCompat.requestPermissions(this,
new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_CODE_ENABLE_LOCATION);
}
No dialog appears, and onRequestPermissionsResult is not called.
This is the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.company.common" android:installLocation="auto">
<!-- Normal permissions -->
<uses-permission android:name="android.permission.ACCESS_GPS" android:required="false"/>
<uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" android:required="false" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="com.android.vending.billing.IN_APP_NOTIFY" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!-- Dangerous permissions -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" android:required="false" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" android:required="false" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-feature
android:name="android.hardware.telephony"
android:required="false" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true" >
</supports-screens>
<application
android:name="com.company.common.App"
android:allowBackup="true"
android:icon="#drawable/icon"
android:label="#string/app_name" >
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
<meta-data android:name="AA_DB_NAME" android:value="propertyforce.db" />
<meta-data android:name="AA_DB_VERSION" android:value="11" />
<meta-data android:name="AA_SERIALIZERS"
android:value="com.company.common.utils.db.JSONObjectSerializer,
com.company.common.utils.db.JSONArraySerializer,
com.company.common.utils.db.AddressSerializer" />
<meta-data
android:name="AA_MODELS"
android:value="com.company.common.utils.db.Model" />
<activity
android:name="com.company.common.Name"
android:configChanges="orientation|keyboardHidden"
android:label="#string/app_label"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activities.AnActivity"/>
<!-- Other activities -->
<service
android:name="com.company.common.utils.services.LogDeleter"
android:icon="#drawable/icon"
android:label="Log Deleter" >
</service>
</application>
</manifest>
Here are some tidbits from the gradle file:
compileSdkVersion 23
buildToolsVersion '21.1.2'
defaultConfig {
minSdkVersion 12
targetSdkVersion 23
}
This is in a FragmentActivity, don't know if that matters. I have uninstalled the app and run it so there should be no permissions already accepted. This is on a Nexus 7 running 6.0.
Why not try this library: https://github.com/tajchert/Nammu. It worked for me.
Nammu.askForPermission(activity, String[] permissions, new PermissionCallback() {
#Override
public void permissionGranted() {}
#Override
public void permissionRefused() {}
});
EDIT
I created a library that encapsulates the whole thing and makes it much more easier. It also shows a customisable explanation dialog before the actual request.
Use this library: https://github.com/ayz4sci/permissionHelper
Usage:
To perform an action that requires Android permission, call permissionHelper.verifyPermission. It accepts the following parameters:
String [] - description of each permission required, this will be displayed to the user in the explanation dialog.
String [] - an array of Manifest permissions
PermissionCallback - you put the actions you want to perform when permission is granted or rejected.
See example below:
permissionHelper.verifyPermission(
new String[]{"dial this number", "take picture"},
new String[]{Manifest.permission.CALL_PHONE, Manifest.permission.CAMERA},
new PermissionCallback() {
#Override
public void permissionGranted() {
//action to perform when permission granteed
}
#Override
public void permissionRefused() {
//action to perform when permission refused
}
}
);

Categories

Resources