hello as a newbie in phonegap app building, i am trying to make use of the webintent plugin to open an external app from my app, can i get a sample code example on how this works, thanks
- 98 Posts
- 0 Reply Likes
Posted 6 years ago
John Weidner, Champion
- 435 Posts
- 80 Reply Likes
There are multiple plugins named WebIntent. I'd go with the net.tunts one since it is used by the most number of apps.
In your config.xml you'd need to add the following:
In your index.html you could add:
In your config.xml you'd need to add the following:
<gap:plugin name="net.tunts.webintent" />
In your index.html you could add:
<script>
function testWebIntent() {
address = "1600+Amphitheatre+Parkway%2C+CA" ;
window.plugins.webintent.startActivity({
action: window.plugins.webintent.ACTION_VIEW,
url: 'geo:0,0?q=' + address},
function() {alert('success')},
function() {alert('Failed to open URL via Android Intent')}
);
}
</script>
<button onclick='testWebIntent()'>Test WebIntent</button>John Weidner, Champion
- 435 Posts
- 80 Reply Likes
I did get the WhatsApp app to launch using:
window.plugins.webintent.startActivity({
action: window.plugins.webintent.ACTION_VIEW,
url: 'whatsapp://send?text=Hello%20World!'
},
function() {alert('success')},
function(errorMsg) {alert('Failed to startActivity errorMsg=' + errorMsg)}
);John Weidner, Champion
- 435 Posts
- 80 Reply Likes
If you aren't seeing "Failed to startActivity errorMsg=..." then you must not be running the latest code.
John Weidner, Champion
- 435 Posts
- 80 Reply Likes
The code above specifies the error function as:
function(errorMsg) {alert('Failed to startActivity errorMsg=' + errorMsg)}. So if the output you see doesn't also have the "errorMsg=" text, then you must not have copied, built, or installed the above code. If you use the above, then the errorMsg displayed might give us more clue as to what's wrong.- 98 Posts
- 0 Reply Likes
it has that error mesage
this is the full error message
"failed to start activity errormsg=No Activity found to handle intent{act=android.intent.action.View dat=whatsapp://send?text=Hello WORLD!}
THIS IS what i did that gave me that error message
this is the full error message
"failed to start activity errormsg=No Activity found to handle intent{act=android.intent.action.View dat=whatsapp://send?text=Hello WORLD!}
THIS IS what i did that gave me that error message
<script type="text/javascript">
function app() {
window.plugins.webintent.startActivity({
action: window.plugins.webintent.ACTION_VIEW,
url: 'whatsapp://send?text=Hello%20World!'
},
function() {alert('success')},
function(errorMsg) {alert('Failed to startActivity errorMsg=' + errorMsg)}
);
}
</script>
<button onclick='app()'>whatsapp</button>John Weidner, Champion
- 435 Posts
- 80 Reply Likes
Is the WhatsAp app installed?
- 98 Posts
- 0 Reply Likes
no its not, could that be the reason ? and if that is, is it possible i launch apps from playstore
John Weidner, Champion
- 435 Posts
- 80 Reply Likes
Yes. Android won't know that there is an app that can handle a "whatsapp://" url unless you install that app. If you want to launch the app store instead, you might use a URL like: market://details?id=com.whatsapp according to the documentation at: http://developer.android.com/distribu...
- 98 Posts
- 0 Reply Likes
thank u so much, it works perfectly, i think ill prefer that method, really appreciate
John Weidner, Champion
- 435 Posts
- 80 Reply Likes
You're welcome. I suppose you could combine the two methods. First, try to start the whatsapp app. But if that fails, then start the android market.
- 98 Posts
- 0 Reply Likes
how ? that would be really gud to do, but can u show me how to go abt that
John Weidner, Champion
- 435 Posts
- 80 Reply Likes
Something like:
<script type="text/javascript">
function launchWhatsApp() {
window.plugins.webintent.startActivity({
action: window.plugins.webintent.ACTION_VIEW,
url: 'whatsapp://send?text=Hello%20World!'
},
function() {alert('success')},
function(errorMsg) {
console.log('Failed to startActivity errorMsg=' + errorMsg);
launchMarketForWhatsApp();
}
);
}
function launchMarketForWhatsApp() {
window.plugins.webintent.startActivity({
action: window.plugins.webintent.ACTION_VIEW,
url: 'market://details?id=com.whatsapp'
},
function() {alert('success')},
function(errorMsg) {
console.log('Failed to startActivity errorMsg=' + errorMsg);
}
);
}
</script>
<button onclick='launchWhatsApp()'>whatsapp</button>Petra V., Champion
- 7794 Posts
- 1391 Reply Likes
See your other thread.
[It's not always a great idea to ask the same question simultaneously in multiple threads]
[It's not always a great idea to ask the same question simultaneously in multiple threads]
- 2 Posts
- 0 Reply Likes
hello,
your code is working fine. but i want to open my own app so please help me?
your code is working fine. but i want to open my own app so please help me?
John Weidner, Champion
- 435 Posts
- 80 Reply Likes
Check out this plugin: https://github.com/EddyVerbruggen/Cus.... I think that is what you are looking for.
- 2 Posts
- 0 Reply Likes
Hello,
i try your suggested plugin but its not working properly.
below are the code of my config.xml :
i try your suggested plugin but its not working properly.
below are the code of my config.xml :
<gap:plugin name="nl.x-services.plugins.launchmyapp">
<param name="URL_SCHEME" value="stsprinter" />
</gap:plugin>
<feature name="Custom URL scheme">
<param name="id" value="nl.x-services.plugins.launchmyapp" />
<param name="url" value="https://github.com/EddyVerbruggen/LaunchMyApp-PhoneGap-Plugin.git" />
<variable name="URL_SCHEME" value="stsprinter" /><!-- change as appropriate -->
</feature>
</pre>
and my .html file code is:
<script>
function launchApp() {
window.plugins.webintent.startActivity({
action: window.plugins.webintent.ACTION_VIEW,
url: 'stsprinter://'
},
function() {alert('success1')},
function(errorMsg) {
alert('false')
}
);
}
</script>
Open the other app
can u please guide me for the same.
thanks in advance,
mayur
Related Categories
-
PhoneGap Build
- 15111 Conversations
- 275 Followers
-
Plugins
- 1283 Conversations
- 38 Followers
_large.jpg)




stack stack
i tried this
<input type="button" onclick="javascript:whatsapp();" value="whatsapp">
</div>
<script type="text/javascript" src="phonegap.js"></script>
<script type="text/javascript" src="webintent.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
function whatsapp() {
alert('open');
window.plugins.webintent.startActivity({
action: 'com.whatsapp'},
function() {alert('Started!?');},
function() {alert('Failed to open URL via Android Intent');}
);
}
</script>
and i keep getting "Failed to open URL via Android Intent"
how do i solve this.
John Weidner, Champion
Maybe one of the other WebIntent plugins would work. Or maybe we can get the author of this plugin to update his.
stack stack