diff --git a/retroshare-qml-app/src/android/src/org/retroshare/android/qml_app/RetroShareQmlActivity.java b/retroshare-qml-app/src/android/src/org/retroshare/android/qml_app/RetroShareQmlActivity.java index 389ee1448..a14d69f19 100644 --- a/retroshare-qml-app/src/android/src/org/retroshare/android/qml_app/RetroShareQmlActivity.java +++ b/retroshare-qml-app/src/android/src/org/retroshare/android/qml_app/RetroShareQmlActivity.java @@ -19,17 +19,24 @@ package org.retroshare.android.qml_app; import android.app.ActivityManager; +import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.provider.MediaStore; import android.util.Log; +import android.net.Uri; + import org.qtproject.qt5.android.bindings.QtActivity; import org.retroshare.android.qml_app.jni.NativeCalls; public class RetroShareQmlActivity extends QtActivity { + + static final int PICK_PHOTO = 1; + @Override public void onCreate(Bundle savedInstanceState) { @@ -73,4 +80,67 @@ public class RetroShareQmlActivity extends QtActivity return true; return false; } + + private Uri capturedImageURI; + + public void openImagePicker() + { + Log.i("RetroShareQmlActivity", "openImagePicker()"); + + Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); + pickIntent.setType("image/*"); + + ContentValues values = new ContentValues(); + values.put(MediaStore.Images.Media.TITLE, "Retroshare Avatar"); + capturedImageURI = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); + Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + takePicture.putExtra(MediaStore.EXTRA_OUTPUT, capturedImageURI); + + Intent chooserIntent = Intent.createChooser(pickIntent, "Select Image"); + chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {takePicture}); + + startActivityForResult( chooserIntent, PICK_PHOTO); + }; + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + + Log.i("RetroShareQmlActivity", "onActivityResult()" + String.valueOf(requestCode)); + + if (resultCode == RESULT_OK) + { + if (requestCode == PICK_PHOTO) + { + final boolean isCamera; + + if (data == null) + { + isCamera = true; + } + else + { + final String action = data.getAction(); + if (action == null) { + isCamera = false; + } else { + isCamera = action.equals(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); + } + } + + Uri selectedImageUri; + if (isCamera) { + selectedImageUri = capturedImageURI; + } else { + selectedImageUri = data == null ? null : data.getData(); + } + + Log.i("RetroShareQmlActivity", "Image uri found!" + selectedImageUri.toString()); + + } + } + } + + + + + } diff --git a/retroshare-qml-app/src/androidimagepicker.h b/retroshare-qml-app/src/androidimagepicker.h index d30026701..d6d3437c1 100644 --- a/retroshare-qml-app/src/androidimagepicker.h +++ b/retroshare-qml-app/src/androidimagepicker.h @@ -19,10 +19,9 @@ public slots: qDebug() << "Starting image picker intent"; #ifdef __ANDROID__ - QAndroidJniObject::callStaticMethod( - "org/retroshare/android/qml_app/RetroshareImagePicker", - "imagePickerIntent", - "()Landroid/content/Intent;" ); + QtAndroid::androidActivity().callMethod( + "openImagePicker", + "()V" ); #endif // __ANDROID__ } };