public class upload extends Activity {
private static final int CAMERA_REQUEST = 1888;
private ImageView imageView;
String selectedPath = "";
TextView textTargetUri;
ImageView targetImage;
InputStream is;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
this.imageView = (ImageView)this.findViewById(R.id.targetimage);
Button photoButton = (Button) this.findViewById(R.id.takeimage);
photoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
Button buttonLoadImage = (Button)findViewById(R.id.loadimage);
textTargetUri = (TextView)findViewById(R.id.targeturi);
targetImage = (ImageView)findViewById(R.id.targetimage); // result gambar ditampilkan
buttonLoadImage.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
Intent intent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 0);
}});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_REQUEST) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
}
if (resultCode == RESULT_OK){
Uri targetUri = data.getData();
textTargetUri.setText(targetUri.toString());
Bitmap bitmap;
try {
bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(targetUri));
targetImage.setImageBitmap(bitmap);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
}
I already manage to display picture from camera and browse from file
but I can't integrate the Upload function
I have read other answers, but it just get more errors..
I confused with the POST PHP things also
anyone can help? Thanks before
these are the XML
<Button
android:id="@+id/loadimage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Open Picture Gallery"
/>
<Button
android:id="@+id/takeimage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Take Picture"
/>
<TextView
android:id="@+id/targeturi"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ImageView
android:id="@+id/targetimage"
android:layout_width="fill_parent"
android:layout_height="323sp" />
<Button
android:id="@+id/uploadimage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Upload Picture" />
@VenkataKrishna seems your code is troubling me a lot XD. I keep searching and found a new solution
replace it with
add this before the try-catch
anyways, thanks for helping me :D
If you get response.getStatusLine().getStatusCode() (status code) 200 that means your image is uploaded to server successfully.