All that I see says that you need to add the <provider> section to AndroidManifest, and you need to access the XML resource file, which indicates the external path to the file you want for the image.
I do none of them, but the code fragment that I found works even on Nougat and newer.
I wonder why. I can't figure out what really makes it work.
Here is my Android manifest:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.inthecheesefactory.lab.intent_fileprovider"> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" 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> </manifest>
And here is the full MainActivity. I would like to trim it a bit for you, but I want to make sure that I don't accidentally cut something that you guys need to see. I can not understand.
public class MainActivity extends AppCompatActivity implements View.OnClickListener { private static final int REQUEST_TAKE_PHOTO = 1; Button btnTakePhoto; ImageView ivPreview; String mCurrentPhotoPath; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initInstances(); } private void initInstances() { btnTakePhoto = (Button) findViewById(R.id.btnTakePhoto); ivPreview = (ImageView) findViewById(R.id.ivPreview); btnTakePhoto.setOnClickListener(this); }
source share