android - app using camera on phone keeps crashing -
i've been trying write basic apps use native android camera take picture , display picture. apps write keep crashing when try display picture. downloaded project found on internet here http://www.techrepublic.com/blog/android-app-builder/androids-camera-intent-makes-taking-pics-a-snap/ crashed on phone. i'll post code here; there wrong phone , how fix it? i'm running android 4.1.1 on galaxy s3
package com.authorwjf.camera; import java.io.file; import android.app.activity; import android.content.contentresolver; import android.content.intent; import android.graphics.bitmap; import android.graphics.matrix; import android.net.uri; import android.os.bundle; import android.os.environment; import android.provider.mediastore; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.imageview; import android.widget.toast; import com.authorwjf.camera.r; public class main extends activity implements onclicklistener { private static final int take_picture = 0; private uri muri; private bitmap mphoto; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); ((button) findviewbyid(r.id.snap)).setonclicklistener(this); ((button) findviewbyid(r.id.rotate)).setonclicklistener(this); } @override 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(); } } } } @override public void onclick(view v) { if (v.getid()== r.id.snap) { intent = new intent("android.media.action.image_capture"); file f = new file(environment.getexternalstoragedirectory(), "photo.jpg"); i.putextra(mediastore.extra_output, uri.fromfile(f)); muri = uri.fromfile(f); startactivityforresult(i, take_picture); } else { if (mphoto!=null) { matrix matrix = new matrix(); matrix.postrotate(90); mphoto = bitmap.createbitmap(mphoto , 0, 0, mphoto.getwidth(), mphoto.getheight(), matrix, true); ((imageview)findviewbyid(r.id.photo_holder)).setimagebitmap(mphoto); } } }
}
did mention permission use system camera in android manifest xml?
Comments
Post a Comment