Open android app from link - android

I know about the universal linking but that's not the thing I want to do. With universal links, I have to define some url schema and when I try to open it in the browser (click on a link that points to that url) it will ask me if I want to open the application. Please correct me if that's not true.. I want to open the application just via app-name:{data goes here} or just simply app-name: (app-name is a name that I want to define somewhere). Not sure how this linking is called? Now I can open the app but via different name and not sure where it is defined. Tried to change the package name because I thought it's autogenerated from there but without success. The application is written in Cordova and maybe there are some limitations, I don't know. But it would be nice if I knew this kind of linking name! Of course, if you can provide some more information on how this can be achieved with Cordova - awesome!

If you want to open one app from another app just use this
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.package.anotherapp");
if (launchIntent != null) {
startActivity(launchIntent);//null pointer check in case package name was not found
}
If you want open from some web url u need this ,its called "deep linking"
read this https://developer.android.com/training/app-links/deep-linking
<intent-filter>
<action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>
<data
android:host="www.my.app.com"
android:path="launch"
android:scheme="http"></data>
</intent-filter>
With the email link set as http://www.my.app.com/launch.
If u need to open your app page from webView in your app u just can create new WebViewClient extended from WebViewClient and handle your url there

I use this plugin (https://github.com/EddyVerbruggen/Custom-URL-scheme) for open my apps with something like that :
<a href="myapps://" />
OR
<a href="myapps://forgotpassw" />
I hope that can help you

Related

can i Broadcast custom intent through my HTML page link from browser?

I want to broadcast my custom intent when i click a link of my html page from browser. I know android system will broadcast "android.intent.action.VIEW" for this and i can receive this in my application but doing this will list my application for every clickable link so i want to broadcast my custom intent action.
I want to broadcast my custom intent when i click a link of my html
page from browser.
You can do that in two ways, the exact choice depend on your use case.
Create an <intent-filter> to open selected links (links of your website)
Change your link on the website to <a href="intent://...>
The first method gives you flexibility to leave the links on your website as it is and it will also helps in deeplinking and AppIndex. Where as the second method will make you change all the links in the website.
I know android system will broadcast "android.intent.action.VIEW" for
this and i can receive this in my application but doing this will list
my application for every clickable link so i want to broadcast my
custom intent action.
It will not list your application for every clickable link on the web, it will only open your app for your website links. If you don't want to do that and only open app for one specific link of your website, you should use method 2 above.
Just a note for the second mehtod
Make sure to implement a fallback url, as suggested by Google
When an intent could not be resolved, or an external application could
not be launched, then the user will be redirected to the fallback URL
if it was given.
The link should look like this
<a href="intent://scan/#Intent;scheme=zxing;package=com.google.zxing.client.android;S.browser_fallback_url=http%3A%2F%2Fzxing.org;end">
Notice the S.browser_fallback_url for fallback
I have solved this by following
create test.html file with this single line
Open Your Application Directly
Here "example.com/test?id=12345" can be any thing you want this will be passed as intent data in our in our onCreate() method so i have given id for example.
"scheme" can be any string we need to write same scheme in our menifest.xml for intent-filter
"package" is your app package name to differentiate it from other app with same scheme
Note : If app is not installed in device then it will open google playstore from given valid package name
in AndroidMenifest.xml file
<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="myapp" />
</intent-filter>
you can add intent filter for any activity i have given to launcher activity
note the <data android:scheme="myapp" /> scheme name must be same as given in HTML file before.
Done! open html file in any browser of your device & click on link it will directly open your app.
You can get intent data in your activity's onCreate() method like
Intent intent = getIntent();
if (intent != null && intent.getData() != null) {
Uri data = intent.getData();
String path = data.getPath();
String id = data.getQueryParameter("id");
Log.d("ID", ": " + id);
}

cordova webintent plugin isnt working

I actually want to capture the weblink which can trigger my app to launch.
I am using the code as given below. [written in AndroidManifest.xml].
<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="mysite.com"
android:pathPrefix="/_mobile/"
android:scheme="http"
/>
</intent-filter>
Launching of an app is a success when I try to visit "mysite.com/_mobile". Basically, the aforementioned link is actually a link to the mobile version of my main website. Now, if a user has the app installed, it should open the app rather than the mobile web page. So far, it works great. Now the problem is when I want to navigate to a specific page in an app. for example, "mysite.com/_mobile?productId=103" - this would open a page for productId=103 in mobile web view. But, incase the user has my app installed, how can I redirect him to this productId page in an app.
I did some googling on this topic and stumbled upon a cordova plugin. I added this plugin, so called "Initsogar/cordova-webintent" here. Now, I am using this code,
window.plugins.webintent.getUri(function(url) {
if(url !== "") {
alert("URL was "+url);
}
});
All I want is to get the uri which launched the app. I do not get the desired outcome. I tried to alert some value to check if this code is working or not, it seems its NOT.
see the code that i used for testing:
window.plugins.webintent.getUri(function(url) {
alert(2);
if(url !== "") {
alert("URL was "+url);
}
});
Here, 2 is not alerted. I dont know whats wrong with this plugin. other than this, I have no clue where to start from. any help would be great. :)

Mail link open my app on specific URL

I'm actually using Crosswalk.
I have some hard restrictions about speaking about my project so i'll try to be as clear as possible.
When I open my app manually, Webview load the home index.html of the website.
But this website is used for WebRTC so, it send an invitation via an e-mail with specific URL.
Is that possible to open my own application with URL that I just clicked ?
I checked for some <intent-filter> but I have no clue how to deal with the URL opening.
Hope someone have some solutions or clues.
EDIT:
<intent-filter>
<data android:scheme="https" android:host="xxx.xxx.com"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
With that I can open my application when I click on a link, but I still need to get the link url and set it as url loaded in my XWalkView.
Example:
https://xxx.xxx.com/join?xertfgf=1
When I click on that, my app open good, but know i want my XWalkView to load this.
Help :c
Problem solved:
After setting <intent-filter> correclty, if you use Crosswalk ( it will work with classic or Cordova Webview ) just :
Intent intent = getIntent();
String link = intent.getDataString();
xWalkWebView.clearCache(true);
if(link!=null){
xWalkWebView.load(link, null);
} else {
xWalkWebView.load("file:///android_asset/index.html", null);
}

Custom URI in Android devices and iOS devices

I had a problem with Custom URI.
Custom URI : scheme:\music\album\tamil\albumID
When I mail this as text it appears as link in iOS devices as link but not in Android devices.
When user select/click the Cutom URI it should navigate to my app and have to show the appropriate content.
This custom URI is passed from one website's button click. In iOS device its react as link not in Android devices.
The web end passing the Custom URI as below
href="scheme://music/tamil/album/albumID"
As a Android developer what should I do to resolve this ?.
Or from web end how to pass the Custom URI as link?.
I think your mail provider/client is responsible for this behaviour. Gmail for example removes custom URIs and replaces href links from <a> tags. This may be for security reasons, not sure why. I suggest you to use "http" as scheme. Then Android will prompt you to open with browser or your app. Add intent filter as below example.
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
You may also add a android:host, and android:path or android:pathPrefix if needed.
Another option is to use a redirect 302. An example for php is below. The drawback is this will open the browser at first.
<a href="openmyapp.php?cat=music&albumID=9128">
<?php
header("Location: scheme://". $_SERVER['QUERY_STRING']);
exit;
?>

Launch android app when a link is tapped on SMS

I don't know if many people have tried this but I am trying a build an app that requires user to tap on a link on the sms he/she receives and this will launch the android app. Is it possible to do in android? If yes, how can I do this? I know this can be done in IOS. Any suggestions or help will be appreciated. Thank You.
In you Manifest, under an Activity that you want to handle incoming data from a link clicked in the messaging app, define something like this:
<activity android:name=".SomeActivityName" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<data android:scheme="com.your_package.something" />
</intent-filter>
</activity>
The android:scheme="" here is what will ensure that the Activity will react to any data with this in it:
<data android:scheme="com.your_package.something" />
In the SomeActivityName (Name used as an illustration. Naturally, you will use your own :-)), you can run a check like this:
Uri data = getIntent().getData();
String strData = data.toString();
if (strScreenName.equals("com.your_package.something://")) {
// THIS IS OPTIONAL IN CASE YOU NEED TO VERIFY. THE ACTUAL USAGE IN MY APP IS BELOW THIS BLOCK
}
My app's similar usage:
Uri data = getIntent().getData();
strScreenName = data.toString()
.replaceAll("com.some_thing.profile://", "")
.replaceAll("#", "");
I use this to handle clicks on twitter #username links within my app. I need to strip out the com.some_thing.profile:// and the # to get the username for further processing. The Manifest code, is the exact same (with just the name and scheme changed).
Add an intent-filter to your app that listens for links that follow the format you want your app to be launched on.
However, this will be a global listener, and any link that fits the format even outside the SMS app will trigger your app. So if the user taps a similar link in the web browser, your app will attempt to respond to it.
Additionally, if there is another app besides yours that can handle this link, Android will create a chooser that allows the user to pick whichever app they want to use. There is nothing you can do about this, except suggest that the user make your app the default handler for such links.
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE"
<data android:scheme="https" android:host="${hostName}" android:pathPattern="/.*" />
</intent-filter>
Previous answers are OK but don't forget to specify the pattern.
See more details here.
Also define your hostname inside Gradle file like:
android {
defaultConfig {
manifestPlaceholders = [hostName:"subdomain.example.com"]
}
}
More info about manifestPlaceholders here.

Categories

Resources