Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Fuse.Scripting;
- using Fuse;
- using Android;
- using Android.ActivityUtils;
- using Uno.Compiler.ExportTargetInterop;
- [extern(Android) ForeignInclude(Language.Java,
- "com.fuse.Activity",
- "android.content.Intent",
- "android.net.Uri",
- "android.os.Bundle",
- "android.provider.MediaStore",
- "android.database.Cursor",
- "android.content.Context",
- "android.util.Log",
- "java.io.File")]
- public class browsePhotoAPI : NativeModule
- {
- string pathFile;
- public browsePhotoAPI()
- {
- AddMember( new NativeFunction("activeBrowsePhoto", (NativeCallback) activeBrowsePhoto));
- AddMember( new NativeFunction("getPathImage", (NativeCallback) getPathImage));
- }
- object activeBrowsePhoto(Context c, object[] args)
- {
- pathFile = "nothing";
- var intent = makeMyIntent();
- if (intent!=null)
- {
- ActivityUtils.StartActivity(intent, OnResult);
- while (pathFile == "nothing") {
- }
- } else {
- debug_log "Didnt make intent. boooo";
- }
- debug_log "ok now";
- return null;
- }
- object getPathImage(Context c, object[] args)
- {
- return pathFile;
- }
- void setPathImage(string file)
- {
- debug_log "This is setPath:";
- debug_log pathFile;
- pathFile = file;
- }
- [Foreign(Language.Java)]
- extern(android) void OnResult(int resultCode, Java.Object intent, object info)
- @{
- String TAG = "My Tag";
- Log.d(TAG, "what what ");
- Intent i = (Intent) intent;
- Log.d(TAG, i.getData().getPath());
- Uri u = i.getData();
- String result;
- Cursor cursor = Activity.getRootActivity().getContentResolver().query(u, null, null, null, null);
- if (cursor == null) { // Source is Dropbox or other similar local file path
- result = u.getPath();
- } else {
- cursor.moveToFirst();
- int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
- result = cursor.getString(idx);
- cursor.close();
- }
- Log.d(TAG, result);
- @{browsePhotoAPI:Of(_this).setPathImage(string):Call(result)};
- @}
- [Foreign(Language.Java)]
- static extern(android) Java.Object makeMyIntent()
- @{
- try {
- int PICK_CONTACT_REQUEST = 1;
- Intent intent=new Intent(Intent.ACTION_PICK);
- intent.setData(Uri.parse("content://media/external/images/media"));
- return intent;
- } catch (Exception ex) {
- return null;
- }
- @}
- extern(!android) void OnResult(int resultCode, object intent, object info)
- {
- }
- static extern(!android) object makeMyIntent()
- {
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement