簡體   English   中英

從離子應用程序調用本機android應用程序

[英]Call a native android app from ionic app

我正在開發一個將由Android本機應用程序調用的應用程序。 我也必須給他們打電話。 為此,我找到了這個插件

他們將按照以下代碼調用我的應用程序(並希望我調用他們的應用程序):

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);

當他們這樣做時,我不知道該插件是否可以打開我的應用程序(他們的應用程序也將打開)。

我尋找一種在離子中使用意圖的方法,但沒有發現任何問題。

謝謝!

也許它將幫助某人我如何解決它。

要打開另一個Android應用程序,請使用com.lampa.startapp 這樣做的代碼是:

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 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
      }
};

就這樣!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM