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();
}
}
}
}
我已經設法從相機顯示圖片和文件
瀏覽,但我不能整合上傳功能
我看過其他的答案,但它只是讓更多的錯誤..
我混淆了POST PHP的東西也
任何人都可以幫忙嗎?由於之前
上傳的ImageView到服務器
這些都是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" />
也許這可以幫助你: http://stackoverflow.com/questions/7163311/android-file-upload-using-http-put – Andreas 2012-02-14 06:24:12