How to open specific activity on clicking on link? - android

I am working on an android app in that i have added sharing whatsapp sharing feature,I have done it successfully,Now i want to open a specific activity of my android application when user click on link i have shared.I have searched few links but no luck,I hope somebuddy will help me in this.
Added manifest
<activity
android:name=".ProductDescriptionActivity"
android:exported="true"
android:screenOrientation="portrait"
android:theme="#style/Theme.AppCompat.NoActionBar">
<intent-filter>
<action android:name="com.abc.allaboutcity.MESSAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http"
android:host="http://allaboutcity.in"
android:pathPrefix="/allaboutcity" />
</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" />
<!-- Accepts URIs that begin with "example://gizmosā€ -->
<data android:scheme="allaboutcity"
android:host="allaboutcity" />
</intent-filter>
</activity>

You should add intent filter in your manifest file to activity that you want to open
<activity
android:name="Your Activity"
android:label="Your Activity Title"
android:theme="Your Style">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="your url"
android:path="/your path"
android:scheme="http" />
</intent-filter>
</activity>

use this code In Your WebView Activity
Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
Webview webView = (WebView) findViewById(R.id.webview_id);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(""+ data);
next, use this code in AndroidManifest.xml, its for all link (Https / Http):
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https"/>
<data android:scheme="http"
android:host="http://allaboutcity.in"
android:pathPrefix="/allaboutcity" />
<data android:host="www.host.com" android:pathPattern="/movie/0.*/" android:scheme="http"/>
</intent-filter>

Related

I am creating a Browser App but Android won't detect my app in chooser while I click on any URL

I am creating a Browser app and I want Android to treat my app as a browser and show up in the app chooser to open with.
I want my app to show up in this list.
Here is my manifest Activity code:
<activity
android:name=".Activity.LinkDetectorActivity"
android:exported="true"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data android:scheme="testscheme" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Replace your intent-filter with below,
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http"/>
<category android:name="android.intent.category.DEFAULT" />
<!-- The BROWSABLE category is required to get links from web
pages. -->
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
Try to change testcheme to "http" and "https"
<activity
android:name=".Activity.LinkDetectorActivity"
android:exported="true"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data android:scheme="http" />
<data android:scheme="https" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

Deep Linking not working

activity
android:name=".activity.rechargetab.RechargeActivity">
<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="mobileleb"
android:host="recharge/checkout/status" />
</intent-filter>
</activity>
When I try mobileleb://recharge/checkout/status from the browser it searches google.Its not working. It does not start RechargeActivity.
add android:autoVerify="true" to intent-filter and specify scheme="http" or "https" or both
<activity
android:name=".activity.rechargetab.RechargeActivity">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="mobileleb" />
<data android:pathPattern ="/recharge/checkout/status" />
</intent-filter>
</activity>

Control multiple activity intents in android

I am trying to open my app depending on the url that is entered but in some cases it tries to execute several activities at the same time, is there any way to restrict this so that the MainAction does not execute when trying to execute another?, basically my manifest goes like this
Main Activity
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="www.test.com" />
<data android:host="m.test.com" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="home"
android:scheme="testapp" />
</intent-filter>
</activity>
Detail Activity
<activity
android:name=".DetailActivity"
android:label="#string/title_activity_detail"
android:launchMode="singleInstance"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="detail"
android:scheme="testapp" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="www.test.com" />
<data android:host="m.test.com" />
<data android:pathPrefix="/homes"/>
</intent-filter>
</activity>
the problem is that when i try to open a link like "http://www.test.com/homes" this happens:
Your DetailActivity should be declared as shown below, no intent filter is needed.
<activity
android:name=".DetailActivity"
android:label="#string/title_activity_detail"
android:theme="#style/AppTheme.NoActionBar">
</activity>
The thing that matters is the launchMode for the MainActivity
You should read that : https://developer.android.com/guide/topics/manifest/activity-element.html#lmode

Applinks intents not working on android

I have an Android app that should open links on the app which clicks from the web browser.
I have the following intent filters:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:autoVerify="true">
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" android:host="www.mysite.com" />
<data android:scheme="https" android:host="www.mysite.com" />
</intent-filter>
And also i checked the my signed sha256 key, package name etc from the assetjson file which is in the mysite/.well-known/assetlinks.json. Everythings looks correct. But the app still not opening when i click the links from the website.
<activity android:name=".YourActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" />
<data android:scheme="http" />
<data android:host="mysite.com" />
</intent-filter>
</activity>

How to open an android app via intent filter?

I am trying to open a file with my app and to receive a file via the SEND intent.
I've tried several filters in the manifest file but could not get it to be displayed anywhere.
How is this done?
<activity
android:name=".MyActivity"
android:label="#string/app_name">
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</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="file" />
<data android:mimeType="*" />
<data android:host="*" />
</intent-filter>
</activity>

Categories

Resources