Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ishafdo4 · May 16, 2017 at 04:43 PM · c#unity 5javaandroidplugin

How to load android app when the button clicked in unity scene?

I have created android app and unity game. So I was able to load unity game from android app using button click event. And the next step is I need to come back to the android app (Specific activity) if the user want. How can I launch the android activity when the user press button. This will be a great help for me, I am tired with this problem. I am trying to solve this within 7 days but I unable to solve it.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Vandarthul · May 18, 2017 at 12:38 PM

Hey @ishafdo4

Try this:

 public void LaunchApp(string package, string storeLink = null)
     {
         bool fail = false;
         string bundleId = package; // your target bundle id
         AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
         AndroidJavaObject ca = up.GetStatic<AndroidJavaObject>("currentActivity");
         AndroidJavaObject packageManager = ca.Call<AndroidJavaObject>("getPackageManager");
 
         AndroidJavaObject launchIntent = null;
         try
         {
             launchIntent = packageManager.Call<AndroidJavaObject>("getLaunchIntentForPackage", bundleId);
         }
         catch (System.Exception e)
         {
             fail = true;
         }
 
         if (fail && storeLink != null)
         { //open app in store
             Application.OpenURL(storeLink);
         }
         else //open the app
             ca.Call("startActivity", launchIntent);
 
         up.Dispose();
         ca.Dispose();
         packageManager.Dispose();
         launchIntent.Dispose();
     }

package is bundleIdentifier of app, such as "com.facebook.katana" and optional parameter is the store link of the app in case the app is not found in device, you can leave it as null and it will only try to open the app if it exists.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ishafdo4 · May 19, 2017 at 07:50 AM 0
Share

Thank you very much @Vandarthul I tried this. And I works successfully. You saved my time. again thank you very much...........!!!!!

avatar image Vandarthul ishafdo4 · May 19, 2017 at 09:02 AM 1
Share

No problem at all, glad it worked for you.

avatar image shahin2002 · Feb 23, 2019 at 12:27 PM 0
Share

How I can open the"play store"(google) in unity by this code? I tested but I could not open play store app.help me plaese

avatar image shahin2002 shahin2002 · Feb 23, 2019 at 12:29 PM 0
Share

means open link my games in " google play store " Application

avatar image
0

Answer by tanveertak · May 19, 2017 at 01:51 PM

1)if you have make the game as you mentioned then use

public void ExitGame()

 {
     Application.Quit();
 }

on the back button it will exit the game 2)and also you have mentioned you also created android app then you would be familiar with activity life cycle on resume() function will be called and you can redirect the user to any activity you want using intents

Intent i=new Intent(getApplicationContext(),SecondActivity.class);

             startActivity(i);

             setContentView(R.layout.activity_second);

second activity might be your home activity or what every activity you want .

this might not be you expecting the answer but as you mention you have spend 7 days .so it might help but it is alternate and might help you to open your mind for something you are missing till some one else answer

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image shahin2002 · Feb 23, 2019 at 12:27 PM 0
Share

How I can open the"play store"(google) in unity by this code? I tested but I could not open play store app.help me plaese

avatar image
0

Answer by shahin2002 · Feb 23, 2019 at 12:27 PM

How I can open the"play store"(google) in unity by this code? I tested but I could not open play store app.help me plaese

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image shahin2002 · Feb 23, 2019 at 12:29 PM 0
Share

means open link my games in " google play store " Application

avatar image
0

Answer by paresh_unity496 · Nov 05, 2019 at 11:18 AM

it's work then ok. other wise you should try this. . i have same scenario as you mention in question. this work for me. https://medium.com/@davidbeloosesky/embedded-unity-within-android-app-7061f4f473a

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

AndroidJava and Implementing java.util.List 0 Answers

How to write a java lib for unity as a plugin to make run another android app? 1 Answer

Shove Player the opposite way of the collider 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges