Call a native android app from ionic app

前端 未结 1 695
后悔当初
后悔当初 2021-01-15 10:47

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 m

1条回答
  •  悲哀的现实
    2021-01-15 11:47

    Maybe it will help someone how I resolved it.

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

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

    That's all!

    0 讨论(0)
提交回复
热议问题