mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Open image camera or gallery selector from main QtActivity
This commit is contained in:
parent
3b092f7fb6
commit
5838b13043
@ -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());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -19,10 +19,9 @@ public slots:
|
||||
qDebug() << "Starting image picker intent";
|
||||
|
||||
#ifdef __ANDROID__
|
||||
QAndroidJniObject::callStaticMethod<void>(
|
||||
"org/retroshare/android/qml_app/RetroshareImagePicker",
|
||||
"imagePickerIntent",
|
||||
"()Landroid/content/Intent;" );
|
||||
QtAndroid::androidActivity().callMethod<void>(
|
||||
"openImagePicker",
|
||||
"()V" );
|
||||
#endif // __ANDROID__
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user