Created
September 7, 2014 04:42
-
-
Save ejcer/946ffc3fbd5c44aa3d01 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.noteworthy; | |
import java.io.ByteArrayInputStream; | |
import java.io.ByteArrayOutputStream; | |
import java.io.File; | |
import java.util.ArrayList; | |
import java.util.List; | |
import android.app.Activity; | |
import android.content.Intent; | |
import android.database.Cursor; | |
import android.graphics.Bitmap; | |
import android.graphics.Bitmap.CompressFormat; | |
import android.net.Uri; | |
import android.os.Bundle; | |
import android.provider.MediaStore; | |
import android.support.v4.content.CursorLoader; | |
import android.util.Base64; | |
import android.util.Log; | |
import com.cleverua.android.post.MultipartPost; | |
import com.cleverua.android.post.PostParameter; | |
import com.github.kevinsawicki.http.*; | |
import com.github.kevinsawicki.http.HttpRequest.HttpRequestException; | |
public class PhotoActivity extends Activity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_photo); | |
dispatchTakePictureIntent();//must be put in with a specific method, will repeat in oncreate | |
} | |
private void dispatchTakePictureIntent() { | |
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | |
if (takePictureIntent.resolveActivity(getPackageManager()) != null) { | |
startActivityForResult(takePictureIntent, 1); | |
} | |
} | |
@Override | |
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
super.onActivityResult(requestCode, resultCode, data); | |
postToServer(data.getData()); | |
} | |
private String getPath(Uri uri) | |
{ | |
String[] data = { MediaStore.Images.Media.DATA }; | |
CursorLoader loader = new CursorLoader(getBaseContext(), uri, data, null, null, null); | |
Cursor cursor = loader.loadInBackground(); | |
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); | |
cursor.moveToFirst(); | |
return cursor.getString(column_index); | |
} | |
private void postToServer(final Uri input) | |
{ | |
final String loc = getPath(input); | |
Thread thread = new Thread(new Runnable(){ | |
@Override | |
public void run(){ | |
List<PostParameter> params = new ArrayList<PostParameter>(); | |
params.add(new PostParameter<File>("file", new File(loc))); | |
MultipartPost post = new MultipartPost(params); | |
try { | |
post.send("http://noteworthy.cloudapp.net"); | |
} catch (Exception e) { | |
Log.d("fuckAndroid", e.toString()); | |
} | |
} | |
}); | |
thread.start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment