mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Support for content URIs that do not report their size
Also brought back ACTION_GET_CONTENT - people should pick from wherever they want!
This commit is contained in:
parent
399609a9d3
commit
23af3c16ce
2 changed files with 15 additions and 2 deletions
|
|
@ -124,6 +124,15 @@ public class UploadService extends IntentService {
|
|||
return cursor.getString(column_index);
|
||||
}
|
||||
|
||||
private long countBytes(InputStream stream) throws IOException {
|
||||
long count = 0;
|
||||
BufferedInputStream bis = new BufferedInputStream(stream);
|
||||
while(bis.read() != -1) {
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
private Contribution mediaFromIntent(Intent intent) {
|
||||
Bundle extras = intent.getExtras();
|
||||
Uri mediaUri = (Uri) extras.getParcelable(EXTRA_MEDIA_URI);
|
||||
|
|
@ -136,7 +145,11 @@ public class UploadService extends IntentService {
|
|||
Long length = null;
|
||||
try {
|
||||
length = this.getContentResolver().openAssetFileDescriptor(mediaUri, "r").getLength();
|
||||
} catch(FileNotFoundException e) {
|
||||
if(length == -1) {
|
||||
// Let us find out the long way!
|
||||
length = countBytes(this.getContentResolver().openInputStream(mediaUri));
|
||||
}
|
||||
} catch(IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -245,7 +245,7 @@ public class ContributionsActivity extends AuthenticatedActivity implements Load
|
|||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch(item.getItemId()) {
|
||||
case R.id.menu_from_gallery:
|
||||
Intent pickImageIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
|
||||
Intent pickImageIntent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
pickImageIntent.setType("image/*");
|
||||
startActivityForResult(pickImageIntent, SELECT_FROM_GALLERY);
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue