Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Jona27 · Oct 18, 2012 at 08:46 AM · androidactivity

How to get Native Activity of Unity in Android NDK?

Hello,

I would like to use the camera of Android to retrieve previews and apply some processing. This action is only possible in Java and to retrieve preview, Camera instance needs to be attached to a SurfaceView. But to create a SurfaceView, we need the instance of the current Activity or at least, the context.

Unity will call a native function of the android library (like init_camera()). Next, this function will load and call the Java class responsible of the Camera management and preview retrieving. But I need to give to it the instance of the current Activity of Unity.

My question is: how to do that?

I will be very grateful if anyone could help me. I know that Unity can access itself to android camera but it's not what I want.

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 kakyounity · Dec 21, 2012 at 02:58 PM 0
Share

I have a similar problem and I'm also wondering how to do it. This doc http://docs.unity3d.com/Documentation/$$anonymous$$anual/PluginsForAndroid.html mentioned that there exists a class UnityPlayerNativeActivity, but I can't find it in script reference.....

2 Replies

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

Answer by Psymon · Dec 21, 2012 at 06:59 PM

You need to create a class MainActivity inherited from UnityPlayerActivity. Quick example :

 package com.example.myplugin;
 import com.unity3d.player.UnityPlayer;
 import com.unity3d.player.UnityPlayerActivity;
                 
 public class MainActivity extends UnityPlayerActivity {
      
     @Override
     public void onCreate(Bundle savedInstanceState) {
     
         RelativeLayout m_Root = new RelativeLayout(this);
         m_Root.setId(1);
 
         this.addContentView(m_Root, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
     
         SurfaceView mySurface = new SurfaceView(this);
         mySurface.setId(2);
         m_Root.addView(mySurface);
     

Then when you'll build your plugin as a .jar you set your androidmanifest in your Assets/Plugins/Android/ folder in Unity.

For example :

 <?xml version="1.0" encoding="utf-8"?>
 <manifest
     xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.example.myplugin"
     android:installLocation="preferExternal"
     android:versionCode="1"
     android:versionName="1.0">
 
     <application
         android:icon="@drawable/app_icon"
         android:label="@string/app_name"
         android:debuggable="true">
       
         
         <activity android:name="com.example.myplugin.MainActivity"
                   android:label="@string/app_name"
                   android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
         
     </application>
 </manifest>
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
0

Answer by Jona27 · Oct 18, 2012 at 12:33 PM

I found out that the java UnityPlayer.currentActivity returns the current Activity. Does this method work in any java class in a plugin?

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

Run again activity Android Plugin 0 Answers

Restarting UnityPlayer inside of Android activity 0 Answers

A node in a childnode? 1 Answer

Unity / QCAR Activity on Android 1 Answer

Send realtime data via android to a unity based PC game 2 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