Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch android application from a browser link

I have a problem trying to launch my application from the browser using my own scheme.
Code is as follow:
Manifest file:

   <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" 
        android:exported="false">
        <intent-filter>

            <data  android:scheme="allplayer" />

            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

Html file:

<html>
<head>
</head>
<body>
<a href="allplayer://site.com">Test link</a>
</body>
</html>

If I click on the link, my application wont start. I did a lot of researches, but couldn't find an answer.
If I change allplayer with http everything works fine.
From this link, I learnt that it is not recommended to use your own schemes.
Does that mean your own schemes wont work?
The person here is using his own scheme, and from his feedback it seems that it is working.
Am I missing something?

like image 972
Lazy Ninja Avatar asked Oct 24 '12 02:10

Lazy Ninja


People also ask

Can I open Android app from URL?

First of all you need to add intent filters for incoming links. Specify the ACTION_VIEW intent action so that the intent filter can be reached from Google Search. Add one or more tags, each of which represents a URI format that resolves to the activity. At minimum, the tag must include the android:scheme attribute.


1 Answers

It took me 6 hours to figure out the problem. Somehow setting the exported to false caused all the problem: android:exported="false". When I set it to true, it worked like a charm.

Funny because I put it there in the first place to avoid the Exported activity does not require permission warning. Setting it back to true, brought back the warning, but it is working now.

Solution is below. Hope it will help others save time.

<activity
      android:name=".MainActivity"
      android:label="@string/title_activity_main" 
      android:exported="true">
      <intent-filter>
          <data  android:scheme="allplayer" />
          <action android:name="android.intent.action.VIEW" />
          <category android:name="android.intent.category.BROWSABLE" />
          <category android:name="android.intent.category.DEFAULT" />
      </intent-filter>
  </activity>
like image 97
Lazy Ninja Avatar answered Oct 15 '22 14:10

Lazy Ninja