android - Google Glass File Observer Not Working Properly -


the goal of program (at least in stage) photo glass , display on screen (i using immersion).

my class (extends activity of course) has following:

protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_picture_analysis);      intent gettheimageintent = new intent(mediastore.action_image_capture);     startactivityforresult(gettheimageintent, 25); } 

which launches camera. after user takes , accepts photo, calls public void onactivityresult method

public void onactivityresult(int requestcode, int resultcode, intent data) {        // bunch of debug logging inserted     log.d("glass", "got pic!!");     log.d("glass", string.valueof(resultcode));     log.d("glass", string.valueof(resultcode==result_ok));       if (data.getextras() != null && requestcode == 25) {         log.d("glass", "in if");          //create instance of bundle , returned data         bundle extras = data.getextras();          final string pathtoimage = (string) extras.get("picture_file_path");          (string key : extras.keyset()) {             object value = extras.get(key);             log.d("glass", string.format("%s %s (%s)", key,                     value.tostring(), value.getclass().getname()));         }             fileobserver observer = new fileobserver(pathtoimage) {              @override             public void onevent(int event, string path) {                  log.d("glass", "we observed event");                  if (event == fileobserver.close_write || event==fileobserver.close_nowrite) {                     bitmap thepicunscaled = bitmapfactory.decodefile(pathtoimage);                      log.d("glass", "observer found close_write event");                       bitmap thepic = bitmap.createscaledbitmap(thepicunscaled,                             getresources().getdisplaymetrics().widthpixels,                             getresources().getdisplaymetrics().heightpixels,                             true);                      imageview imgview = (imageview) findviewbyid(r.id.thepictureview);                     imgview.setimagebitmap(thepic);                 }             }         };          observer.startwatching();         log.d("glass","observer started watching");       } else {         log.d("glass", "there no extras passed intent in onactivityresult");     }  } 

now problem although have called file observer, never observes change. though have log.d("glass", "we observed event"); should log every time there event, never logs. logcat (filtered tags) looks like:

05-16 14:27:31.007    4976-4976/com.nkhosla.glasstest.app d/dalvikvm﹕ late-enabling checkjni 05-16 14:27:31.007    4976-4976/com.nkhosla.glasstest.app d/dalvikvm﹕ try disable coredump pid 4976 05-16 14:27:31.007    4976-4976/com.nkhosla.glasstest.app d/dalvikvm﹕ process 4976 nice name: com.nkhosla.glasstest.app 05-16 14:27:31.007    4976-4976/com.nkhosla.glasstest.app d/dalvikvm﹕ options: not specified 05-16 14:27:32.031    4976-4976/com.nkhosla.glasstest.app d/openglrenderer﹕ enabling debug mode 0 05-16 14:27:35.625    4976-4976/com.nkhosla.glasstest.app d/glass﹕ got pic!! 05-16 14:27:35.625    4976-4976/com.nkhosla.glasstest.app d/glass﹕ -1 05-16 14:27:35.625    4976-4976/com.nkhosla.glasstest.app d/glass﹕ true 05-16 14:27:35.625    4976-4976/com.nkhosla.glasstest.app d/glass﹕ in if 05-16 14:27:35.625    4976-4976/com.nkhosla.glasstest.app d/glass﹕ thumbnail_file_path /storage/emulated/0/thumbnail_cache/t_thumb_20140516_142732_930.jpg (java.lang.string) 05-16 14:27:35.625    4976-4976/com.nkhosla.glasstest.app d/glass﹕ picture_file_path /storage/emulated/0/dcim/camera/20140516_142732_930.jpg (java.lang.string) 05-16 14:27:35.640    4976-4976/com.nkhosla.glasstest.app d/glass﹕ observer started watching 

i have tried access file there, right after observer starts watching, nullpointerexception if try access bitmap created using bitmap thepicunscaled = bitmapfactory.decodefile(pathtoimage);

i have left file observer sit watch @ least 5 or seconds, eternity in flash write speeds. have no clue problem is.

for reference, layout.xml:

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     android:paddingbottom="@dimen/activity_vertical_margin"     tools:context="com.nkhosla.glasstest.app.pictureanalysis">       <imageview         android:layout_height="fill_parent"         android:layout_width="fill_parent"         android:id="@+id/thepictureview"         android:maxheight="300dp"         android:maxwidth="640dp"         android:scaletype="centercrop"         android:adjustviewbounds="true"/>  </relativelayout> 

if thing you're interested in when using camera intent scaled down version of image, should use cameramanager#extra_thumbnail_file_path instead of full picture reasons:

  1. it available right away: full image may take multiple seconds written due post processing
  2. it scaled-down preview size

if need full image, fileobserver should observe parent directory of file, not file itself. here code snippet provided in our developer's guide:

private static final int take_picture_request = 1;  private void takepicture() {     intent intent = new intent(mediastore.action_image_capture);     startactivityforresult(intent, take_picture_request); }  @override protected void onactivityresult(int requestcode, int resultcode, intent data) {     if (requestcode == take_picture_request && resultcode == result_ok) {         string picturepath = data.getstringextra(                 cameramanager.extra_picture_file_path);         processpicturewhenready(picturepath);     }      super.onactivityresult(requestcode, resultcode, data); }  private void processpicturewhenready(final string picturepath) {     final file picturefile = new file(picturepath);      if (picturefile.exists()) {         // picture ready; process it.     } else {         // file not exist yet. before starting file observer,         // can update ui let user know application         // waiting picture (for example, displaying thumbnail         // image , progress indicator).          final file parentdirectory = picturefile.getparentfile();         fileobserver observer = new fileobserver(parentdirectory.getpath(),                 fileobserver.close_write | fileobserver.moved_to) {             // protect against additional pending events after close_write             // or moved_to handled.             private boolean isfilewritten;              @override             public void onevent(int event, string path) {                 if (!isfilewritten) {                     // safety, make sure file created in                     // directory 1 we're expecting.                     file affectedfile = new file(parentdirectory, path);                     isfilewritten = affectedfile.equals(picturefile);                      if (isfilewritten) {                         stopwatching();                          // file ready, recursively call                         // processpicturewhenready again (on ui thread).                         runonuithread(new runnable() {                             @override                             public void run() {                                 processpicturewhenready(picturepath);                             }                         });                     }                 }             }         };         observer.startwatching();     } } 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -