从离子应用程序调用本机Android应用程序 [英] Call a native android app from ionic app
问题描述
我正在开发一款将由Android原生应用调用的应用。我也要打电话给他们。为此,我找到了这个插件。
I’m developing an app that will be called by an android native app. I also have to call them. For doing this I found this plugin.
他们会根据以下代码致电我的应用程序(并希望我打电话给他们):
They will call my app (and expect me to call theirs) following this code:
String packageName = "com.android.app";
Intent intent = getPackageManager().getLaunchIntentForPackage(packageName);
if (intent == null) {
// The app is not installed
intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=" + packageName));
}
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("param", "aaaaa");
startActivity(intent);
如果插件在他们执行此操作时打开我的应用程序(并且他们的应用程序也将打开)。
I don’t get if the plugin will work to open my app when they do this (and their app will open also).
我寻找一种在离子中使用意图的方法,但我一无所获。
I look for a way of using intends in ionic but I found nothing.
谢谢!
推荐答案
也许它可以帮助别人我如何解决它。
Maybe it will help someone how I resolved it.
要打开另一个Android应用程序,我使用 com.lampa.startapp 。这样做的代码是:
To open another android app I use the com.lampa.startapp. The code for doing it it's:
var sApp = startApp.set({
"package": "packageName" //The packageName of the app I want to open
}, {
//extras I want to add
"myParams" : "aaaaa"
});
sApp.start();
要使用意图(打开我的应用程序的意图),我使用 cordova-plugin-intent ,代码如下:
To work with intents (the ones that open my app) I use the cordova-plugin-intent with the following code:
//To get the intent and extras when the app it's open for the first time
window.plugins.intent.getCordovaIntent (function (intent) {
intenthandler(intent);
});
//To get the intent and extras if the app is running in the background
window.plugins.intent.setNewIntentHandler (function (intent) {
intenthandler(intent);
});
//To handle the params
var intenthandler = function (intent) {
if (intent && intent.extras && intent.extras.myParams) {
//Do something
}
};
这就是全部!
这篇关于从离子应用程序调用本机Android应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!