- Forum-Beiträge: 9
17.06.2014, 19:53:19 via Website
17.06.2014 19:53:19 via Website
Moin,
ich mache moment eine App wo ich per buttondruck ein Bild aus der Galerie aussuchen kann oder die Kamera öffnen kann.
Anschließend soll das Bild in ImageView gezeigt werden und per druck auf den uploadbutton auf meinen server hochgeladen werden.
Problem ist das ich den Pfad zu dem Bild nicht bekomme um es in die Uploadactivity zu übertragen.
Hier einmal mein code:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == 1) {
File f = new File(Environment.getExternalStorageDirectory().toString());
for (File temp : f.listFiles()) {
if (temp.getName().equals("temp.jpg") {
f = temp;
break;
}
}
try {
Bitmap bitmap;
BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
bitmap = BitmapFactory.decodeFile(f.getAbsolutePath(),
bitmapOptions);
viewImage.setImageBitmap(bitmap);
String path = android.os.Environment
.getExternalStorageDirectory()
+ File.separator
+ "Phoenix" + File.separator + "default";
f.delete();
OutputStream outFile = null;
File file = new File(path, String.valueOf(System.currentTimeMillis()) + ".jpg"
try {
outFile = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 85, outFile);
outFile.flush();
outFile.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
} else if (requestCode == 2) {
Uri selectedImage = data.getData();
String[] filePath = { MediaStore.Images.Media.DATA };
Cursor c = getContentResolver().query(selectedImage,filePath, null, null, null);
c.moveToFirst();
int columnIndex = c.getColumnIndex(filePath[0]);
String picturePath = c.getString(columnIndex);
c.close();
Bitmap thumbnail = (BitmapFactory.decodeFile(picturePath));
Log.w("path of image from gallery......******************.........", picturePath+""
viewImage.setImageBitmap(thumbnail);
}
}
}
}
zur upload klasse:
imageUrl = "picturePath";
uploadUrl = "htp://10.0.2.2/upoadandroid/upload.php";
findViewById(R.id.senden).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String responce = new sendensave().uploadFile(uploadUrl, imageUrl);
Toast.makeText(SendenActivity.this, responce,Toast.LENGTH_SHORT).show();
}
});
}
Problem ist jetzt, dass ich jetzt entweder einen pfad von der Gelerie oder von der Cam habe.
Wie übergebe ich jetzt den Galerie Pfad ODER den Image Pfad von der Cam, je nach dem was für eine aktion ausgeführt wird?
Ich würde mich wahnsinnig über eure Hilfe freuen!
Liebe Grüße!