Skip to content

Instantly share code, notes, and snippets.

@bansalayush
Created March 7, 2017 06:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bansalayush/fd5a298e61b7feb283c1322546aadd4c to your computer and use it in GitHub Desktop.
Save bansalayush/fd5a298e61b7feb283c1322546aadd4c to your computer and use it in GitHub Desktop.
Get size of selected image in bytes
private void showFileChooser() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), 2);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 2 && resultCode == RESULT_OK)
{
String path = data.getData().toString();
try {
f = new File(new URI(path));
} catch (URISyntaxException e) {
e.printStackTrace();
}
System.out.println("File size in bytes"+f.length());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment