- Home /
BroadcastReceiver onReceive does not work (custom Unity Android plugin)
Hello friends. I am working in a plugin to capture the actions of an external input-peripheral and send these to a game in Unity. I have a class in java that extends UnityPlayerActivity, here, I have override some methods to test if the conexion between this class and Unity is working, for example, the onStart method it is call. The main point is that I need to create a BroadcastReceiver, and I do it like this:
 protected static final int EVENT_BUTTON = 8000;
 protected static final int EVENT_BUTTON1 = EVENT_BUTTON + 1;
 protected static final int EVENT_BUTTON2 = EVENT_BUTTON + 2;
     
 private BroadcastReceiver ReceivePeripheral = new BroadcastReceiver()
 {
     @Override
     public void onReceive (Context context, Intent intent)
     {
         SendMessageToUnity("onReceive");
         
         try {
             Log.d("TEST", "ONReceive");
 
             CommunicationIntent info =
                 CommunicationIntent.intentToCommunicationIntent(context, intent);
             
             switch (info.getIdEvent())
             {
                 case EVENT_BUTTON1:
                     Toast.makeText
                     (
                         context,
                         "Intent peripheral button 1 " + info.getValue("action"),
                         Toast.LENGTH_LONG
                     ).show();
                     
                     SendMessageToUnity("onReceive EVENT_BUTTON1");
                     break;
 
                 case EVENT_BUTTON2:
                     Toast.makeText
                     (
                         context,
                         "Intent peripheral button 2 " + info.getValue("action"),
                         Toast.LENGTH_LONG
                     ).show();
                     
                     SendMessageToUnity("onReceive EVENT_BUTTON2");
                     break;
 
                 default:
                     break;
             }
         } catch (Exception e) {
             e.printStackTrace();
         }
     }
 };
And this seems not to be working...
The receiver is registered in the onStart method:
 @Override
 protected void onStart ()
 {
     IntentFilter iFilter = new IntentFilter("amialcance.accessiblegame");
     instance.registerReceiver(ReceivePeripheral, iFilter);
     
     super.onStart();
     
     SendMessageToUnity("Started");
 }
and the AndroidManifest.xml:
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.company.pushTest"
     android:versionCode="1"
     android:versionName="1.0" >
 
     <uses-sdk
         android:minSdkVersion="14"
         android:targetSdkVersion="20" />
 
     <application
         android:allowBackup="true" >
         
         <activity android:name=".PushButtonPlugin"
              android:label="@string/app_name"
              android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
     
     </application>
 
 </manifest>
 
I have lost a lot of time with this... Anyone can help me?
Thanks!
Your answer
 
 
             Follow this Question
Related Questions
GooglePlayGames plugin path not correct? 0 Answers
android time cheat plugin problem with broadcastreceiver 1 Answer
How to alter the Android Manifest to use my ad-displaying activity in Unity? 0 Answers
How to write a java lib for unity as a plugin to make run another android app? 1 Answer
Web plugin like uWebKit for Android? 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                