How to send user to another App and return the selected item

Hi all, I use FuseJS/InterApp module, send user to another app gallery image by using this

var InterApp = require(“FuseJS/InterApp”); InterApp.launchUri(“content://media/external/images/media”);

I tested it and it actually works that it can send to gallery image app, then I choose my favorite image, but it didn’t send me back to my app, so how can I turn back to my app and save the path image I’ve selected.

Devices: Android

Thank you.

Hi, the InterApp module does not support this as iOS does not have the concept of Intents in the way android does.

However we do have an undocumented mechanism for this. It is not publically exposed yet as it is only available through Uno, only works for android and hasn’t gone through the kind of testing we require for recommending people use it.

So if you are feeling crazy and don’t need support you can see this gist for an example of creating and starting an Intent using foreign code: https://gist.github.com/cbaggers/489e2533570f246e32157e0018cab95c

Thanks for your help. But I try to launch your code https://gist.github.com/cbaggers/489e2533570f246e32157e0018cab95c I’ve got the error: ActivityForResult.unoproj: E0100: Package ‘Android.ActivityRequest’ was not found

I’m using fusetools version 0.20.2

I’m sorry I seem to have posted an older test. I have updated the gist now.

Thanks for your patience

I’m newbie to fusetools, I still got error I don’t know how to resolve it now. I tried to update and launch your code again Here’s the error I’ve got

Main.ux.uno(26.13): E3129: No overloads of ‘StartActivity’ matches the argument list (object,) Candidates are: Android.ActivityUtils.StartActivity(object) Android.ActivityUtils.StartActivity(object,Android.ActivityResultCallback,[object]) k:\Project\testfuse\sampleActivityResult\Main.ux.uno(26,14,26,60): Error E3129: No overloads of ‘StartActivity’ matches the argument list (object,) Candidates are: Android.ActivityUtils.StartActivity(object) Android.ActivityUtils.StartActivity(object,Android.ActivityResultCallback,[object]) build\Local\Preview6\cache\Main.g.uno(27.58): E3102: There is no identifier named ‘ClickPlay’ accessible in this scope. Did you mean ‘ClickPlay’ (as in ‘MainView.ClickPlay(object,Uno.EventArgs)’)? k:\Project\testfuse\sampleActivityResult\build\Local\Preview6\cache\Main.g.uno(27,59,27,68): Error E3102: There is no identifier named ‘ClickPlay’ accessible in this scope. Did you mean ‘ClickPlay’ (as in ‘MainView.ClickPlay(object,Uno.EventArgs)’)?

I want to ask you another question, I use foregin code to handle the same problem above: The code with .uno file like this

[Foreign(Language.Java)]
static extern(Android) void LogNativeCode(string message)
@{
    int PICK_CONTACT_REQUEST = 1;
    Intent intent=new Intent(Intent.ACTION_PICK);  
    intent.setData(Uri.parse("content://media/external/images/media"));  
    Activity.getRootActivity().startActivityForResult(intent, PICK_CONTACT_REQUEST);
@}

It works, I want to impletement the onActivityReuslt function in order to get data after user select the image, Here is the code I got on https://developer.android.com/reference/android/app/Activity.html

public class MyActivity extends Activity

{

 static final int PICK_CONTACT_REQUEST = 0;

 public boolean onKeyDown(int keyCode, KeyEvent event) {
     if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
         // When the user center presses, let them pick a contact.
         startActivityForResult(
             new Intent(Intent.ACTION_PICK,
             new Uri("content://contacts")),
             PICK_CONTACT_REQUEST);
        return true;
     }
     return false;
 }

 protected void onActivityResult(int requestCode, int resultCode,
         Intent data) {
     if (requestCode == PICK_CONTACT_REQUEST) {
         if (resultCode == RESULT_OK) {
             // A contact was picked.  Here we will just display it
             // to the user.
             startActivity(new Intent(Intent.ACTION_VIEW, data));
         }
     }
 }

}

How can I implement onActivityResult in uno? Thank you for help.

Finally I’ve resolved my problem, here is the sample code for running another application like as image and pick a image from there and return to the app. Or you can access to this link to get details of the code: http://pastebin.com/fr3kwhPt

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; } }

Sorry for the slow reply, I have been out the country for a couple of days. Great to see you worked it all out!