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
5
Question by Onizuka101 · Oct 15, 2016 at 02:16 PM · unity 5vrjavalauncherintent

Opening another Unity app with java intent, sending a parameter and reading it in the second Unity app

Hello everyone, I have been struggling with this problem for days now, I would really appreciate some help. I am making a gear vr game that requires people to put in their email and name before they play. The idea here is to avoid having a vr keyboard input and just have a simple launch app with UI fields that once filled will open the vr app and send the name and email as a java intent. I've been all over the web trying to look for solutions but nothing has worked so far, here is the code I use in the launch app:

 public void LaunchApp() {
         bool fail = false;
         string message = playerName.text + "_" + email.text;
         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);
             launchIntent.Call<AndroidJavaObject>("putExtra", bundleId + "arguments", message);
         }
         catch (System.Exception e){
             fail = true;
         }
 
         if (fail) {
             Debug.Log("app not found");
         }
         else
         {
             ca.Call("startActivity", launchIntent);
         }
         up.Dispose();
         ca.Dispose();
         packageManager.Dispose();
         launchIntent.Dispose();
     }

and this is the code I use to try and read the intent in the vr app once it opens, right in the start function:

 void Start () {
         string arguments = "";
 
         AndroidJavaClass UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
         AndroidJavaObject currentActivity = UnityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
 
         AndroidJavaObject intent = currentActivity.Call<AndroidJavaObject>("getIntent");
         bool hasExtra = intent.Call<bool>("hasExtra", "arguments");
 
         if (hasExtra)
         {
             AndroidJavaObject extras = intent.Call<AndroidJavaObject>("getExtras");
             arguments = extras.Call<string>("getString", "arguments");
             mytext.text = arguments;
         }
     }

I also tried going the "custom" android plugin way but no luck, I'm not that well versed in native java dev, Any ideas what I am doing wrong?

Thank you

Comment
Add comment · Show 1
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 FC_Alessandro · Oct 15, 2016 at 09:47 PM 0
Share

I'm stuck on something similar myself, but co$$anonymous$$g from and android app. I'm not sure what the procedure for reading an intent is from unity. Was anyone able to get this working?

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer Wiki

Answer by Onizuka101 · Oct 16, 2016 at 05:32 AM

UPDATE: So I feel like an idiot but I actually solved this... at the end all of the code was correct my only problem was that when sending the extra I included the bundle id for some reason. I removed it and it worked like a charm! I hope this will help anyone that comes across this problem.

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
avatar image
1

Answer by angusmf · Jan 14, 2017 at 03:19 PM

As indicated in @Onizuka101's answer, the bundle id is added to the string identifier for the extra info. For completeness, the LaunchApp code should be:

 public void LaunchApp() {
          bool fail = false;
          string message = playerName.text + "_" + email.text;
          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);
              launchIntent.Call<AndroidJavaObject>("putExtra", "arguments", message);
          }
          catch (System.Exception e){
              fail = true;
          }
  
          if (fail) {
              Debug.Log("app not found");
          }
          else
          {
              ca.Call("startActivity", launchIntent);
          }
          up.Dispose();
          ca.Dispose();
          packageManager.Dispose();
          launchIntent.Dispose();
      }
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 ravibabu435 · Jun 16, 2018 at 04:27 AM 0
Share

This is the important line of code.

launchIntent.Call("putExtra", "arguments", message);

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

9 People are following this question.

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

Related Questions

How to send multiple screenshots to the android intent(Social networks - Mail, WhatsApp, Hangouts, Facebook ...etc) 2 Answers

VR app development, unity camera face downward when i face my xperia c4 camera downward during selection 0 Answers

How do I get list of installed android apps with their icons? 1 Answer

Is it feasible to play 4K video in Unity? 8 Answers

How to download 360 video to Android device's Streaming assets folder, before playback using Easy Movie Texture. 1 Answer


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