Im trying to write a simple test app that listens in the background(using BroadcastReceiver) for Google Glass camera events such as taken picture, and than take that picture & do something with it. onReceive() is not being called.
My Google Glass is running XE19.1 OS & my GDK api is Google Glass Development Preview 4.4.2.
My class that extends BroadcastReceiver:
package com.example.recentpicscollage;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.util.Log;
import android.widget.Toast;
public class TestReciever extends BroadcastReceiver {
//Attempt # 1 listen to picture taken events
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Log.d("DEBUG", "RecentPicsCollage BroadcastReceiver");
//use the Cursor interface to query data from the Intent ( Intents asynchronous intera & inter app communication)
Cursor cursor = context.getContentResolver().query(intent.getData(),null,null, null, null);
//The moveToFirst() method is used to position the cursor pointer at the beginning of the data set
cursor.moveToFirst();
//get data under the column _data
String image_path = cursor.getString(cursor.getColumnIndex("_data"));
//as toast
Toast.makeText(context, "image data : " + image_path, 1000).show();
//as log
Log.d("DEBUG", "image data: "+image_path);
for (int i=0; i<cursor.getColumnNames().length; i++)
{
Log.d("DEBUG", "column name: "+cursor.getColumnNames()[i]);
}
//just print out all data to see what data is available
while (cursor.isAfterLast()!=true)
{
//move to next row
cursor.moveToNext();
//get data
String data = cursor.getString(cursor.getColumnIndex("_data"));
Log.d("DEBUG", "image data: "+data);
}
}
/*
//Attempt # 2 , Test to see if i can capture any other action such as TAP
@Override
public void onReceive(Context context, Intent intent) {
System.out.println("onReceive TAP");
Log.d("DEBUG", "onReceive TAP");
}
*/
}//end class
AndroidManifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.recentpicscollage"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<!-- permission to read SD card -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name="com.example.recentpicscollage.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- broadcast receiver that listens actions/event associated with NEW PICTURE -->
<receiver
android:name=".TestReciever"
android:enabled="true"
android:priority="999" >
<intent-filter>
<action android:name="com.android.camera.NEW_PICTURE" />
<action android:name="android.hardware.action.NEW_PICTURE" />
<action android:name="android.provider.MediaStore.ACTION_IMAGE_CAPTURE" />
<action android:name="com.google.android.glass.media.CameraManager.ACTION_IMAGE_CAPTURE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</receiver>
<!-- broadcast receiver that listens actions/event associated with a TAP-->
<!--
<receiver android:name=".TestReciever" android:exported="false">
<intent-filter android:priority="999" >
<action android:name="com.google.glass.action.TAP" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</receiver>
-->
</application>
</manifest>
In my first attempt a I tried to capture image capture event & I tried all combinations of filter such as:
<action android:name="com.android.camera.NEW_PICTURE" />
<action android:name="android.hardware.action.NEW_PICTURE" />
<action android:name="android.provider.MediaStore.ACTION_IMAGE_CAPTURE" />
<action android:name="com.google.android.glass.media.CameraManager.ACTION_IMAGE_CAPTURE" />
<category android:name="android.intent.category.DEFAULT" />
But nothing is being logged or printed to the console.
In my 2nd attempt I tried registering for another event in this case TAP event , but I cant get onReceive() to be called for that either, the code is simple I'm either missing something very small or their is a bug in XE19.1 release for Glass.
Any intellegent help will be appreciated.
Thanks