Calling the Camera Apps (Permission Denial: starting Intent ) - android

My fragment is trying to start Camera Activity, but it seems like there is some camera permission problem,
while debugging it goes till below line of code only
startActivityForResult(callCameraApplicationIntent, CAMERA_PIC_REQUEST);
Below is the logcat result
java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE flg=0x3 cmp=android/com.android.internal.app.ResolverActivity clip={text/uri-list U:content://com.example.tc.provider/external_files/Pictures/photo_saving_app/IMAGE_20191205_070208.jpg} (has extras) } from ProcessRecord{8920903 18662:com.example.tc/u0a343} (pid=18662, uid=10343) with revoked permission android.permission.CAMERA
at android.os.Parcel.readException(Parcel.java:2016)
at android.os.Parcel.readException(Parcel.java:1962)
at android.app.IActivityManager$Stub$Proxy.startActivity(IActivityManager.java:4452)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1617)
at android.app.Activity.startActivityForResult(Activity.java:4551)
at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:767)
Following is the part of code That seems required.
if (Build.VERSION.SDK_INT > 21) { //use this if Lollipop_Mr1 (API 22) or above
Intent callCameraApplicationIntent = new Intent();
callCameraApplicationIntent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
// We give some instruction to the intent to save the image
File photoFile = null;
try {
// If the createImageFile will be successful, the photo file will have the address of the file
photoFile = createImageFile();
// Here we call the function that will try to catch the exception made by the throw function
} catch (IOException e) {
Logger.getAnonymousLogger().info("Exception error in generating the file");
e.printStackTrace();
}
// Here we add an extra file to the intent to put the address on to. For this purpose we use the FileProvider, declared in the AndroidManifest.
Uri outputUri = FileProvider.getUriForFile(
getActivity(),
BuildConfig.APPLICATION_ID + ".provider",
photoFile);
callCameraApplicationIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputUri);
// The following is a new line with a trying attempt
callCameraApplicationIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
Logger.getAnonymousLogger().info("Calling the camera App by intent");
// The following strings calls the camera app and wait for his file in return.
startActivityForResult(callCameraApplicationIntent, CAMERA_PIC_REQUEST);
Manifest file is below
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tc">
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-feature
android:name="android.hardware.camera.any"
android:required="true" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" />
<!--
Allows Glide to monitor connectivity status and restart failed requests if users go from a
a disconnected to a connected network state.
-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".LoginActivity"
android:label="Login"
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=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
</activity>
<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>
</manifest>
It was working fine previously. I might have done some silly mistake as I am just a learner with help of internet only.

As per the ACTION_IMAGE_CAPTURE documentation:
Note: if you app targets M and above and declares as using the Manifest.permission.CAMERA permission which is not granted, then attempting to use this action will result in a SecurityException.
You do not need the camera permission to use ACTION_IMAGE_CAPTURE on any API level. Therefore, if you are only using ACTION_IMAGE_CAPTURE, you can remove the line <uses-permission android:name="android.permission.CAMERA" />.
If you are using the Camera APIs in addition to using ACTION_IMAGE_CAPTURE, you must request the permission at runtime.

Related

How to solve Permission Denial: reading com.android.providers.downloads.DownloadStorageProvider

I'm using react-native-document-picker to get file from android device and upload them. I was able to pick a file and upload normally but only from folder inside My File. If I pick a file in others directory, for example, Recent (the one display first when open the Document picker) the app would stop immidiately and display error:
Permission Denial: reading com.android.providers.downloads.DownloadStorageProvider uri content://com.android.providers.downloads.documents/document/msf:3239 from pid=19089, uid=10372 requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs
despite it is the same file storaged in My File.
I used react-native-image-crop-picker and was able to pick image in any directory.
Below is the code of my manifest file and document picker function:
---------------AndroidManifest----------------
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:name=".MainApplication"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:roundIcon="#mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="#style/AppTheme">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyCeZH6swcDYvYWT78RhSAQYbE1m_Gt2VXs"/>
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
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="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
---------------DocumentPickerFunction----------------
let arrFile: FileUploadParam[] = [];
let pickFile = async () => {
DocumentPicker.pick({
type: [DocumentPicker.types.allFiles],
}).then((file: any) => {
arrFile.push(
fileStorageService.createFileUploadParam(file.name, file.uri, false),
);
fileStorageService.uploadChatAttachs(arrFile).subscribe((result) => {
let urlArr: MessageAttach[] = [];
result.map((item: any) => {
urlArr.push({
name: item.name,
storage_filename: item.storage_filename,
url: item.url,
type: AttachType.FILE,
});
});
chatService
.sendAttachFileMessage('', urlArr, roomId)
.subscribe((message) => {});
console.log('Upload data', urlArr);
});
});
};

How do I get permissions only in AndroidManifest.xml file for installed apps in android device?

I'm developing an android application that can do permission-based searches. I have a code that takes and parses AndroidManifest.xml files in apk files.
This code parses the xml file and outputs an result like this:
android.permission.WRITE_EXTERNAL_STORAGE
android.permission.READ_CONTACTS
android.permission.WRITE_CONTACTS
android.permission.ACCESS_NETWORK_STATE
android.permission.INTERNET
I have a model called PInfo. This model has an ArrayList named permissions. When you get permissions with "PackageInfo" on Android, it gives the following results.
android.permission.WRITE_EXTERNAL_STORAGE
android.permission.READ_CONTACTS
android.permission.WRITE_CONTACTS
android.permission.ACCESS_NETWORK_STATE
android.permission.INTERNET
android.permission.WAKE_LOCK
com.google.android.finsky.permission.BIND_GET_INSTALL_REFERRER_SERVICE
com.google.android.c2dm.permission.RECEIVE
android.permission.READ_EXTERNAL_STORAGE
AndroidManifest.xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.omfaer.minion">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name="com.omfaer.minion.activities.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.omfaer.minion.activities.HomeActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".activities.WallpapersActivity"/>
<provider
android:exported="false"
android:grantUriPermissions="true"
android:authorities="${applicationId}.provider"
android:name="android.support.v4.content.FileProvider">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_path"
/>
</provider>
</application>
</manifest>
PackageInfo code:
List<PackageInfo> packs = context.getPackageManager().getInstalledPackages(context.getPackageManager().GET_PERMISSIONS);
for (int i = 0; i < packs.size(); i++) {
PackageInfo p = packs.get(i);
PInfo deviceApps = new PInfo();
deviceApps.appName = p.applicationInfo.loadLabel(context.getPackageManager()).toString();
deviceApps.appPackage = p.packageName;
deviceApps.appIconId = p.applicationInfo.icon;
StringBuilder strBuilderPermissions = new StringBuilder();
try {
if (p.requestedPermissions != null) {
for (String perms : p.requestedPermissions) {
deviceApps.permissions.add(perms);
}
}
} catch (Exception e) {
//Log.v("PUCA for add permissions ", e.toString());
}
}
I want to get this result also on the Android side.
android.permission.WRITE_EXTERNAL_STORAGE
android.permission.READ_CONTACTS
android.permission.WRITE_CONTACTS
android.permission.ACCESS_NETWORK_STATE
android.permission.INTERNET
This should provide accurate results for thousands of applications. How can I do?
According to official docs:
Your APK file can contain just one AndroidManifest.xml file, but your
Android Studio project may contain several—provided by the main source
set, build variants, and imported libraries. So when building your
app, the Gradle build merges all manifest files into a single manifest
file that's packaged into your APK.
The manifest file you attached is your manifest but when android compiling your project it will merge other manifests into your manifest. for example if you implement a library its manifest will merge into yours in apk file. for finding manifest file of your apk try to decompile it (here) and read that file.

Permission Denial Issue even after adding the required permission in manifest file

Here is the Error Log:
Permission Denial: starting Intent { act=android.settings.WIFI_DISPLAY_SETTINGS cmp=com.android.settings/.Settings$WifiDisplaySettingsActivity } requires com.android.setting.permission.ALLSHARE_CAST_SERVICE
at android.os.Parcel.readException(Parcel.java:1472)
at android.os.Parcel.readException(Parcel.java:1426)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2329)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1426)
at android.app.Activity.startActivityForResult(Activity.java:3513)
at android.app.Activity.startActivityForResult(Activity.java:3474)
at android.app.Activity.startActivity(Activity.java:3716)
at android.app.Activity.startActivity(Activity.java:3684)
Manifest file with Permission:
<uses-sdk android:minSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.setting.permission.ALLSHARE_CAST_SERVICE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:exported="true" >
</activity>
<activity
android:name=".SplashScreenActivity1"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
if your app is having target API level 23 make sure user grants the permission before using them. See RunTimePermission
I hope you are testing this application on samsung device because this permission is only worked on samsung device. As per my knowledge such permission is not exists in the android permission list.
Below is the permission list from android.
http://developer.android.com/reference/android/Manifest.permission.html
Hope this will help you.

Is it possible to write to the sd card without a file picker on kitkat+

I want to delete files from the SD card root without a file picker.
After searching around for a couple of days,i haven't found a way to do this.But files apps ES file explorer have no problem,does anyone know why that is?
The closest thing i found would be this
How to use the new SD-Card access API presented for Lollipop? but i have to use a file picker
Manifest
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>
<uses-permission android:name="ANDROID.PERMISSION.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="ANDROID.PERMISSION.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.GET_PACKAGE_SIZE"/>
<uses-permission android:name="android.permission.CLEAR_APP_CACHE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
You must provide us some source code and tell what you tried.
Check if you can create new empty files:
File newFile = new File("/storage/sdcard1/test");
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Edit after comment:
Add this in your manifest above application tag.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

java.lang.SecurityException: Permission Denial: starting Intent

I am a newbie to Android application development... When i try to run my application i am getting a security exception as Permission Denial... though i am able to open my application i am unable to proceed to any of the process... Application doesn't access the web service... Plz help me out...
The following is the exception message I receive,
[2012-01-11 11:02:09 - eCalc] ActivityManager: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.anb.eCalculator/.LoginActivity } from null (pid=-1, uid=-1) requires android.permission.INTERNET
enter code here
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.anb.eCalculator"
android:installLocation="internalOnly"
android:versionName="1.2.1" android:versionCode="10">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application android:label="#string/app_name"
android:theme="#android:style/Theme"
android:permission="android.permission.INTERNET"
android:icon="#drawable/ecalcicon" android:allowClearUserData="true">
<activity android:name=".LoginActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".CalculationActivity"></activity>
<activity android:name="ResultActivity"></activity>
<activity android:name=".InformationActivity"></activity>
<activity android:name=".RegisterActivity"></activity>
<activity android:name=".SettingsActivity"></activity>
<activity android:name=".ResultDetailsActivity"></activity>
<activity android:name=".Disclaimer"></activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk android:targetSdkVersion="5"
android:minSdkVersion="5"
android:maxSdkVersion="12">
</uses-sdk>
<uses-permission android:name="android.permission.INTERNET" />
Add this above line in your manifest file after your <uses-sdk> line.
Add this permission to your manifest file.
<uses-permission android:name="android.permission.INTERNET" />
I fixed it .
Click on "Run" and "Edit configuration". Select the activity you want to launch.

Categories

Resources