Make a link in the Android browser start up my app?

前端 未结 9 1135
小鲜肉
小鲜肉 2020-11-21 22:06

Is it possible to make a link such as:

click me!

cause my Anton app to start

相关标签:
9条回答
  • 2020-11-21 22:44

    I also faced this issue and see many absurd pages. I've learned that to make your app browsable, change the order of the XML elements, this this:

    <activity
        android:name="com.example.MianActivityName"
        android:label="@string/title_activity_launcher">
    
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    
        <intent-filter>                
            <data android:scheme="http" />     
            <!-- or you can use deep linking like  -->               
    
            <data android:scheme="http" android:host="xyz.abc.com"/>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.BROWSABLE"/>
            <category android:name="android.intent.category.DEFAULT"/>
    
        </intent-filter>
    </activity>
    

    This worked for me and might help you.

    0 讨论(0)
  • 2020-11-21 22:48

    I think you'll want to look at the <intent-filter> element of your Mainfest file. Specifically, take a look at the documentation for the <data> sub-element.

    Basically, what you'll need to do is define your own scheme. Something along the lines of:

    <intent-filter>
        <data android:scheme="anton" />
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" /> <--Not positive if this one is needed
        ...
    </intent-filter>
    

    Then you should be able to launch your app with links that begin with the anton: URI scheme.

    0 讨论(0)
  • 2020-11-21 22:48

    I apologize for promoting myself, but I have a jQuery plugin to launch native apps from web links https://github.com/eusonlito/jquery.applink

    You can use it easy:

    <script>
    $('a[data-applink]').applink();
    </script>
    
    <a href="https://facebook.com/me" data-applink="fb://profile">My Facebook Profile</a>
    
    0 讨论(0)
  • 2020-11-21 22:48

    This method doesn't call the disambiguation dialog asking you to open either your app or a browser.

    If you register the following in your Manifest

    <manifest package="com.myApp" .. >
      <application ...>
        <activity ...>
          <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:host="gallery"
              android:scheme="myApp" />
          </intent-filter>
        </activity>
        ..
    

    and click this url from an email on your phone for example

    <a href="intent://gallery?directLink=true#Intent;scheme=myApp;package=com.myApp;end"> 
      Click me 
    </a>
    

    then android will try to find an app with the package com.myApp that responds to your gallery intent and has a myApp scheme. In case it can't, it will take you to the store, looking for com.myApp, which should be your app.

    0 讨论(0)
  • 2020-11-21 22:49

    Here's my recipe:

    Create a static HTML that redirects to your requested app URL, put that page on the web.

    That way, the links you share are 'real' links as far as Android is concerned ( they will be 'clickable').

    You 'share' a regular HTTP link, www.your.server.com/foo/bar.html This URL returns a simple 8 line HTML that redirects to your app's URI (window.location = "blah://kuku") (note that 'blah' doesn't have to be HTTP or HTTPS any more).

    Once you get this up and running, you can augment the HTML with all the fancy capabilities as suggested above.

    This works with the built-in browser, Opera, and Firefox (haven't tested any other browser). Firefox asks 'This link needs to be opened with an application' (ok, cancel). Other browsers apparently don't worry about security that much, they just open the app, no questions asked.

    0 讨论(0)
  • 2020-11-21 22:57

    You may want to consider a library to handle the deep link to your app:

    https://github.com/airbnb/DeepLinkDispatch

    You can add the intent filter on an annotated Activity like people suggested above. It will handle the routing and parsing of parameters for all of your deep links. For example, your MainActivity might have something like this:

    @DeepLink("somePath/{useful_info_for_anton_app}")
    public class MainActivity extends Activity {
       ...
    }
    

    It can also handle query parameters as well.

    0 讨论(0)
提交回复
热议问题