Unresolved Class 'FileProvider' in manifest.xml (Android Java) - java

I am building my first Java application. Its functionality includes taking camera images and saving them along with saving 'Project' information locally for said images to be associated with.
I believe I need to include the FileProvider to my code:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="devkit.blade.vuzix.com.blade_template_app"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_path"></meta-data>
</provider>
In the above XML .FileProvider is not resolving and so I cant build the app. What's the problem here?
Also for context #xml/provider_path references this file:
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path name="/storage/emulated/0" path="."/>
</paths>

I believe I need to include the FileProvider to my code
In your <provider> element in your manifest, try changing android.support.v4.content.FileProvider (the fully-qualified class name to an old edition of FileProvider) to androidx.core.content.FileProvider.

Adding this to my build.grade (app module) allowed it to be referenced correctly. If you are required to use API level 27 (pre androidX) this is the way!
implementation 'com.android.support:support-core-utils:27.0.0'

Related

How to set file provider for images stored in app data folder

I have been working on CameraX API and storing captured image on Internal storage App data folder with path say storage/emulated/0/Android/data/packageName/Files/IMG_25052021_171806.jpg
Now i want to get content URI for this saved image. For this i have been using provider in Manifest.
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.abc.xyz.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/filepath" />
</provider>
with File path as
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="my_images" path="/" />
When i am calling FileProvider.getUriForFile(ImageCrop.this,"com.abc.xyz.fileprovider", pictureFile); it returning me Illegal Argument Exception
Please suggest !!!
You seem to be using getExternalFilesDir() for the filesystem location. If so, use <external-files-path>, not <files-path>, in your metadata XML resource. See the documentation for more.

Android: Using a File Provider on ExternalStorage

I'm having really hard time trying to open downloaded apk
I'm trying to use FileProvider (https://developer.android.com/reference/android/support/v4/content/FileProvider), I've followed this steps but I think I'm doing something wrong. I change this code in different ways many times, but unsuccessful.
Here's what I have:
File downloaded in:
app.setPathUpdate(Environment.getExternalStorageDirectory() +
File.separator + "trovata/update/" +
this.getApplicationInfo().packageName + File.separator)
The code above make this outcome: /storage/emulated/0/trovata/update/br.com.trovata.milano.elite/
Here's what I'm doing:
SincronizacaoActivity.java
File FileAppInst = new File(app.getPathUpdate() + "atualizador");
Uri apkUri = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID+".provider", FileAppInst);
Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
intent.setData(apkUri);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
AndroidManifest.xml
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/filepaths" />
</provider>
filepaths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="atualizador" path="/trovata/update/${applicationId}/"/>
</paths>
Error:
...
Caused by: java.lang.IllegalArgumentException: Failed to find configured
root that contains /storage/emulated/0/trovata/update/br.com.trovata.milano.elite/atualizador
...
Could you help me?
path="/trovata/update/${applicationId}/"
${applicationId} only turns into your application ID in AndroidManifest.xml. You cannot use manifest placeholders in resource files. So, replace ${applicationId} with your actual application ID.
In all the encounters with FileProvider it occurs that in most of the cases it only worked when the path was set to path=".".
Replace your filepaths.xml with this
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="atualizador" path="."/>
</paths>
And give it a try.

Share content using ShareCompat

I have a strange problem when I try to share a my_file.html using ShareCompat.
As best practice I have created my own FileProvider but I get the error java.lang.IllegalArgumentException: Failed to find configured root that contains /forms/Proof_of_Life_Form.html I think I have set up all of the stuff correctly.
My XML I have created a provider for that.
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.douglas.sample"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/filepaths" />
</provider>
This is my filepaths created in res/xml/filepaths
<?xml version="1.0" encoding="utf-8"?>
<paths>
<cache-path path="/forms" name="forms" />
</paths>
and also my method that is responsible to call share content.
public void shareContent() {
File file = new File("/forms/", fileName + ".html");
Uri uri = FileProvider.getUriForFile(getContext(), "com.douglas.sample", file);
Intent shareIntent = ShareCompat.IntentBuilder.from(getActivity())
.setType(getActivity().getContentResolver().getType(uri))
.setStream(uri)
.getIntent();
//Provide read access
shareIntent.setData(uri);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, getString(R.string.share_form)));
}
Finally my exception:
java.lang.IllegalArgumentException: Failed to find configured root that contains /forms/Proof_of_Life_Form.html
at android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:719)
at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:404)
at com.douglas.sample.TabbedFormsFragment$2.run(TabbedFormsFragment.java:254)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Any Idea? thanks :D
It seems there are some little mistakes in your code.
Try the following:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.FileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_paths"/>
</provider>
and then in your provider_paths.xml try:
<?xml version="1.0" encoding="utf-8"?>
<paths>
<!-- We would like to give access to the External Storage of the app.
external_files will expose the path app to storage/emulated/0/ and the
"." is to actually point the root folder. The final path of the Uri will start
from path above and whatever folder we defined. For application upgrades
will be external_files/Android/data/package name/files/updates/name of update apk.-->
<external-path
name="external_files"
path="."/>
</paths>
and then whereever you want to use it try:
String path = Uri.parse(your_file_uri).getPath();
FileProvider.getUriForFile(application, PROVIDER, new File(path)),my_file_type);
where my_file_type = e.g. "application/vnd.android.package-archive" for .apk file
Hope it helps!!!

Resources referenced from the manifest cannot vary by configuration

When I want to insert the follow meta-tag:
<meta-data
android:name="com.android.systemui.action_assist_icon"
android:resource="#mipmap/ic_launcher" />
I get the error message:
Resources referenced from the manifest cannot vary by configuration
(except for version qualifiers, e.g. -v21.) Found variation in hdpi,
mdpi, xhdpi, xxhdpi, xxxhdpi
How can I fix this?
Variation of resources in AndroidManifest.xml is detected as error.
It may be ignored like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest ...
xmlns:tools="http://schemas.android.com/tools"
...>
...
<meta-data
android:name="com.android.systemui.action_assist_icon"
android:resource="#mipmap/ic_launcher"
tools:ignore="ManifestResource" />
...
</manifest>
see:
Android : Facebook app id showing error in values-ta/strings.xml and can't able to generate signed apk
I moved such strings to globalstrings.xml and removed the references from the locale files.

AndroidManifest.xml not working properly

we are sooooo close to finishing our game, it is ready to be published through google play but we are having problems making any of the game services work.
we have a simple achievement button that should call the achievement UI, same goes for logging in. but we do not get any prompts when we are running it on our android device.
we have
PlayGamesPlatform.Activate();
in our start function
Social.localUser.Authenticate((bool success) => {
// handle success or failure
});
connected to a log in button
and
Social.ShowAchievementsUI();
on our show achievement button.
our email is connected as a tester on google play and the game service API's are all enabled
my real question is about the AndroidManifest that the game play service for unity created.
this is it:
<?xml version="1.0" encoding="utf-8"?>
<!-- This file was automatically generated by the Google Play Games plugin for Unity
Do not edit. -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.example.games.mainlibproj"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" />
<application>
<!-- Required for Nearby Connections API -->
<meta-data android:name="com.google.android.gms.nearby.connection.SERVICE_ID"
android:value="" />
<!-- the space in these forces it to be interpreted as a string vs. int -->
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="\ 606268116612" />
<meta-data android:name="com.google.android.gms.appstate.APP_ID"
android:value="\ 606268116612" />
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity android:name="com.google.games.bridge.NativeBridgeActivity"
android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
</application>
</manifest>
i have read online that the package name should be our package name but shouldnt this be created when we run android set up using our ID number for our game? should i physically change this in code in the manifest even though it says i shouldnt edit it?
also OUR.ID i have replaced just for this question and in the real manifest has our actual ID No
Many Thanks In Advance
I always have the same package name (at application level) than my hierarchy in the project. In my opinion is a good practice to set the root at the folder where you have all your activities.
On the other hand, you can sign your app for market with the ID you want setting it in your gradle file.
You can see a good reference here.
I hope this would help you.

Categories