mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-03 06:35:08 -04:00
Get real file path from Uri
This commit is contained in:
parent
2404696003
commit
2d9f062c27
1 changed files with 16 additions and 3 deletions
|
@ -22,6 +22,7 @@ import android.app.ActivityManager;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.database.Cursor;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
@ -139,16 +140,28 @@ public class RetroShareQmlActivity extends QtActivity
|
||||||
selectedImageUri = data == null ? null : data.getData();
|
selectedImageUri = data == null ? null : data.getData();
|
||||||
}
|
}
|
||||||
|
|
||||||
String uri = selectedImageUri.toString();
|
String uri = getRealPathFromURI(selectedImageUri);
|
||||||
if (uri != null)
|
if (uri != null)
|
||||||
{
|
{
|
||||||
Log.i("RetroShareQmlActivity", "Image uri found!" + uri);
|
Log.i("RetroShareQmlActivity", "Image path from uri found!" + uri);
|
||||||
NativeCalls.notifyIntentUri(uri);
|
NativeCalls.notifyIntentUri("//file"+uri); // Add the authority for get it on qml code
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getRealPathFromURI(Uri uri) {
|
||||||
|
String[] projection = { MediaStore.Images.Media.DATA };
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
Cursor cursor = managedQuery(uri, projection, null, null, null);
|
||||||
|
int column_index = cursor
|
||||||
|
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
|
||||||
|
cursor.moveToFirst();
|
||||||
|
String result = cursor.getString(column_index);
|
||||||
|
cursor.close();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue