TedPark Developer
Published in

TedPark Developer

[Android]Start Activity by Custom URL Scheme

If you want start activity, you write code like this.

And If you want launch url page, you will pass Uri with Intent.ACTION_VIEW.

If you use many browser in your phone, android will show select browser view for url load.
This select view is not only url also any other duplication action.

How you can see this select view?

Because that applications use same custom scheme (like ‘http://', ‘xxx://’)

Let’s see example.
This is notification view about user’s action.
(Look like facebook or instagram’s notification view)

If you click item of list, we will move to activity.
Post’s row id is 10 and Activity name is ‘Activity_Post_Detail’.
Then you can write code like this.
Make new intent instance and pass String extra.

But If you use ‘Custom URL’, you can write code like this.
(Look like load url page)

This way don’t need Activity name. (need only url path)
Furthermore you can launch activity at your browser

Custom URL Scheme

1. Declare host / scheme at your activity (AndroidManifest.xml)

In this example, schme is selphone and host is post_detail

(Custom url will selphone://post_detail)

Now If you load ‘selphone://post_detail?…’ url, this activity will launch.

2. If you want to pass parameter to Activity, pass by query string

If you want pass post_id ( id: 10), you can add query string end of url.
“selphone://post_detail?post_id=10”

3. In your Activity, get your parameter at query string

Check intent action, and get query parameter from intent data.

Do it your self custom url activity for your application
If you want to know more detail infomation, check this page Android Intent Fileters

--

--

https://github.com/ParkSangGwon/Introduce

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store