• 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
3
Question by The_Eagle_Thing · Feb 09, 2015 at 04:06 AM · android

Can't recieve android media controls in plugin

Hi,

I try to recieve events from the buttons of a headset pluged into an android device. I already made a app without unity, just to test if its working in general and it does. I followed this article: http://developer.android.com/training/managing-audio/volume-playback.html

Now i tried to use the same code my unity android plugin. So i added

         mAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
         mRemoteControlResponder = new ComponentName(getPackageName(),
                 RemoteControlReceiver.class.getName()); 

to the onCreate Method of my main activity. Futhermore i added:

     @Override
     protected void onResume() {
         super.onResume();
         startLocationListeners();
         sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR),
                 SensorManager.SENSOR_DELAY_FASTEST);
         mAudioManager.registerMediaButtonEventReceiver(mRemoteControlResponder);
         
         Log.d("AndroidPluginActivity", "ON RESUME");
     }
     
     @Override
     public void onDestroy() {
         super.onDestroy();
         mAudioManager.unregisterMediaButtonEventReceiver( mRemoteControlResponder); //unregister app as app to get all sound remote inputs
         Log.d("AndroidPluginActivity", "ON DESTROY");
     }

to the acitivity class.

RemoteControlReciever looks like this

 public class RemoteControlReceiver extends BroadcastReceiver {
 
     @Override
     public void onReceive(Context context, Intent intent) {
          Log.d("AndroidPluginActivity", "Java Plugin Headset Action A");
         if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) {
             
             KeyEvent event = (KeyEvent) intent .getParcelableExtra(Intent.EXTRA_KEY_EVENT);
             
             if (event == null) {
                 return;
             }
             Log.d("AndroidPluginActivity", "Java Plugin Headset Action B"+event.getKeyCode());
             if (event.getAction() == KeyEvent.ACTION_DOWN) {
                 Log.d("AndroidPluginActivity", "Java Plugin Headset Action Key Down"+event.getKeyCode());
                 UnityPlayer.UnitySendMessage("Main Camera", "switchState", "");
                abortBroadcast();
             }
         }
     }
 
 }

Finally i added the lines

     <receiver android:name="com.TimReiter.SkyglassUnity.RemoteControlReceiver">
             <intent-filter>
                 <action android:name="android.intent.action.MEDIA_BUTTON" />
             </intent-filter>
     </receiver>


Both to the xml in the jar and the xml besides the jar plugin in the assets folder. Package path is com.TimReiter.SkyglassUnity

I don't recieve any signals besides from "ON RESUME" via logcat... What I'm doing wrong? It barely looks like unity is "swallowing" all reciever signals

Comment
Add comment · Show 5
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 The_Eagle_Thing · Feb 09, 2015 at 02:20 PM 0
Share

Okay, it's really weird after 5 $$anonymous$$utes running the app i suddenly get some data form time to time

avatar image The_Eagle_Thing · Feb 12, 2015 at 10:44 AM 0
Share

Okay, recieving volume control signals work. However, play/pause signals get lost when the engine loading prompt screen finsihes. Also tried to recieve signals with this code

     @Override
     public boolean dispatch$$anonymous$$eyEvent($$anonymous$$eyEvent event) {
         int action = event.getAction();
         int keyCode = event.get$$anonymous$$eyCode();
         Log.d("AndroidPluginActivity", ""+keyCode);
         
             switch (keyCode) {
             case $$anonymous$$eyEvent.$$anonymous$$EYCODE_VOLU$$anonymous$$E_UP:
                 if (action == $$anonymous$$eyEvent.ACTION_DOWN) {
                     UnityPlayer.UnitySend$$anonymous$$essage("$$anonymous$$ain Camera", "volumeUpPushed","");
                 }
                 return true;
             case $$anonymous$$eyEvent.$$anonymous$$EYCODE_VOLU$$anonymous$$E_DOWN:
                 if (action == $$anonymous$$eyEvent.ACTION_DOWN) {
                     UnityPlayer.UnitySend$$anonymous$$essage("$$anonymous$$ain Camera", "volumeDownPushed","");
                 }
                 return true;
             default:
                 return super.dispatch$$anonymous$$eyEvent(event);
             }
         }
avatar image TeddyBird · Apr 08, 2015 at 02:21 PM 0
Share

Got the exact same issue, have you resolved this yet?

avatar image The_Eagle_Thing · Apr 08, 2015 at 04:59 PM 0
Share

No, also send a bug report to Unity. No answer since 2 months or so.

avatar image charles_littlstar · Feb 24, 2016 at 08:32 PM 0
Share

Any news on this? have this issue as well!

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I get Android game from computer to phone? 1 Answer

from Local Database on PC to Android. 1 Answer

I use Unity 5.2.2. Android Manifest It gives error. What can I do ? 0 Answers

Android build freezes on attaching unity profiler 0 Answers

Mobile Computer Vision functionality advice 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