Qt 打開安卓相冊選擇圖檔并擷取圖檔的本地路徑
過程例如以下:
- 通過
Intent
打開安卓的系統相冊。
推薦使用
擷取靜态字段。QAndroidJniObject::getStaticObjectField
QAndroidJniObject action = QAndroidJniObject::getStaticObjectField( "android/content/Intent", "ACTION_GET_CONTENT", "Ljava/lang/String;");
- 使用者在系統相冊選擇到一個圖檔後,在
代碼中擷取到圖檔的C++
位址。content
- 通過查詢得出圖檔的本地路徑。
Uri uri = data.getData(); String[] proj = { MediaStore.Images.Media.DATA }; Cursor actualimagecursor = managedQuery(uri,proj,null,null,null); int actual_image_column_index = actualimagecursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); actualimagecursor.moveToFirst(); String img_path = actualimagecursor.getString(actual_image_column_index); File file = new File(img_path);
将上訴的 Java 代碼轉成 C++ 代碼。
參考 Qt and Android Gallery - MediaStore using QAndroidJniObject。
樣例下載下傳CallNativeGallery,你也能夠選擇 fork 這個項目。
參考資料:
Qt and Android Gallery - MediaStore using QAndroidJniObject
HOW TO OPEN ANDROID IMAGE GALLERY IN QT
android實作Uri擷取真實路徑轉換成File的方法
Thread: Converting QAndroidJniObject to jobjectArray: most elements are NULL!
How to return an array from JNI to Java?
轉載于:https://www.cnblogs.com/llguanli/p/7280460.html