Posts

Showing posts from April, 2021

Rectifying FileUriExposedException

If we use the code Uri imageuri = Uri.fromFile(new java.io.File(_path)); It will cause FileUriExposedException if the file:// Uri is exposed to another app. You cannot use uri.fromFile(File) in new versions of android because it causes file uri exposed exception. You have to use File provider. If you are using Sketchware : 1. First Add Camera Component. 2. Then use following code: Uri imageUri = FileProvider.getUriForFile(MainActivity.this, getApplicationContext().getPackageName() + ".provider", new java.io.File(_path)); If you are using android studio 1. Put following code in AndroidManifest.xml: <provider android:name="androidx.core.content.FileProvider" android:authorities="com.xxxx.xxxx.provider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths"/> </provider> Replace com.xxxx.xxxx in c