android android.provider.MediaStore.ACTION_VIDEO_CAPTURE return null onActivityResult with nexus 7 -


i using intent record video.

so use following code on recordvideo button's click

videofilepath = ""; intent intent = new intent(android.provider.mediastore.action_video_capture); startactivityforresult(intent,request_video_captured); 

and in onactivityresult

protected void onactivityresult(int requestcode, int resultcode, intent data) {          if (resultcode == activity.result_ok) {             switch (requestcode) {             case image_pick:                 this.imagefromgallery(resultcode, data);                 break;             case image_capture:                 this.imagefromcamera(resultcode, data);                 break;             case request_video_captured:                 this.videofromcamera(resultcode, data);                  break;             default:                 break;             }         }     }   private void videofromcamera(int resultcode, intent data) {         urivideo = data.getdata();           uploadedfilename="";         constant.is_file_attach = true;          toast.maketext(pdfactivity.this, urivideo.getpath(), toast.length_long)         .show();         string[] filepathcolumn = { mediastore.video.media.data };          cursor cursor = getcontentresolver().query(urivideo, filepathcolumn,                 null, null, null);         cursor.movetofirst();          int columnindex = cursor.getcolumnindex(filepathcolumn[0]);         string filepath = cursor.getstring(columnindex);         videofilepath = filepath;         system.out.println("videofilepath filepath camera : "                 + videofilepath);         cursor.close();         file f = new file(filepath);         system.out.println("file created ? : " + f.exists());          bitmap bmap = null;         {             try {                 // simulate network access.                 thread.sleep(3000);             } catch (interruptedexception e) {                 e.printstacktrace();             }         } while (!f.exists());         bmap = thumbnailutils.createvideothumbnail(filepath,                 mediastore.video.thumbnails.micro_kind);         {             try {                 // simulate network access.                 thread.sleep(1000);             } catch (interruptedexception e) {                 e.printstacktrace();             }         } while (bmap == null);         imageorvideo = "video";         attachmentvalue.setimagebitmap(bmap);     } 

this code working fine samsung galaxy tab. not working nexus 7. may nexus 7 have front camera. got resultant data intent null onactivityresult.

so in logcat got following exception :-

08-08 12:51:31.160: e/androidruntime(10899): fatal exception: main 08-08 12:51:31.160: e/androidruntime(10899): java.lang.runtimeexception: failure delivering result resultinfo{who=null, request=200, result=-1, data=intent {  }} activity {com.example.activity/com.example.pdfactivity}: java.lang.nullpointerexception 

finally resolved issue. nexus 7 stores videos in dcim directory onactivityresults returns null. documented issue nexus 7 device.

so fix issue intent.putextra(mediastore.extra_output, fileuri);
code :-

code on record button click:-

  intent = new intent(android.provider.mediastore.action_video_capture);        fileuri = getoutputmediafile(media_type_video);  // create file save video in specific folder (this works video only)     intent.putextra(mediastore.extra_output, fileuri);     intent.putextra(mediastore.extra_video_quality, 1); // set video image quality high      // start video capture intent     startactivityforresult(intent, request_video_captured_nexus); 

code inside switch - case block of onactivityresult :-

protected void onactivityresult(int requestcode, int resultcode, intent data) {          if (resultcode == activity.result_ok) {             switch (requestcode) {     case request_video_captured_nexus:     this.videofromcameranexus(resultcode, data);     break;  default:                 break;             }         }     } 

// videofromcameranexus method

private void videofromcameranexus(int resultcode, intent data) {          if(fileuri != null) {             log.d(tag, "video saved to:\n" + fileuri);             log.d(tag, "video path:\n" + fileuri.getpath());             log.d(tag, "video name:\n" + getname(fileuri));      // use uri.getlastpathsegment() if store in folder     //use file uri.         }     } 

get output media file uri following method

public uri getoutputmediafile(int type)     {         // safe, should check sdcard mounted          if(environment.getexternalstoragestate() != null) {             // works android 2.2 , above             file mediastoragedir = new file(environment.getexternalstoragepublicdirectory(environment.directory_movies), "smw_video");              // location works best if want created images shared             // between applications , persist after app has been uninstalled.              // create storage directory if not exist             if (! mediastoragedir.exists()) {                 if (! mediastoragedir.mkdirs()) {                     log.d(tag, "failed create directory");                     return null;                 }             }              // create media file name             string timestamp = new simpledateformat("yyyymmdd_hhmmss").format(new date());             file mediafile;            if(type == media_type_video) {                 mediafile = new file(mediastoragedir.getpath() + file.separator +                 "vid_"+ timestamp + ".mp4");             } else {                 return null;             }              return uri.fromfile(mediafile);         }          return null;     } 

its works me.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -