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 janleow · Apr 01, 2017 at 07:13 AM · androidjava to c#intent

Sending data using intent from Unity app to Android app

I have two separate apps, AppA (developed using Android Studio) and AppB (developed using Unity). AppA will launch AppB (which is a game app). After the user is done playing the game (AppB) and click the logout button, it will send the game records (string arrays) back to AppA.

Currently, AppA is able to launch AppB, but I can't get AppB to send the game records (using intent) back to AppA.

AppA's StartGameActivity :

 Intent launchGameIntent = getPackageManager().getLaunchIntentForPackage("com.joy.AppB"); 
     startActivity(launchGameIntent);
 
     retrieveGameRecords = (Button) findViewById(R.id.retrieveRecordsButton);
     retrieveGameRecords.setOnClickListener(new View.OnClickListener() {
         public void onClick(View v) {
 
             //Retrieving game records from game app
             database = new gameDbHelper(StartGameActivity.this.getApplicationContext()).getWritableDatabase();
             Intent intent = getIntent();
             String[] gameRecords_array = intent.getStringArrayExtra("gameRecord");
             System.out.println("Number of game records received from game : " + gameRecords_array.length);

AppA's Android Manifest :

 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.joy.AppA">

 <uses-permission android:name="android.permission.INTERNET" />
 <uses-permission android:name="android.permission.CAMERA" />
 <uses-permission android:name="android.permission.FLASHLIGHT" />
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
 <uses-permission android:name="android.permission.GET_ACCOUNTS" />
 <uses-permission android:name="android.permission.WAKE_LOCK" />
 <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
 <permission android:name="com.joy.AppA.permission.C2D_MESSAGE" android:protectionLevel="signature" />
 <uses-permission android:name="com.joy.AppA.permission.C2D_MESSAGE" />
 <uses-feature android:name="android.hardware.camera" />
 <uses-feature android:name="android.hardware.camera.autofocus" />

 <application
     android:largeHeap="true"
     android:allowBackup="true"
     android:icon="@drawable/ic_launcher"
     android:label="@string/app_name"
     android:theme="@style/AppTheme"
     android:name="android.support.multidex.MultiDexApplication">
 
     <activity
         android:name="com.joy.AppA.views.activities.StartGameActivity"
         android:label="Start Game">
         <intent-filter>
             <action android:name="com.joy.AppA.views.activities.LAUNCH_IT"/>
             <category android:name="android.intent.category.DEFAULT" />
         </intent-filter>
         <meta-data
             android:name="android.support.PARENT_ACTIVITY"
             android:value=".views.activities.DashboardActivity" />
     </activity>

AppB's C# code:

 public void sendDataToAppAFunction()
 {
     int counter = 0;
     string className = "com.joy.AppA"; 
     string[] gameRecord_strArray = new string[100];
     AndroidJavaObject launchIntent = null;

     AndroidJavaClass Intent = new AndroidJavaClass (className);
     AndroidJavaObject sendIntent = new AndroidJavaObject (className);

     AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
     AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");

     sendIntent.Set<AndroidJavaObject> ("gameRecord", javaArrayFromCS(gameRecord_strArray));
     sendIntent.Call<AndroidJavaObject> ("putExtra", Intent.GetStatic<string[]>("gameRecord"), gameRecord_strArray);
     currentActivity.Call ("startActivity", sendIntent);
 }

 private AndroidJavaObject javaArrayFromCS(string [] values) {
     AndroidJavaClass arrayClass = new AndroidJavaClass ("java.lang.reflect.Array");
     AndroidJavaObject arrayObject = arrayClass.CallStatic<AndroidJavaObject> ("newInstance", new AndroidJavaClass ("java.lang.String"), values.Length);
     for (int i = 0; i < values.Length; ++i) {
         arrayClass.CallStatic ("set", arrayObject, i, new AndroidJavaObject ("java.lang.String", values [i]));
     }
     return arrayObject;
 }

I tried putting "com.joy.AppA.views.activities.StartGameActivity" for the className in Unity but it gives the same error too.

This is the error I get:

I/Unity: AndroidJavaException: java.lang.ClassNotFoundException: com.joy.AppA java.lang.ClassNotFoundException: com.joy.AppA at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:309) at java.lang.Class.forName(Class.java:273) at com.unity3d.player.UnityPlayer.nativeRender(Native Method) at com.unity3d.player.UnityPlayer.a(Unknown Source) at com.unity3d.player.UnityPlayer$c$1.handleMessage(Unknown Source) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:135) at com.unity3d.player.UnityPlayer$c.run(Unknown Source) Caused by: java.lang.ClassNotFoundException: Didn't find class "com.joy.AppA" on path: DexPathList[[zip file "/data/app/com.joy.AppB-1/base.apk"],nativeLibraryDirectories=[/data/app/com.joy.AppB-1/lib/arm, /vendor/lib, /system/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:511) at java.lang.ClassLoader

Please kindly help me! Thanks in advance for your help! :)

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

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

[ANDROID] How can this intent be made in Unity? 0 Answers

Unity Android app crashes when activated a few times with Android's SDK's startActivity(intent). 1 Answer

Modifying Android intents via C# in Unity 0 Answers

how to open app from notification intent 0 Answers

Android Share intent Twitter not working? 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