How to view an image with default gallery in Android 8.0?
I wanted to view my recently downloaded image with my default gallery app in my Android 8.0 [Oreo].
I have been using intent for that, but it shows notification as "Media not found".
After doing bit search on it, I found that, for "Android N and above" we need to use "FileProvider" but I did not found good explanatory post for that, so please help me on it.....
Please help me by either using intent or file provider:
My code is as follows:
String root = Environment.getExternalStorageDirectory().toString();
public void onClick(DialogInterface dialog, int id)
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(root + "/h_jokes_images/"+fname+".jpg"), "image/mime");
startActivity(intent);
java android-intent android-contentprovider android-gallery android-fileprovider
add a comment |
I wanted to view my recently downloaded image with my default gallery app in my Android 8.0 [Oreo].
I have been using intent for that, but it shows notification as "Media not found".
After doing bit search on it, I found that, for "Android N and above" we need to use "FileProvider" but I did not found good explanatory post for that, so please help me on it.....
Please help me by either using intent or file provider:
My code is as follows:
String root = Environment.getExternalStorageDirectory().toString();
public void onClick(DialogInterface dialog, int id)
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(root + "/h_jokes_images/"+fname+".jpg"), "image/mime");
startActivity(intent);
java android-intent android-contentprovider android-gallery android-fileprovider
refer the documentation, developer.android.com/reference/android/support/v4/content/…
– Karan Mer
Nov 14 '18 at 7:27
1
stackoverflow.com/a/49828751/5102423 check this out ,this should answer your question
– Zaid Zakir
Nov 14 '18 at 7:57
Thanks @KaranMer
– prasad_21
Nov 14 '18 at 8:57
Thanks @ZaidZakir
– prasad_21
Nov 14 '18 at 8:57
add a comment |
I wanted to view my recently downloaded image with my default gallery app in my Android 8.0 [Oreo].
I have been using intent for that, but it shows notification as "Media not found".
After doing bit search on it, I found that, for "Android N and above" we need to use "FileProvider" but I did not found good explanatory post for that, so please help me on it.....
Please help me by either using intent or file provider:
My code is as follows:
String root = Environment.getExternalStorageDirectory().toString();
public void onClick(DialogInterface dialog, int id)
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(root + "/h_jokes_images/"+fname+".jpg"), "image/mime");
startActivity(intent);
java android-intent android-contentprovider android-gallery android-fileprovider
I wanted to view my recently downloaded image with my default gallery app in my Android 8.0 [Oreo].
I have been using intent for that, but it shows notification as "Media not found".
After doing bit search on it, I found that, for "Android N and above" we need to use "FileProvider" but I did not found good explanatory post for that, so please help me on it.....
Please help me by either using intent or file provider:
My code is as follows:
String root = Environment.getExternalStorageDirectory().toString();
public void onClick(DialogInterface dialog, int id)
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(root + "/h_jokes_images/"+fname+".jpg"), "image/mime");
startActivity(intent);
java android-intent android-contentprovider android-gallery android-fileprovider
java android-intent android-contentprovider android-gallery android-fileprovider
edited Nov 17 '18 at 6:01
prasad_21
asked Nov 14 '18 at 7:10
prasad_21prasad_21
217
217
refer the documentation, developer.android.com/reference/android/support/v4/content/…
– Karan Mer
Nov 14 '18 at 7:27
1
stackoverflow.com/a/49828751/5102423 check this out ,this should answer your question
– Zaid Zakir
Nov 14 '18 at 7:57
Thanks @KaranMer
– prasad_21
Nov 14 '18 at 8:57
Thanks @ZaidZakir
– prasad_21
Nov 14 '18 at 8:57
add a comment |
refer the documentation, developer.android.com/reference/android/support/v4/content/…
– Karan Mer
Nov 14 '18 at 7:27
1
stackoverflow.com/a/49828751/5102423 check this out ,this should answer your question
– Zaid Zakir
Nov 14 '18 at 7:57
Thanks @KaranMer
– prasad_21
Nov 14 '18 at 8:57
Thanks @ZaidZakir
– prasad_21
Nov 14 '18 at 8:57
refer the documentation, developer.android.com/reference/android/support/v4/content/…
– Karan Mer
Nov 14 '18 at 7:27
refer the documentation, developer.android.com/reference/android/support/v4/content/…
– Karan Mer
Nov 14 '18 at 7:27
1
1
stackoverflow.com/a/49828751/5102423 check this out ,this should answer your question
– Zaid Zakir
Nov 14 '18 at 7:57
stackoverflow.com/a/49828751/5102423 check this out ,this should answer your question
– Zaid Zakir
Nov 14 '18 at 7:57
Thanks @KaranMer
– prasad_21
Nov 14 '18 at 8:57
Thanks @KaranMer
– prasad_21
Nov 14 '18 at 8:57
Thanks @ZaidZakir
– prasad_21
Nov 14 '18 at 8:57
Thanks @ZaidZakir
– prasad_21
Nov 14 '18 at 8:57
add a comment |
1 Answer
1
active
oldest
votes
if your app targets Android N (7.0) and above, you must use a ContentProvider.
Intent intent = new Intent(Intent.ACTION_VIEW)//
.setDataAndType(VERSION.SDK_INT >= VERSION_CODES.N ?
android.support.v4.content.FileProvider.getUriForFile(this,getPackageName() + ".provider", file) : Uri.fromFile(file),
"image/*").addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
manifest:
<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/provider_paths"/>
</provider>
res/xml/provider_paths.xml :
<?xml version="1.0" encoding="utf-8"?>
<paths>
<!--<external-path name="external_files" path="."/>-->
<external-path
name="files_root"
path="Android/data/$applicationId"/>
<external-path
name="external_storage_root"
path="."/>
</paths>
Thanks @Sultan Mahmud
– prasad_21
Nov 14 '18 at 8:58
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53294817%2fhow-to-view-an-image-with-default-gallery-in-android-8-0%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
if your app targets Android N (7.0) and above, you must use a ContentProvider.
Intent intent = new Intent(Intent.ACTION_VIEW)//
.setDataAndType(VERSION.SDK_INT >= VERSION_CODES.N ?
android.support.v4.content.FileProvider.getUriForFile(this,getPackageName() + ".provider", file) : Uri.fromFile(file),
"image/*").addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
manifest:
<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/provider_paths"/>
</provider>
res/xml/provider_paths.xml :
<?xml version="1.0" encoding="utf-8"?>
<paths>
<!--<external-path name="external_files" path="."/>-->
<external-path
name="files_root"
path="Android/data/$applicationId"/>
<external-path
name="external_storage_root"
path="."/>
</paths>
Thanks @Sultan Mahmud
– prasad_21
Nov 14 '18 at 8:58
add a comment |
if your app targets Android N (7.0) and above, you must use a ContentProvider.
Intent intent = new Intent(Intent.ACTION_VIEW)//
.setDataAndType(VERSION.SDK_INT >= VERSION_CODES.N ?
android.support.v4.content.FileProvider.getUriForFile(this,getPackageName() + ".provider", file) : Uri.fromFile(file),
"image/*").addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
manifest:
<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/provider_paths"/>
</provider>
res/xml/provider_paths.xml :
<?xml version="1.0" encoding="utf-8"?>
<paths>
<!--<external-path name="external_files" path="."/>-->
<external-path
name="files_root"
path="Android/data/$applicationId"/>
<external-path
name="external_storage_root"
path="."/>
</paths>
Thanks @Sultan Mahmud
– prasad_21
Nov 14 '18 at 8:58
add a comment |
if your app targets Android N (7.0) and above, you must use a ContentProvider.
Intent intent = new Intent(Intent.ACTION_VIEW)//
.setDataAndType(VERSION.SDK_INT >= VERSION_CODES.N ?
android.support.v4.content.FileProvider.getUriForFile(this,getPackageName() + ".provider", file) : Uri.fromFile(file),
"image/*").addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
manifest:
<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/provider_paths"/>
</provider>
res/xml/provider_paths.xml :
<?xml version="1.0" encoding="utf-8"?>
<paths>
<!--<external-path name="external_files" path="."/>-->
<external-path
name="files_root"
path="Android/data/$applicationId"/>
<external-path
name="external_storage_root"
path="."/>
</paths>
if your app targets Android N (7.0) and above, you must use a ContentProvider.
Intent intent = new Intent(Intent.ACTION_VIEW)//
.setDataAndType(VERSION.SDK_INT >= VERSION_CODES.N ?
android.support.v4.content.FileProvider.getUriForFile(this,getPackageName() + ".provider", file) : Uri.fromFile(file),
"image/*").addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
manifest:
<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/provider_paths"/>
</provider>
res/xml/provider_paths.xml :
<?xml version="1.0" encoding="utf-8"?>
<paths>
<!--<external-path name="external_files" path="."/>-->
<external-path
name="files_root"
path="Android/data/$applicationId"/>
<external-path
name="external_storage_root"
path="."/>
</paths>
edited Nov 14 '18 at 7:35
answered Nov 14 '18 at 7:28
Sultan MahmudSultan Mahmud
23017
23017
Thanks @Sultan Mahmud
– prasad_21
Nov 14 '18 at 8:58
add a comment |
Thanks @Sultan Mahmud
– prasad_21
Nov 14 '18 at 8:58
Thanks @Sultan Mahmud
– prasad_21
Nov 14 '18 at 8:58
Thanks @Sultan Mahmud
– prasad_21
Nov 14 '18 at 8:58
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53294817%2fhow-to-view-an-image-with-default-gallery-in-android-8-0%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
refer the documentation, developer.android.com/reference/android/support/v4/content/…
– Karan Mer
Nov 14 '18 at 7:27
1
stackoverflow.com/a/49828751/5102423 check this out ,this should answer your question
– Zaid Zakir
Nov 14 '18 at 7:57
Thanks @KaranMer
– prasad_21
Nov 14 '18 at 8:57
Thanks @ZaidZakir
– prasad_21
Nov 14 '18 at 8:57