android - ImageView not showing image in activity -
i made app use default camera take photo displays on image view.problem is, image not show in image view. tried many ways no solution.
mainactivity.java:
public class mainactivity extends activity { private static final int activity_start_camera_app = 0; static final int request_image_capture = 1; private imageview mphotocapturedimageview; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); mphotocapturedimageview = (imageview) findviewbyid(r.id.capturephotoimageview); } public void takephoto(view view){ intent callcameraapplicationintent = new intent(); callcameraapplicationintent.setaction(mediastore.action_image_capture); startactivityforresult(callcameraapplicationintent, activity_start_camera_app); } protected void onactivityresult(int requestcode, int resultcode, intent data) { toast.maketext(this, "picture taken sucessfully!", toast.length_short).show(); if (requestcode == request_image_capture && resultcode == result_ok) { bundle extras = data.getextras(); bitmap imagebitmap = (bitmap) extras.get("data"); mphotocapturedimageview.setimagebitmap(imagebitmap); } } }
main_activity.xml:
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.constraintlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.taufiq.ocrdemo.mainactivity"> <imageview android:id="@+id/capturephotoimageview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/photobutton" android:layout_marginbottom="19dp" android:layout_marginend="43dp" android:layout_marginleft="43dp" android:layout_marginright="43dp" android:layout_marginstart="43dp" android:layout_margintop="16dp" android:contentdescription="@string/preview" android:minheight="300dp" app:layout_constraintbottom_totopof="@+id/photobutton" app:layout_constraintleft_toleftof="parent" app:layout_constraintright_torightof="parent" app:layout_constrainttop_totopof="parent" tools:ignore="missingconstraints" tools:layout_constraintbottom_creator="1" tools:layout_constraintleft_creator="1" tools:layout_constraintright_creator="1" tools:layout_constrainttop_creator="1" tools:minheight="300dp" /> <button android:id="@+id/photobutton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onclick="takephoto" android:text="@string/capture_photo" android:layout_weight="1" tools:ignore="missingconstraints" tools:layout_constraintright_creator="1" tools:layout_constraintbottom_creator="1" app:layout_constraintbottom_tobottomof="parent" app:layout_constraintright_torightof="parent" tools:layout_constraintleft_creator="1" android:layout_marginbottom="27dp" app:layout_constraintleft_toleftof="parent" /> </android.support.constraint.constraintlayout>
problem here :
if (requestcode == request_image_capture && resultcode == result_ok) {
you starting activity requestcode activity_start_camera_app
startactivityforresult(callcameraapplicationintent, activity_start_camera_app);
so need modify if condition like:
if (requestcode == activity_start_camera_app && resultcode == result_ok) {
Comments
Post a Comment