1

I've tried to open my app directly, without opening google play store or browser, when user tap on the link.

I've tried this code:

     <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize">

        <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="fptest"
                android:host="forgot"
                android:pathPrefix="/"/>
        </intent-filter>
    </activity>

I'm using link as follows

<a href="intent://TestApplication#Intent;scheme=fptest;package=com.example.testapplication;end">  
   Open App
 </a>

where , 
   TestApplication -- my app name
   package -- com.example.testapplication

But it always open Google Play or a Browser , not my app.

I want to open my app from a link eg : fptest://forgot . I dont want to use http as scheme

Mareena
  • 11
  • 3

3 Answers3

0

You can achieve this by the below code. You don't need to change anything if you are opening your own app. However, if you are willing to open a different app, then just change getPackageName with that specific one.

@SuppressLint("WrongConstant")
    public void OpentheApp()
    {
        Intent localIntent = new Intent("android.intent.action.VIEW", Uri.parse("market://details?id=" + getPackageName()));
        localIntent.addFlags(1208483840);
        try
        {
            startActivity(localIntent);
        }
        catch (Exception localException)
        {
            startActivity(new Intent("android.intent.action.VIEW", Uri.parse("http://play.google.com/store/apps/details?id=" + getPackageName())));
        }
    }

If you want to open it by webview. Then Follow this: Declare these two on the Activity.

String market_url = "market://details?id=package_name";
String website_url = "https://play.google.com/store/apps/details?id=package_name";

Inside OnCreate:

WebView webview = (WebView) findViewById(R.id.webview);
webview.loadUrl("file:///android_asset/index.html");               // path to html
webview.setWebViewClient(new Callback());


    private class Callback extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.equals(website_url)) {
                try {
                    Intent intent = new Intent();
                    intent.setAction(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse(market_url));
                    startActivity(intent);
                } catch (ActivityNotFoundException e) {
                }
            }
            return (false);
        }
    }

index.html

<a href="https://play.google.com/store/apps/details?id=package_name">App link</a>

It will open the app in the play store.

Muntasir Aonik
  • 1,800
  • 1
  • 9
  • 22
  • Hi thank you for your time. I want to open my own application which is installed in my device. Actually , my function is to send a link to mail for resetting password . On click of link, our application should get open (if it is installed). I dont want to open play store. If i'm giving scheme http , then app will open . But i dont want to add http , my url is for eg: fptest://forgot – Mareena Jun 30 '20 at 09:01
0
<data
       android:host="www.yourdomain.com"
       android:pathPrefix="/api/forgot"
       android:scheme="https"
</data>

Then handle the data in onCreate() and onNewIntent(). Your host should be the complete domain of the incoming url. PathPrefix should be the path segments And scheme should could any of http/https/etc

You can use a URL like:- https://www.yourdomain.com/api/forgot/abc.php

0

Add this as your link

<a href="intent://forgot#Intent;scheme=fptest;package=com.example.testapplication;end">  
   Open App
 </a>

Note: I replaced TestApplication with forgot you need to use host after the intent://

AgentP
  • 6,261
  • 2
  • 31
  • 52