After a bit of research throughout some questions here (and I upvoted the ones that were especially useful), and in various coding places and quite a bit of late-night-self-coding-education, I have it working now. Below is the working code snippet:
@Override
public void onClick(View v) {
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
//intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//super.onActivityResult(requestCode, resultCode, data);
if(requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE && resultCode == RESULT_OK) {
final ContentResolver cr = getContentResolver();
final String[] p1 = new String[] {
MediaStore.Images.ImageColumns._ID,
MediaStore.Images.ImageColumns.DATE_TAKEN
};
Cursor c1 = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, p1, null, null, p1[1] + " DESC");
if ( c1.moveToFirst() ) {
String uristringpic = "content://media/external/images/media/" +c1.getInt(0);
Uri uri = Uri.parse(uristringpic);
try {
Bitmap bm = android.provider.MediaStore.Images.Media.getBitmap(cr, uri);
int w = bm.getWidth();
int h = bm.getHeight();
Bitmap bmg = Bitmap.createBitmap(w, h, bm.getConfig());
for(int x = 0; x < w; ++x) {
for(int y = 0; y < h; ++y) {
int pixel = bm.getPixel(x, y);
a = Color.alpha(pixel);
r = Color.red(pixel);
g = Color.green(pixel);
b = Color.blue(pixel);
r = g = b = (int)(0.299 * r + 0.587 * g + 0.114 * b);
bmg.setPixel(x, y, Color.argb(a, r, g, b));
grey = 0.299 * r + 0.587 * g + 0.114 * b;
if(grey > 20) {
sum += grey;
count++;
}
//int grey = (r + g + b) / 3;
}
}
ImageView imageView = (ImageView) findViewById(R.id.ImageView);
imageView.setImageBitmap(bmg);
//Toast.makeText(MainActivity.this, String.valueOf(Y), Toast.LENGTH_LONG).show();
//Toast.makeText(this, uri.toString(),Toast.LENGTH_LONG).show();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(this, "Failed to load", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(this, "Failed to load", Toast.LENGTH_SHORT).show();
}
//Toast.makeText(this, "newuri " + uri, Toast.LENGTH_LONG).show();
} c1.close();
//Toast.makeText(this, "Image saved to:\n" + data.getData(), Toast.LENGTH_LONG).show();
double Y = sum / count;