0

I'm trying to get an old app of mine working again... When trying to capture an picture, with this code:

public void photoIntent() {
 Log.d("MainActivity", "photoIntent");
 Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
 File photo = null;
 try {
 File outputDir = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES); // context being the Activity pointer
 photo = new File(outputDir+"picture.jpg");
 // place where to store camera taken picture
 //photo.delete();
 } catch (Exception e) {
 Log.d("MainActivity", "Can't create file to take picture!");
 }
 **Uri mImageUri = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID+".fileprovider, photo);**
 intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
 // start camera intent
 this.startActivityForResult(intent, 1);
 }

I'm having this error, on line "mImageUri = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID, photo);":

java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference
 at android.support.v4.content.FileProvider.parsePathStrategy(FileProvider.java:583)
 at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:557)
 at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:399)
 at com.marzinp.mycelium.MainActivity.photoIntent(MainActivity.java:96)
 at com.marzinp.mycelium.MainActivity1ドル.onClick(MainActivity.java:69)
 at android.view.View.performClick(View.java:7892)
 at android.widget.TextView.performClick(TextView.java:16220)
 at android.view.View.performClickInternal(View.java:7869)
 at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
 at android.view.View$PerformClick.run(View.java:30891)
 at android.os.Handler.handleCallback(Handler.java:942)
 at android.os.Handler.dispatchMessage(Handler.java:99)
 at android.os.Looper.loopOnce(Looper.java:226)
 at android.os.Looper.loop(Looper.java:313)
 at android.app.ActivityThread.main(ActivityThread.java:8762)
 at java.lang.reflect.Method.invoke(Native Method)
 at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)

Here is my manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.marzinp.mycelium"
 android:versionCode="112"
 android:versionName="1.1.2" >
 <uses-sdk
 android:minSdkVersion="22"
 android:targetSdkVersion="33" />
 <uses-permission android:name="android.permission.CAMERA" />
 <uses-feature android:name="android.hardware.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.INTERNET"/>
 <application
 android:allowBackup="true"
 android:icon="@drawable/lombric"
 android:label="@string/app_name"
 android:theme="@style/AppTheme" >
 <provider
 android:name="android.support.v4.content.FileProvider"
 android:authorities="com.marzinp.mycelium.provider"
 android:exported="false"
 android:grantUriPermissions="true">
 <meta-data
 android:name="android.support.FILE_PROVIDER_PATHS"
 android:resource="@xml/provider_paths"/>
 </provider>
 <activity
 android:name="com.marzinp.mycelium.MainActivity"
 android:configChanges="orientation|screenSize" 
 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>
</manifest>

and my res.xml provider_path file:

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
 <external-path
 name="external_files"
 path="Pictures" />
</paths>

I've tried many solutions, from many web pages, to no result...

Thanks for your help, I'm a noob, returning to android after 10 years!

asked Oct 18, 2024 at 9:15
2
  • 1
    Did you try changing android:name of provider tag in AndroidManifest.xml from android.support.v4.content.FileProvider to androidx.core.content.FileProvider? Commented Oct 18, 2024 at 9:27
  • Thanks. I wasn't using androidx, but I will do that and tell you. Commented Oct 18, 2024 at 10:52

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.