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. :)
Related
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
At first please do not mar this question as duplicate. All other questions are old and I've tried solutions from most of them and none of them work.
I'm working on an Android app and I'd added my app to share Android menu. I'd like to add functionality so if user clicks my app on the share list e.g. in Chrome browser or Google Drive app, my app will receive the data from that app e.g. from Chrome it wold be URL.
I've tried to use different plugins and read many posts about how to use intent in my app. Unfortunately none of them work.
I've tried:
Sending url to ionic android app via webintents from another app - this one looked very promising
https://www.npmjs.com/package/phonegap-webintent
https://github.com/napolitano/cordova-plugin-intent - this one looked promising as well
https://github.com/okwei2000/webintent
https://github.com/stample/cordova-sharingreceptor
Did anyone got this working?
My AndroidManifest.xml is as follows - the part about intent:
<intent-filter android:label="#string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
In my config.xml I have:
<preference name="AndroidLaunchMode" value="singleTask" />
And I'm not getting data I'm expecting.
When I'm using https://github.com/napolitano/cordova-plugin-intent plugin I'm getting the intent but clipItems element is missing and the plugin is useless.
What am I doing wrong?
Any help appreciated.
Finally I've done it.
I used https://github.com/napolitano/cordova-plugin-intent ver 0.1.3 and
window.plugins.intent.setNewIntentHandler(function (intent) {
// To get browser URL I had to use
var subject = intent.extras['android.intent.extra.SUBJECT'];
var url = intent.extras['android.intent.extra.TEXT'];
// For Chrome, Opera and FireFox it works. For build in Android browser TEXT holds page title and URL joined with +
});
Although ver 0.1.3 has
window.plugins.intent.getRealPathFromContentUrl(contentUrl, function (realPath) {}, function () {});
available I couldn't use it because this didn't give me the data I wanted. contentUrl is different for differen browsers e.g. for Chrome it is uri and for build in Android browser it's text.
I installed ver 0.1.3 using CLI
phonegap plugin add https://github.com/napolitano/cordova-plugin-intent.git#61a47ae8c28a62004eeff4ed96a6f3c64c271a16
I couldn't add it using tag in config.xml
I hope this will help others.
I am a developer of a basic e-commerce app which has a companion website. I wanted to try app links as a way to direct my users from my website to certain screens on my mobile app.
The applinks website tutorial gives the following example as a way to introduce app links to a certain app.
This is possible if I wanted to "link" to just one screen in each app. But what do I have to do if I want to link to multiple screens?
I want the website to be able to direct the user to the home screen, the search screen as well as the payment screen. Is there an efficient way to do this? Do I have to add different app links on different pages?
EDIT
Thanks for the response Alex. I've tried to follow your guide for my Android app but it doesn't seem to work. Whenever I open the URL of my website on the Android Chrome browser nothing happens. I want an automatic redirect to my app.
This is a snippet of my code (under pseudonyms for the names and urls).
Website:
<meta property="al:android:url" content="ecommerceapp://dlogsman" />
<meta property="al:android:app_name" content="ECommerceApp" />
<meta property="al:android:package" content="com.ecommerce.app" />
<meta property="al:web:url" content="http://ecommerce.com/~dlogsman" />
Android Manifest:
<activity
android:name="com.ecommerce.app.App"
android:label="#string/app_name_ecommerce">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<data android:scheme="ecommerceapp" android:host="open" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
And then my onStart method handles the intent exactly like you recommended. Any suggestions?? Thanks again for the time.
As a heads up, I work on the Branch linking tool (branch.io) which helps simplify deep linking across all channels including Facebook (and simplifying the AppLinks nightmare)
What App Links do is simply tell the Facebook robot how to map a corresponding website URL to your native app URL. It's just a set of metatags to add to your site's header in order to tell Facebook which app URL to call when the app is installed. The only actual link is your website link. Therefore, you can only have 1 set of AppLinks on a given page on your existing ecommerce site. In order to use AppLinks to different pages in your app, you'll need to actually have different web URLs. So, you'll need to have a:
http://yourecommercesite.com/home and add metatags for yourecommerceapp://home
http://yourecommercesite.com/search and add metatags for yourecommerceapp://search
http://yourecommercesite.com/payment and add metatags for yourecommerceapp://payment
Then, you'll need to structure your app for deep linking. In case you haven't done that, here's how to set it up and receive the URL path in iOS:
Add the URI scheme for yourecommerceapp:// to the PLIST file
Write the code to receive the URI path
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
if ([[url path] hasSuffix:#"home"]) {
// load the home view controller
} else if ([[url path] hasSuffix:#"search"]) {
// load the search view controller
} else if ([[url path] hasSuffix:#"payment"]) {
// load the payment view controller
}
return YES;
}
And here's how in Android:
Setup the app Manifest to receive intents from yourecommercesite://. You just need to add this inside the <activity></activity> tags
<intent-filter>
<data android:scheme="yourecommercesite"/>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
In onStart of the Activity that receives the intent, add the following code:
#Override
protected void onStart() {
super.onStart();
if (this.getIntent().getData() != null) {
if (this.getIntent().getData().getPath().equals("home")) {
// load the home activity
} else if (this.getIntent().getData().getPath().equals("search")) {
// load the search activity
} else if (this.getIntent().getData().getPath().equals("payment")) {
// load the payment activity
}
}
}
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);
}
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.