Tuesday, 20 August 2013

Samsung Galaxy S3 Camera Intent Landscape

Samsung Galaxy S3 Camera Intent Landscape

I've searched for 2 days trying to find the answer to my problem and
haven't really found a satisfactory answer.
I'm making an app that calls the camera Intent and basically takes the
photo captured, put's it into an ImageView to preview, and I have a button
to save the file to a user defined folder in an app folder I create.
I can run my app quite easily with the AVD, my GF's Droid Razr M. But when
I try to run it on my GS3 it dies a horrible death after hitting accept on
the image, unless I force the app to a Landscape mode in the manifest, and
keep the phone in landscape when i take the picture. I think it has
something to do with what I saw about the onActivityResult data input
being null as i get a null pointer exception like they do. I'm looking for
a solution specific to my problem.
My Camera Intent:
if (v.getId() == R.id.snap) {
//start camera up, and set temp file to store image for viewing
inside the app
String identity = android.os.Build.MANUFACTURER;
Intent intent1,cameraIntent;
File f = new File(Environment.getExternalStorageDirectory(),
"photo1.jpg");
try {
if (identity.equalsIgnoreCase("samsung")) {
intent1 = new Intent("android.media.action.IMAGE_CAPTURE");
Toast.makeText(getApplicationContext(), identity,
Toast.LENGTH_LONG).show();
//File f = new File(Environment.getExternalStorageDirectory(),
"photo1.jpg");
mUri=Uri.fromFile(f);
intent1.putExtra(MediaStore.EXTRA_OUTPUT, mUri);
startActivityForResult(intent1, TAKE_PICTURE);
}
else {
cameraIntent = new Intent("android.media.action.IMAGE_CAPTURE");
Toast.makeText(getApplicationContext(), identity,
Toast.LENGTH_LONG).show();
//File f = new File(Environment.getExternalStorageDirectory(),
"photo1.jpg");
mUri=Uri.fromFile(f);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mUri);
startActivityForResult(cameraIntent, TAKE_PICTURE);
}
I know that I really don't have to have the Manufacturer part, but the
framework is there in case I have to implement a Samsung specific fix.
My save block:
else if (v.getId() == R.id.save){
//store photo in a bitmap, and set string to make folder to store
photos later on
Bitmap bitmap = mPhoto;
String root = Environment.getExternalStorageDirectory().toString();
File newDir;
if (value.isEmpty())
newDir = new File(root + "/CamExample/default_folder");
else
newDir = new File(root + "/" + "CamExample/" + value);
//if the chosen directory doesn't exist
if (!newDir.exists()) {
newDir.mkdirs();
Toast.makeText(getApplicationContext(), "folder created
successfully", Toast.LENGTH_SHORT).show();
}
//if it does exist
else {
Toast.makeText(getApplicationContext(), "directory already
exists", Toast.LENGTH_SHORT).show();
}
//image naming convention to avoid duplicate images, should look
like IMG_yyyMMdd_HHmmss.jpg
String TIMESTAMP = new SimpleDateFormat("yyyyMMdd_HHmmss",
Locale.US).format(new Date());
String photoname = "IMG_"+TIMESTAMP+".jpg";
File file1=new File (newDir, photoname);
if (file1.exists()) {
file1.delete();
}
try {
//actually create the jpeg file and put it in file1 in newDir
FileOutputStream out = new FileOutputStream(file1);
bitmap.compress(Bitmap.CompressFormat.JPEG, 70, out);
out.flush();
out.close();
((ImageView)findViewById(R.id.photo_holder)).setImageDrawable(null);
mPhoto=null;
Toast.makeText(getApplicationContext(), photoname+" has been
saved properly", Toast.LENGTH_SHORT).show();
}
catch (Exception e) {
Toast.makeText(getApplicationContext(), photoname+" has not
saved properly", Toast.LENGTH_SHORT).show();
}
}
And my onActivityResult definition:
public void onActivityResult(int requestCode, int resultCode, Intent
data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case TAKE_PICTURE:
if (resultCode == Activity.RESULT_OK) {
getContentResolver().notifyChange(mUri, null);
ContentResolver cr = getContentResolver();
try {
mPhoto =
android.provider.MediaStore.Images.Media.getBitmap(cr,
mUri);
((ImageView)findViewById(R.id.photo_holder)).setImageBitmap(mPhoto);
}
catch (Exception e) {
Toast.makeText(this, e.getMessage(),
Toast.LENGTH_SHORT).show();
}
}
}
}
And here is my logcat:
08-20 21:58:26.387: E/AndroidRuntime(10541): FATAL EXCEPTION: main
08-20 21:58:26.387: E/AndroidRuntime(10541): java.lang.RuntimeException:
Unable to resume activity
{com.example.camexample/com.example.camexample.Main}:
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null,
request=0, result=-1, data=null} to activity
{com.example.camexample/com.example.camexample.Main}:
java.lang.NullPointerException
08-20 21:58:26.387: E/AndroidRuntime(10541): at
android.app.ActivityThread.performResumeActivity(ActivityThread.java:2639)
08-20 21:58:26.387: E/AndroidRuntime(10541): at
android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2667)
08-20 21:58:26.387: E/AndroidRuntime(10541): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2140)
08-20 21:58:26.387: E/AndroidRuntime(10541): at
android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3576)
08-20 21:58:26.387: E/AndroidRuntime(10541): at
android.app.ActivityThread.access$800(ActivityThread.java:143)
08-20 21:58:26.387: E/AndroidRuntime(10541): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
08-20 21:58:26.387: E/AndroidRuntime(10541): at
android.os.Handler.dispatchMessage(Handler.java:99)
08-20 21:58:26.387: E/AndroidRuntime(10541): at
android.os.Looper.loop(Looper.java:137)
08-20 21:58:26.387: E/AndroidRuntime(10541): at
android.app.ActivityThread.main(ActivityThread.java:4950)
08-20 21:58:26.387: E/AndroidRuntime(10541): at
java.lang.reflect.Method.invokeNative(Native Method)
08-20 21:58:26.387: E/AndroidRuntime(10541): at
java.lang.reflect.Method.invoke(Method.java:511)
08-20 21:58:26.387: E/AndroidRuntime(10541): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
08-20 21:58:26.387: E/AndroidRuntime(10541): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
08-20 21:58:26.387: E/AndroidRuntime(10541): at
dalvik.system.NativeStart.main(Native Method)
08-20 21:58:26.387: E/AndroidRuntime(10541): Caused by:
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null,
request=0, result=-1, data=null} to activity
{com.example.camexample/com.example.camexample.Main}:
java.lang.NullPointerException
08-20 21:58:26.387: E/AndroidRuntime(10541): at
android.app.ActivityThread.deliverResults(ActivityThread.java:3205)
08-20 21:58:26.387: E/AndroidRuntime(10541): at
android.app.ActivityThread.performResumeActivity(ActivityThread.java:2626)
08-20 21:58:26.387: E/AndroidRuntime(10541): ... 13 more
08-20 21:58:26.387: E/AndroidRuntime(10541): Caused by:
java.lang.NullPointerException
08-20 21:58:26.387: E/AndroidRuntime(10541): at
android.os.Parcel.readException(Parcel.java:1431)
08-20 21:58:26.387: E/AndroidRuntime(10541): at
android.os.Parcel.readException(Parcel.java:1379)
08-20 21:58:26.387: E/AndroidRuntime(10541): at
android.content.IContentService$Stub$Proxy.notifyChange(IContentService.java:452)
08-20 21:58:26.387: E/AndroidRuntime(10541): at
android.content.ContentResolver.notifyChange(ContentResolver.java:1280)
08-20 21:58:26.387: E/AndroidRuntime(10541): at
android.content.ContentResolver.notifyChange(ContentResolver.java:1259)
08-20 21:58:26.387: E/AndroidRuntime(10541): at
com.example.camexample.Main.onActivityResult(Main.java:190)
08-20 21:58:26.387: E/AndroidRuntime(10541): at
android.app.Activity.dispatchActivityResult(Activity.java:5363)
08-20 21:58:26.387: E/AndroidRuntime(10541): at
android.app.ActivityThread.deliverResults(ActivityThread.java:3201)
08-20 21:58:26.387: E/AndroidRuntime(10541): ... 14 more

No comments:

Post a Comment