Hello, I am very new to Android and Processing. The thing I am trying to do is. 1: App start on Android physical device with a default image. 2: User tap or press a button to choose an imag from Android device and replace the image from step 1, then, draw this selected image on Android device.
I am stuck here, since, Processing build in selectInput() does not work with Android mode, hence, I have to cook my own file chooser. Google the Android development, found something:
private static final int READ_REQUEST_CODE = 42;
/**
* Fires an intent to spin up the "file chooser" UI and select an image.
*/
public void performFileSearch() {
// ACTION_OPEN_DOCUMENT is the intent to choose a file via the system's file
// browser.
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
// Filter to only show results that can be "opened", such as a
// file (as opposed to a list of contacts or timezones)
intent.addCategory(Intent.CATEGORY_OPENABLE);
// Filter to show only images, using the image MIME data type.
// If one wanted to search for ogg vorbis files, the type would be "audio/ogg".
// To search for all documents available via installed storage providers,
// it would be "*/*".
intent.setType("image/*");
startActivityForResult(intent, READ_REQUEST_CODE);
//Uri selectedImageUri = intent.getData();
//docUri = DocumentsContract.buildDocumentUriUsingTree(selectedImageUri, DocumentsContract.getTreeDocumentId(selectedImageUri));
}
but, when I paste this into processing (3.2.3) window, and imported the suggested lib, processing still gives me errors "The global variable "ACTION_OPEN_DOCUMENT" does not exit.
further reading android dev article,
@Override
public void onActivityResult(int requestCode, int resultCode,
Intent resultData) {
// The ACTION_OPEN_DOCUMENT intent was sent with the request code
// READ_REQUEST_CODE. If the request code seen here doesn't match, it's the
// response to some other intent, and the code below shouldn't run at all.
if (requestCode == READ_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
// The document selected by the user won't be returned in the intent.
// Instead, a URI to that document will be contained in the return intent
// provided to this method as a parameter.
// Pull that URI using resultData.getData().
Uri uri = null;
if (resultData != null) {
uri = resultData.getData();
//Log.i(TAG, "Uri: " + uri.toString());
//showImage(uri);
path = uri.toString();//my edit
img = loadImage(path);// this is what I want.
}
}
}
how can I put above codes into a function processing sketch which can run on Android device?
I have been struggling with this "file chooser" for 3 days, please help.
Thank you for your help.