Device.OpenURI not working on Android 9?

psyonpsyon USMember ✭✭

I had a user complain that a button wasn't working in my app. All the button does is calls Device.OpenURI() to open a website in the system browser. I loaded up my app in an Android 9 emulator, and sure enough, it doesn't open anything. I tried searching the forums and didn't see anything. Has anyone else had a problem with this?

Posts

  • JohnHardmanJohnHardman GBUniversity mod

    @psyon

    I've just tested using Android 9 on a physical Motorola One, with a XF app using XF 3.4.0.1008975.
    Device.OpenUri(uri); worked fine, using a URI in the form "https://www.mywebsite.com".
    (I cannot test in an emulator right now - I'm in the midst of updating emulators)

    If a user with a physical device is hitting a problem, is it possible that the user has denied necessary permissions in Settings?

  • psyonpsyon USMember ✭✭

    Yeah, the user has a physical device, and I can't get it to work in the Android 9 emulator no matter what URL I put in it.

    The motorola one ships with 8.1, and is updatable to 9. Did you do the update, or is it possible you are still on 8.1? Just want to rule it out.

  • JohnHardmanJohnHardman GBUniversity mod

    @psyon said:
    Yeah, the user has a physical device, and I can't get it to work in the Android 9 emulator no matter what URL I put in it.

    The motorola one ships with 8.1, and is updatable to 9. Did you do the update, or is it possible you are still on 8.1? Just want to rule it out.

    Definitely on 9. Being able to upgrade to 9 was the reason I bought the Motorola One :-)

  • JohnHardmanJohnHardman GBUniversity mod

    @psyon said:
    Yeah, the user has a physical device, and I can't get it to work in the Android 9 emulator no matter what URL I put in it.

    The motorola one ships with 8.1, and is updatable to 9. Did you do the update, or is it possible you are still on 8.1? Just want to rule it out.

    Is your URL https or http?
    If it's http, see https://stackoverflow.com/questions/51902629/how-to-allow-all-network-connection-types-http-and-https-in-android-9-pie

  • psyonpsyon USMember ✭✭

    I tried http and https to rule it out as a problem. Tried https://www.google.com as a test, and it won't work. Sucks that Device.OpenUri() returns void, so can't check for errors :(

  • JohnHardmanJohnHardman GBUniversity mod
    edited February 10

    @psyon said:
    I tried http and https to rule it out as a problem. Tried https://www.google.com as a test, and it won't work. Sucks that Device.OpenUri() returns void, so can't check for errors :(

    Do you catch exceptions thrown by OpenUri() ?

    I have just been testing using an emulator for an Android TV. OpenUri() threw an exception containing
    "No Activity found to handle Intent { act=android.intent.action.VIEW dat=https://www.mywebsite.com/... flg=0x10000000 }"
    which is presumably because there is no browser installed as part of that emulator's image. Just wondered if you might be encountering the same when using emulators

    I'll fire up an Android 9 emulator when I get some time, although probably not today.

  • psyonpsyon USMember ✭✭

    No exception is being thrown, and Chrome is install on the emulator image, and the user's device.

  • JohnHardmanJohnHardman GBUniversity mod
    edited February 11

    @psyon

    I fired up an Android 9 emulator and checked OpenUri(). It worked without problem for a URI in the form "https://www.mywebsite.com" in an app built using XF 3.4.0.1008975

    A couple of thoughts:
    (1) is your app in the foreground when calling OpenUri() ?
    (2) are you calling OpenUri() from the UI thread ?
    (From your original post, I assume the answer to both of those is yes)

  • psyonpsyon USMember ✭✭

    Just... just kill me now. So this has all been working for the last few years with no issue. Initially, the Android 9 user was having an issue related to permissions, which I fixed, but he told me the only problem he was having was that the button that opens the browser was not working. I had put up a special alpha release for him to try, that was using previously unreleased code. In the unreleased code, I had changed some things so I could build two separate versions of the app more easily. Somehow, in my changes, I deleted the line that binds the button CommandProperty to the command that opens the browser. The button isn't a very big part of the app, so I must not have tested it, nor any of my dozen other beta testers. So, sorry for having a problem that wasn't really a problem and due more to my over worked self being stupid.

  • JohnHardmanJohnHardman GBUniversity mod
    edited February 11

    @psyon - With my devops hat on, I've been in charge of build/release processes for various teams in the past, to avoid just such things happening. Few independent app developers follow such strict processes though, so these sorts of things will happen from time to time. Xamarin.UITest may help prevent similar things happening again, although I personally am loathe to spend more time on using it until it supports UWP (come on Microsoft - surely the CodedUI team can help make that happen)

  • psyonpsyon USMember ✭✭

    The app is for a citizen science project I run, for which I am the sole developer (and general IT person) for everything we do. That is on top of the work I actually do to pay the bills. My process is definitely not very strict. I tend to focus more on the security of the website, and mission critical parts of things, and slack a bit on some other aspects. With my most recent code changes, the structure of data we store in the app is changing, so 99% of my testing has just been making sure the app doesn't delete or otherwise corrupt any pending data that hasn't been sent to our servers yet when the person gets an update. Any other bugs that pop up, our users would understand that I have to put out another bug fix, but lost data can't be recovered. The worse part is, my son is working on an app for someone, and recently asked me if he was creating buttons right, because they weren't showing up. And I asked him "Are you sure the code that creates them is even being called?" Sure enough, he forgot to negate a conditional so it wasn't. I should learn to ask myself the same questions I ask him.

Sign In or Register to comment.