I've googled a lot but it doesn't work. I found a lot of sites with information but by all the sites my app crashed. The picture that I want to open is: "lastfile.png". It is stored in internal storage so I open it with openFileInput("lastfile.png");
I do it in in an AsyncTask.
This is my code so far:
class PostTask extends AsyncTask<String, String, String>{
@Override
protected String doInBackground(String... uri) {
if(picture == null) {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response;
String responseString = null;
try {
response = httpclient.execute(new HttpGet(uri[0]));
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
out.close();
responseString = out.toString();
} else{
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
} catch (ClientProtocolException e) {
Toast.makeText(AddStoryActivity.this, getResources().getString(R.string.error), Toast.LENGTH_LONG).show();
e.printStackTrace();
} catch (IOException e) {
Toast.makeText(AddStoryActivity.this, getResources().getString(R.string.error), Toast.LENGTH_LONG).show();
e.printStackTrace();
}
return responseString;
} else {
/* IMAGE UPLOAD */
}
return "";
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
progress.cancel();
Toast.makeText(getApplicationContext(), result, Toast.LENGTH_LONG).show();
}
}