How to Implement My Very Own Uri Scheme on Android

How to implement my very own URI scheme on Android

This is very possible; you define the URI scheme in your AndroidManifest.xml, using the <data> element. You setup an intent filter with the <data> element filled out, and you'll be able to create your own scheme. (More on intent filters and intent resolution here.)

Here's a short example:

<activity android:name=".MyUriActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myapp" android:host="path" />
</intent-filter>
</activity>

As per how implicit intents work, you need to define at least one action and one category as well; here I picked VIEW as the action (though it could be anything), and made sure to add the DEFAULT category (as this is required for all implicit intents). Also notice how I added the category BROWSABLE - this is not necessary, but it will allow your URIs to be openable from the browser (a nifty feature).

Android how to create Custom URL scheme with the given format myapp://http://

As CommonsWare said the given URI upon I needed to create a Scheme is not a valid URI thus the scheme didn't not work and the application didn't launch. After this explanation the server side guys were convinced to change the URI to myapp://... and it worked like magic :).

The Activity looks like this now :

 <activity
android:name="com.myapp.test.SplashScreen"
android:exported="true"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<!-- Test for URL scheme -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myapp" />
</intent-filter>
<!-- End Test for URL scheme -->
</activity>

android custom url scheme..?

I think the problem is with the Action you defined.
There is a "android.intent.action.VIEW" which is what I think you want.

<activity android:name=".Gallery1" android:label="@string/app_name" android:launchMode="singleTask" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="cedemo" android:host="com.cedemo.scan" />

</intent-filter>
</activity>

Try that and I bet will resolve correctly. I only made this assumption because you included the browsable category which is usually used by the Browser, which does not know of any of your custom actions. If you do want the GALLERY action as you have implied then just create 2 filters

<activity android:name=".Gallery1" android:label="@string/app_name" android:launchMode="singleTask" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.GALLERY" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="cedemo" android:host="com.cedemo.scan" />

</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="cedemo" android:host="com.cedemo.scan" />

</intent-filter>
</activity>

So within the contents of your activity you can do something like:

// Value should be "toto" as in your example
String value = getData().getQueryParameter("X");

Android custom URI scheme incorrectly encoded when type in browser

Why does it have to be a custom uri?

I'd try it with a standard URL and then I'd define a broadcast receiver for it.

That's essentially how http://youtube.com or http://maps.google.com work I think. Just try typing those two URLs in your Android browser of your Galaxy Ace.

How to use intents for Android custom URL schema?

  1. You didn't call super.onCreate(b);
  2. Url myapp://foo doesn't match your IntentFilter. It should be myapp://path/ or you can change the IntentFilter and remove host part.

    <data android:scheme="myapp"/>

Open Android App with custom URL from PDF file

The Adobe Reader app seems to block unknown URLs since everything works fine with other PDF reader apps such as the built in PDF Viewer in Dropbox.

Android Custom URL Scheme Refuses To Work / How to Navigate Back to Android App After OAuth

After something like 64 hours of scouring the internet and countless attempts I have finally found a solution to this issue. Yay me! I must admit I feel a bit of shame as to how long this issue took to resolve.

The Issue: Could not find a way to navigate back to android app after salesforce authorization (custom url scheme was extremely painful with android).

Solution: After searching around I found a code example from salesforce that did what I was attempting to do here:

https://developer.salesforce.com/page/Developing_Mobile_Applications_with_Force.com_and_Appcelerator_Titanium

Here is the github link provided in the above article that has the much needed code:

https://github.com/appcelerator-developer-relations/Force

TLDR: The real key here was to NOT use a custom url scheme with android and titanium. Instead the github code listed above opens the auth page in a web view and then, using listeners, closes that webview after auth is done and opens whatever view you need.

Explanation: to navigate back to my app on IOS all I had to do was add a couple of lines to my tiapp.xml file in order to use a custom url scheme. It worked very quickly and simply without any headache. Naturally I assumed a custom url scheme was the way to go with android, simple right? false. I spent many hours as listed above trying to make a custom url scheme on android to no avail. There seems to be lots of info online about android custom url schemes but none of them worked for me and believe me I tried so many things (after all it was approx. 64 hours). Eventually I just tried to find an example online of code that did what I wanted. This was the one that I found.



Related Topics



Leave a reply



Submit