Skip to main content

Launch android application within Unity app.

In Unity android application(called application A), you want to launch other android app(application B).
I had tried to follow some entries and try : 
List<ApplicationInfo> packages = getPackageManager().getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages) {
if(packageNameToOpen.equals(packageInfo.packageName)){
try{
Intent intent = new Intent();
intent.putExtra(key, value);
intent.setComponent(new ComponentName(packageName,activityName));
UnityPlayer.currentActivity.startActivity(intent);
}catch(Exception e){
}
Android manages its items in "tasks" and "activity stack". If you normally call new activity as above, the activity of other app would be put in to same task of the current applications, which means you are not openning new application. You can see an example of opening mail client, the mail client allow you to call mail activity and it is put in to your current application's task.

To open separate application, you need to use:

The right method:

final PackageManager pm = UnityPlayer.currentActivity.getPackageManager();
Intent LaunchIntent = pm.getLaunchIntentForPackage(packageNameToOpen);
try{
LaunchIntent.putExtra(key, value);
UnityPlayer.currentActivity.startActivity(LaunchIntent);
}catch(Exception e){
}
<Note:> Need to add "singleInstance" launchmode to manifest of the new-app, in some case.
Hope it helps

Comments

Popular posts from this blog

Install Ruby on Rails on MAC

Hello, I am quite familliar with Apache's friend products like XAMPP, LAMPP... And this is the first time I try Ruby on Rails(RoR). I'm quite stuck on installing it. As a normal PHP guy, I first try install Rails, following this tutorial: http://installrails.com/ And the next thing I want to learn about is how RoR works with MySQL, PhpMyadmin. So I tried to make it connect to XAMPP's MySQL but it did not work at all. I found out that, using mySQL in XAMPP package is not a common method, what I should do is to install MySQL as a single service onto my MAC. So I did following: 1. Install MYSQL with HomeBrew Did you install HomeBrew, if not, please follow:  https://coolestguidesontheplanet.com/installing-homebrew-on-os-x-el-capitan-10-11-package-manager-for-unix-apps/ Next, type this command to install MySQL to your machine: $ brew install mysql This will install mysql to your computer, if the installation is success, you could try start using mySQL with this c...

Install MySQL for python on Mac OS 10.9 with XAMPP

Assume that you already have Python installed. 1. Install XAMPP for MAC http://sourceforge.net/projects/xampp/files/ As it is a dmg file, it should be easy to be installed. 2. Now you need to install MySQLdb package for Python a. Download the lastest module of MySQLdb here : http://sourceforge.net/projects/mysql-python/files/latest/download b. Extract it to your prefered location. Notice: You might need to change site.cfg according to your mysql_config path. See the next step c. Setup your path Because you need to setup /bin and /lib folder of XAMPP's MySQL. So, let prepare your $PATH variable. > Edit your ~/.bash_profile ( or ~/.profile) by adding the following lines:  export DYLD_LIBRARY_PATH=/Applications/XAMPP/xamppfiles/lib export PATH=/Applications/XAMPP/xamppfiles/bin/:$PATH Notice: if you are not using XAMPP, you should edit above PATH by your mysql equivalent path. for example /usr/local/mysql/lib and /usr/local/mysql/bin Notice: About site.cfg(in y...

Kí sự Béc-tơ - Vòng quay hoàn hảo

Năm 20xx, một sự kiện vô cùng trọng đại đã diễn ra trên đất nước chúng tôi. Tại đại hội liên đoàn lao động thế giới ĐuA, chúng tôi được vinh dự xếp vào hàng những quốc gia phát triển nhất thế giới. Toà báo yêu cầu tôi đi phỏng vấn vị đại diện liên hợp các doanh nghiệp thần tốc trong nước, ông mới từ hội nghị ĐuA trở về. Tên ông là Rôn-ni-bin. Ngài Rônnibin rất thẳng thắn trong mọi câu trả lời của ngài. Nhiều câu nói của ngài khiến cho bản thân tôi cực kì ngưỡng mộ, đơn cử có một đoạn như sau: "Thưa ngài Rôn, theo ngài thì yếu tố quan trọng nhất để trở thành một người thành công trong bất cứ lĩnh vực nào, đó là gì?" Ngài trả lời: " Theo chúng tôi đó là tính cách độc lập suy nghĩ và không chờ để người khác sai khiến. Chúng tôi đã nghiên cứu CV của rất nhiều bạn sinh viên. Và chúng tôi luôn đánh giá cao những ai như vậy. Đối với 1 người luôn chủ động thì hẳn anh ta sẽ không để thừa 1 phút 1 giây nào trong cuộc sống để hoang phí, và luôn tìm cách để đạt được mục...