The onReceive function is called when the BroadcastReceiver is registered in the manifest, but NOT if it is registered dynamically.
Below is the code:
public class EyeGesture extends BroadcastReceiver { //Eye Gesture private static IntentFilter eyeGestureIntent; private static Context eyeGestureContext; private static StringBuilder gestureInfo = null; private static BroadcastReceiver broadcastReceiver; // public void startEyeListening() { //Eye Gesture //} @Override public void onReceive(Context context, Intent intent) { // this = context; if (intent.getStringExtra("gesture").equals("WINK")) { Log.e("WINKED ",""); }else { Log.e("SOMETHING", "is detected " + intent.getStringExtra("gesture")); } //Disable Camera Snapshot // abortBroadcast(); } public void stopEyeListening() { eyeGestureContext.unregisterReceiver(broadcastReceiver); eyeGestureIntent = null; eyeGestureContext = null; gestureInfo = null; } }
Below is the manifest file
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.inno.inno.glassplugin" > <uses-permission android:name="com.google.android.glass.permission.DEVELOPMENT" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainFunct" android:icon="@drawable/ic_glass_logo" android:label="@string/title_activity_main_funct" > <intent-filter> <action android:name="com.google.android.glass.action.VOICE_TRIGGER" /> </intent-filter> <meta-data android:name="com.google.android.glass.VoiceTrigger" android:resource="@xml/voice_trigger" /> </activity> <receiver android:name="com.inno.inno.glassplugin.EyeGesture"> <intent-filter> <action android:name="com.google.android.glass.action.EYE_GESTURE" /> </intent-filter> </receiver> </application> </manifest>
The problem is that the onReceive NOT function is called during dynamic accounting. I have to do it dynamically. The code below is NOT a working code.
public class EyeGesture extends Activity { //Eye Gesture IntentFilter eyeGestureIntentFilter; Context eyeGestureContext; BroadcastReceiver broadcastReceiver; public EyeGesture(){ Log.e("CONSTRUCTOR ", ""); eyeGestureContext = MainFunct.getCurrentContext(); eyeGestureIntentFilter = new IntentFilter("com.google.glass.action.EYE_GESTURE"); eyeGestureIntentFilter.setPriority(1000); startRunning(); } void startRunning(){ eyeGestureContext.registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.e("Received ", " Something"); } },eyeGestureIntentFilter); } @Override public void onResume(){ super.onResume(); } @Override public void onPause(){ super.onPause(); unregisterReceiver(broadcastReceiver); } public void stopEyeListening() { eyeGestureContext.unregisterReceiver(broadcastReceiver); eyeGestureIntentFilter = null; eyeGestureContext = null; } }
Also, I don't want to extend the BroadcastReceiver from this class. Why am I not getting anything if registered dynamically. I also removed the following line from the manifest:
<receiver android:name="com.inno.inno.glassplugin.EyeGesture"> <intent-filter> <action android:name="com.google.android.glass.action.EYE_GESTURE" /> </intent-filter> </receiver>
but still it does not work. Bug fixed or exception. What am I doing wrong?
android google-glass android-intent android-activity google-gdk
Programmer
source share