2016-05-11 13 views
2

アンドロイドネイティブアプリから呼び出されるアプリを開発しています。私も彼らに電話しなければならない。これを行うために私はthis pluginを見つけました。ionicアプリからネイティブアンドロイドアプリを呼び出す

彼らは私のアプリを呼び出して(と私は彼らを呼び出すことを期待する)このコードは次のようになります。

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

プラグインは、彼らがこれを行うとき、私のアプリを開くために働くだろう場合、私は得ることはありません(とそのアプリまた開きます)。

私はionicで意図を使用する方法を探しますが、私は何も見つかりませんでした。

ありがとうございます!

答えて

3

多分私はそれを解決した方法を助けるでしょう。

別のアンドロイドアプリを開くには、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 
     } 
}; 

すべてです!

関連する問題