Comments (6)
Hi @NaikSoftware . Were u able to solve this? I got stuck on this one =/
from afilechooser.
any news on this?
from afilechooser.
Any news? I've got the same issue.
from afilechooser.
I ended up applied a quick-n-dirty fix:
FileUtils.java
public static boolean isCloudFile(Uri uri) {
return "content".equalsIgnoreCase(uri.getScheme());
}
then in my app
if (FileUtils.isCloudFile(uri)) {
path = handleRemoteFile(uri);
}
where handleRemoteFile(final Uri uri)
is
private String handleRemoteFile(final Uri uri) throws IOException {
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
int nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
int sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE);
cursor.moveToFirst();
String filename = cursor.getString(nameIndex);
long filesize = cursor.getLong(sizeIndex);
InputStream is = getContentResolver().openInputStream(uri);
File downloadedCloudFile = new File(downloads_folder, filename);
if (downloadedCloudFile.exists()) {
downloadedCloudFile.delete();
}
FileOutputStream out = new FileOutputStream(downloadedCloudFile);
IOUtils.copy(is, out);
return downloadedCloudFile.getAbsolutePath();
}
from afilechooser.
Thanks, but doesn't work for me. I have the folowing problem:
I have to caputure an image from camera, so I'm doing this:
MediaCatchActivity.java
@OnClick(R.id.sendPhoto_button)
public void sendPhotoButton(View view) {
Intent imageCaptureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mMediaUri = Util.getImageUri(this);
imageCaptureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mMediaUri);
imageCaptureIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (imageCaptureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(imageCaptureIntent, IMAGE_CAPTURE);
}
}
Util.java
public static Uri getImageUri(Context context) {
File imageFile = createImageFile(context);
if (imageFile != null) {
return FileProvider.getUriForFile(context, AUTHORITY, imageFile);
}
return null;
}
public static File createImageFile(Context context) {
return createImageFile(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), "jpg");
}
static File createMediaFile(File storageDirectory, String extension) {
// Create an mediaFile file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String fileName = extension.toUpperCase() + "_" + timeStamp + "_";
File mediaFile = null;
try {
mediaFile = File.createTempFile(
fileName, /* prefix */
"." + extension, /* suffix */
storageDirectory /* directory */
);
} catch (IOException e) {
e.printStackTrace();
}
// Save a file: path for use with ACTION_VIEW intents
//mCurrentPhotoPath = mediaFile.getAbsolutePath();
return mediaFile;
}
And this is me trying to get real path from uri
public static String getRealPathFromURI(Context context, Uri contentUri) {
Cursor cursor = null;
try {
String[] proj = { MediaStore.Images.Media.DATA };
cursor = context.getContentResolver().query(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} finally {
if (cursor != null) {
cursor.close();
}
}
}
AndroidManifest.xml
...
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.capture.image"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
...
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="images" path="Android/data/com.capture.image/files/Pictures" />
</paths>
Error
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=Intent { }} to activity {com.com.capture.image/com.capture.image.MediaCatchActivity}: java.lang.IllegalArgumentException: column '_data' does not exist. Available columns: []
from afilechooser.
I suggest to take a look at https://github.com/ArthurHub/Android-Image-Cropper or just use it as a full handle-photo-capture library. Implementing photo capture and upload from scratch is pretty hard due to android manufacturers different implementations.
from afilechooser.
Related Issues (20)
- java.lang.IllegalArgumentException: Unknown URI HOT 9
- java.lang.SecurityException: Permission Denial HOT 1
- What is the new file chooser that we should use?
- how to get fileid
- Crash in Android 10
- Hdj
- How to make FileUtils work for camera ?
- Crash when choosing pdf file in android 11
- With USB it return null instead of path. HOT 1
- is it possible to set default folder in afilechooser?
- java.lang.String java.io.File.getName() throws Null pointer
- Include in React Native HOT 1
- Recent files not working
- Not Working for Google Drive Uri HOT 4
- Result code always -1 HOT 1
- Select File - only music or gallery, I need txts
- Please add or link to this guide HOT 1
- Path return null when selecting Video From Google Photos app
- java.lang.NumberFormatException
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from afilechooser.