Intent.actionview does not work on android 9.0 but works on 5.0 - HELP

thejumpingwolfthejumpingwolf Member ✭✭
edited December 2 in Xamarin.Android

Hi

What i want : To show media by default app
What i provide : the media absolute path
By what: Dependency services

Code:

public void ShowMedia(string path)
{

            Java.IO.File file = new Java.IO.File(path);
            Android.Net.Uri pathToFile = Android.Net.Uri.FromFile(file);
            Intent intent = new Intent(Intent.ActionView,pathToFile);            

            intent.SetDataAndType(pathToFile,"image/jpeg");
            Xamarin.Forms.Forms.Context.StartActivity(intent);


    }

Worked on : Android 5.0
Not worked on : Android 9.0

Tested on : Android 5.0 AND Android 9.0

Can someone help please?

Thanks,
TJW

Best Answer

  • Accepted Answer

    Update:

    Remove this line
    // intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.NewTask);

    and go with this link -
    https:// www.syncfusion.com/forums/144553/android-9-0-api-28-throws-exception-when-viewing-the-pdf-file

    Anyone will be able to go with view. LMK if anyone faces issues.

    Regards,
    TJW

Answers

  • thejumpingwolfthejumpingwolf Member ✭✭
    edited December 2

    Update here :

    Follow this link - https:// www.syncfusion.com/forums/144553/android-9-0-api-28-throws-exception-when-viewing-the-pdf-file

    https:// medium.com/@ali.dev/open-a-file-in-another-app-with-android-fileprovider-for-android-7-42c9abb198c1

    This will work as i guess if the version is after android 24+ / Naugat +

  • LeonLuLeonLu Member, Xamarin Team Xamurai

    Did you solved this issue? If so, please mark your reply as answer, it will help others who have similar issue.

  • thejumpingwolfthejumpingwolf Member ✭✭

    @LeonLu said:
    Did you solved this issue? If so, please mark your reply as answer, it will help others who have similar issue.

    No. I is not working yet!
    Still working on it. There is some issue but the link provides good understanding.
    Surely i will update the solution here and mark as accepted answer.

  • thejumpingwolfthejumpingwolf Member ✭✭
    Accepted Answer

    Update:

    Remove this line
    // intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.NewTask);

    and go with this link -
    https:// www.syncfusion.com/forums/144553/android-9-0-api-28-throws-exception-when-viewing-the-pdf-file

    Anyone will be able to go with view. LMK if anyone faces issues.

    Regards,
    TJW

Sign In or Register to comment.