Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android how is a Chrome intent-based URI opened

From the Chrome docs, I understand apps can be opened with the following URI

intent:  
   HOST/URI-path // Optional host  
   #Intent;  
      package=\[string\];  
      action=\[string\];  
      category=\[string\];  
      component=\[string\];  
      scheme=\[string\];  
   end;

I was wondering if I could open this URI from my app.

Example URI

intent:
    //qr/json/%7B%22u%22%3A%22https%3A%2F%2Fprivacybydesign.foundation%2Fbackend%2Firma%2Fsession%2FvsRjkZF2B2H17sBWmVZe%22%2C%22irmaqr%22%3A%22disclosing%22%7D
    #Intent;
        package=org.irmacard.cardemu;
        scheme=cardemu;
        l.timestamp=1620907855707;
        S.browser_fallback_url=https%3A%2F%2Fplay.google.com%2Fstore%2Fapps%2Fdetails%3Fid%3Dorg.irmacard.cardemu
    ;end

Since it look like a normal URI I thought I could open it like this:

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("%EXAMPLE_URI%"));
startActivity(intent);

That gives me an ActivityNotFoundException. What am I missing?

Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=intent://qr/json/{"u":"https://privacybydesign.foundation/backend/irma/session/vsRjkZF2B2H17sBWmVZe","irmaqr":"disclosing"} pkg=org.irmacard.cardemu (has extras) }

like image 536
Robin Dijkhof Avatar asked Nov 06 '22 01:11

Robin Dijkhof


1 Answers

The "intent:" syntax described in the Chrome docs is used to launch apps from a web page, Chrome will handle the href and retrieve the params to launch apps via the Android Intent.

The scheme of the example URI you provided is intent://, it is not handled by default.

if you want to handle the intent:// URI, you need to create a deep link

If you want to open a web page from your Android app, you can use the ACTION_VIEW action and specify the web URL in the intent data.

public void openWebPage(String url) {
    Uri webpage = Uri.parse(url);
    Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }
}

// example
// openWebPage("https://privacybydesign.foundation/backend/irma/session/vsRjkZF2B2H17sBWmVZe")

more info about Intents and Intent Filters

like image 185
iamwent Avatar answered Nov 11 '22 10:11

iamwent