I'm on a roll here with being confused with Google Glass development! My app is currently taking photos using the built-in camera functionality and the sample code on the GDK site (https://developers.google.com/glass/develop/gdk/camera). When I take a photo, it looks like a picture is being taken, but then when I try to upload it to an imgur server (using their API), I get a FileNotFound Exception. Also when I try using Android Studio's File Explorer, I can't seem to find any images in the filepath it should be in. It seems like the file is not being created, or I'm accessing the wrong path somehow. What could I be doing wrong?
Code for using the camera:
public void startRecog(){
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.i(TAG,"Got to onActivity");
Log.i(TAG,"Request code: " + requestCode + ", Result code: " + resultCode + ", what it wants: " + RESULT_OK);
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE && resultCode == RESULT_OK) {
Log.i(TAG,"Got inside the IF");
String picturePath = data.getStringExtra(Intents.EXTRA_THUMBNAIL_FILE_PATH);
// String picturePath = data.getStringExtra(Intents.EXTRA_PICTURE_FILE_PATH);
Log.i(TAG,"The real path: " + picturePath);
processPictureWhenReady(picturePath);
}
super.onActivityResult(requestCode, resultCode, data);
}
private void processPictureWhenReady(final String picturePath) {
final File pictureFile = new File(picturePath);
if (pictureFile.exists()) {
// The picture is ready; process it.
Log.i(TAG,"Got in from the picture processing");
new ImgurUploadTask(Uri.parse(picturePath), this).execute();
} else {
// The file does not exist yet. Before starting the file observer, you
// can update your UI to let the user know that the application is
// waiting for the picture (for example, by displaying the thumbnail
// image and a 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 is handled.
private boolean isFileWritten;
@Override
public void onEvent(int event, String path) {
if (!isFileWritten) {
// For safety, make sure that the file that was created in
// the directory is actually the one that we're expecting.
File affectedFile = new File(parentDirectory, path);
isFileWritten = affectedFile.equals(pictureFile);
if (isFileWritten) {
stopWatching();
// Now that the file is ready, recursively call
// processPictureWhenReady again (on the UI thread).
runOnUiThread(new Runnable() {
@Override
public void run() {
processPictureWhenReady(picturePath);
}
});
}
}
}
};
observer.startWatching();
}
}
The errors I am getting:
11-01 14:34:43.281 10449-10449/com.example.cerveau.recognizeplaces I/RecogPlaces﹕ Got to onActivity
11-01 14:34:43.281 10449-10449/com.example.cerveau.recognizeplaces I/RecogPlaces﹕ Request code: 100, Result code: -1, what it wants: -1
11-01 14:34:43.281 10449-10449/com.example.cerveau.recognizeplaces I/RecogPlaces﹕ Got inside the IF
11-01 14:34:43.281 10449-10449/com.example.cerveau.recognizeplaces I/RecogPlaces﹕ The real path: /storage/emulated/0/storage/emulated/0/thumbnail_cache/t_thumb_20141101_143439_397.jpg
11-01 14:34:43.281 10449-10449/com.example.cerveau.recognizeplaces I/RecogPlaces﹕ Got in from the picture processing
11-01 14:34:43.288 10449-10704/com.example.cerveau.recognizeplaces E/ImgurUploadTask﹕ could not open InputStream
java.io.FileNotFoundException: No content provider: /storage/emulated/0/thumbnail_cache/t_thumb_20141101_143439_397.jpg
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1049)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:904)
at android.content.ContentResolver.openInputStream(ContentResolver.java:629)
at com.example.cerveau.recognizeplaces.ImgurUploadTask.doInBackground(ImgurUploadTask.java:32)
at com.example.cerveau.recognizeplaces.ImgurUploadTask.doInBackground(ImgurUploadTask.java:16)
at android.os.AsyncTask$2.call(AsyncTask.java:302)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:240)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
And yes, I think I have the right permissions set in my AndroidManifest...
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="com.google.android.glass.permission.DEVELOPMENT" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET" />
Thanks guys! I keep butting my head into problems every step of the way with developing for Glass and it's frustrating me to no end. I really appreciate your help!
0 comments:
Post a Comment