How to launch a native mobile app

How to launch a native mobile app

  

Hi guys,

 

I have a problem for open the native apps and sent a parameter, i have a code in mobile native android. like this : 

Intent intent = getPackageManager().getLaunchIntentForPackage("com.startapss");

if (intent == null) {

intent = new Intent(Intent.ACTION_VIEW);

intent.setData(Uri.parse("market://details?id=" + "com.startapss.goodapps"));

}

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

intent.putExtra("com.startapss.intent.TransactionArgument.type_id", "0");

intent.putExtra("com.startapss.intent.TransactionArgument.amount", "20000");

...

setResult(Activity.RESULT_OK, intent);

startActivity(intent);


Can you help me, how to convert this code in JS for implement in Outsystems?

Thanks & Regards,

Imas 

i have also same problem

Hi Imas,

You can use the JS tool in an client action flow to execute custom JavaScript code on your device (like the one you have there) but I don't see any parameters there?

Hi Jorge,


I think here, show the data based on the id we give

Can you help me for the implement in JS ? 


Thanks 

Imas 

Mind you, I have not tested this now, so I may have forgotten some detail, but try adding an input parameter to your JS node (call it Id for instance), and in your JavaScript replace "com.startapps.goodapps" with $parameters.Id

Hope this helps. Further information about using JavaScript within your client actions can be found here.

Hi Jorge,


Thanks for your replay,

But the main problem is how I launch other apps with js? And send the parameters 


Thanks 

Imas 

I don't know how to launch native apps in JavaScript, I thought that was what the JS code you posted was for?...

My answer was how can you call *that* code from a client action. You might want to look into this Cordova plugin. Appears to do what you need...

Hi,

You can try this component: https://www.outsystems.com/forge/component-discussions/2622/AppLauncherPlugin

Just three actions. You can use CanLaunch to check if the app can be launched and Launch to launch it.
Very simple for now, accepts just an URI (like "fb://" to launch facebook).

Cheers,
Eduardo Jauch 


Hi Eduardo,


How to send parameters from my application to the native app with the package name as image below


Thanks,

Imas Deny 

Hello Imas,

I still have to add the possibility to use intent (this works only on Android).

Provably I'll do it tonight. I'll let you know.

Cheers

Eduardo Jauch

Hi Imas,

You can learn how to utilize cordova plugin to access native device capabilities here:
https://success.outsystems.com/Documentation/10/Extensibility_and_Integration/Mobile_Plugins/Create_a_Plugin_to_Use_Mobile_Capabilities_in_Your_Application


Simply put, just open Extensibility Configuration in your module's Advanced property, here's one example:

How to use it in Javascript, you can read it directly from the github page.


For example this cordova plugin: https://github.com/nchutchind/cordova-plugin-app-launcher

After you add that to Extensibility Configuration, you can execure Javascript from Client Action.

Based on documentation provided on that github link:

Launch MxPlayer Free with Extras for specific videos from the sdcard, specific titles, and starting at 3 seconds in (Android)

var sdcard = "file:///sdcard/";
var file1 = sdcard + "video1.mp4", file2 = sdcard + "video2.mp4";

window.plugins.launcher.launch({
packageName:'com.mxtech.videoplayer.ad',
uri:file1,
dataType:'video/*'
extras: [
{"name":"video_list", "value":[file1,file2], "dataType":"ParcelableArray", "paType":"Uri"},
{"name":"video_list.name", "value":["Awesome Video","Sweet Title"], "dataType":"StringArray"},
{"name":"position", "value":3000, "dataType":"int"}
]
}, successCallback, errorCallback);


You can put parameter in the extras json.

It's simple right?


But a great Outsystems component/plugin like App Launcher Plugin made by Eduardo Jauch, will transform all that highcode to lowcode :)

Hi Harlin & Eduardo

I tried to implement the above code, but I did not manage to send the parameters, can you help me? maybe my implementation is wrong


Thanks,

Imas 

I am no expert in Cordova/Native Android, but here's my two cents:

1. Try to put only "type_id" / "amount" in name, like the example on the github page I quoted above.

2. In value, try removing the enclosing double quote, eg: "value":$parameter.value, or test first using hardcoded value.

3. Was the called app successfully launch? If not, make sure you generate the APK first, then reinstall it to your Android device again.

Hi Harlin, 


I already to implement your solution 1, 2, but the result is the same

yes I called app successfully launch


can you help me? 

 
Thanks,

Ima

Install Logcat [NO ROOT] from Playstore.

Connect it to your computer with USB cable, and enable USB debugging in Setting > Developer Options.


You need to have Android SDK installed on your computer.

Run this command: 

adb tcpip 5555


Now you can see your Android console logs using this app.

Maybe you can find some errors or hints there...

You can search for package name.



Solution

Hello imas,

Sorry for the delay. I'm still learning to work with plugins for mobile :)
I uploaded a new version of the plugin (0.2.0).

There are some changes. Now it is possible to pass a JSON (as string) with what you need there. Please, see examples in the plugin version 0.2.0 details.

It is also possible to use the LaunchWithData and CanLaunchWithData, where the "WithData" (poor name, I'll probably will have to change this in the future) means that you can pass the information to launch the application using a structure.

For what you told me, I think you will not have problems to put it to work. If it does not work, we have to investigate more. I tested to launch Whatsapp with an action (SEND) and passing as argument a string, and it worked.

Cheers,
Eduardo Jauch

Solution

Attached is a little example on how to use this plugin.

Cheers,
Eduardo Jauch

Hi Eduardo,


Thanks for help, i will try it :)


Cheers,

Imas Deny  

Hi Eduardo & Harlin 


I have a problem where I still can't send parameters to native app, can we debug to see the parameters sent or not?


harlin is there any way other than Logcat [NO ROOT] above?


Thanks,

Imas 

imas deny wrote:

Hi Eduardo & Harlin 


I have a problem where I still can't send parameters to native app, can we debug to see the parameters sent or not?


harlin is there any way other than Logcat [NO ROOT] above?


Thanks,

Imas 

Hi imas, 

You are not defining an action. This way, I don't think the application will know what to do with the data without the action...
Can you share the intent filter definition of the target application? It should be something like this:

<intent-filter>
  <action android:name="android.intent.action.SEND">
  </action>
  <category android:name="android.intent.category.DEFAULT">
  </category>
  <data android:mimeType="audio/*">
  </data>
  <data android:mimeType="video/*">
  </data>
  <data android:mimeType="image/*">
  </data>
  <data android:mimeType="text/plain">
  </data>
  <data android:mimeType="text/x-vcard">
  </data>
</intent-filter>

The above intent filter is for whatsapp. It's in its manifest.xml file.
It tells the android that if someone calls an INTENT with the ACTION SEND, with one of the dataType defined in the DATA elements, it will appear in the selection box. If the intent specify the com.whatsapp, than the android will call it automatically.

So, I would say that what is missing in your intent is the action. Probably a SEND or SENDTO, but only knowing the manifest intent filters to be sure.

In the case of whatsapp I call this intent like in the example, using "com.whatsapp/android.intent.action.SEND".

Cheers,
Eduardo Jauch

Hi Eduardo,


So in conclusion, if I want to send a parameter there must be an action, right?


Thanks,

Imas Deny 

imas deny wrote:

Hi Eduardo,


So in conclusion, if I want to send a parameter there must be an action, right?


Thanks,

Imas Deny 

Hum...

I'm not an expert in android programming, but with "implicit" intents, that is what we are doing here, I would say that yes, you need an action. Otherwise, you will just open the application, without telling it what to do, and it will ignore the parameters.

Cheers,
Eduardo Jauch


Hi Eduardo,


I have applied the action as shown below


but it does not work and exits error "Activity not found for package name"


Thanks,

Imas Deny 


Hi imas,

This means that the package com.smartpesa.visionet.dev does not have a filter for both the action you provided and the data type you provided (text/plain).

Can you share the intent filter that implements this action?

Cheers,
Eduardo Jauch

Hi Eduardo,


Sorry eduardo, What do you mean "intent filter" ?


Thanks,

Imas Deny 

Hi imas,

For an application to be launched by another through intents, it must inform the os (android) that it is available to be launched on certain conditions. It does so through the intent filters. 

For example, the Whatsapp provide many intent filters. One of them, that I used as example some posts above, tells android that whatsapp is available to be launched if the action is SEND and the data type is one of those, like text/plain.

If, in the intent request, the data type is missing, or the action is not SEND, that filter will not match the request and the activity that is executed for that filter is not available.

If you can launch the package, but it fails with activity not found, means that package does not have an intent filter with the action you defined and the data type you defined.

So, now I ask you. How do you know that you must use that action (that the action exists) and that the activity for that action accepts a data type text/plain?

You need to ask that information to who created the package. Ask them about the intent filters, so you know what to use in the request.

Cheers,

Eduardo Jauch

Hi Eduardo,


when I run can launch using the existing package the result is successful, like the picture below:


Here's the intent filter in our visionet application:

<intent-filter>

<action android:name="com.smartpesa.intent.action.TRANSACT" />

<data android:mimeType="text/plain"/>

<category android:name="android.intent.category.DEFAULT" />

</intent-filter>


here I attach my .oml, while I ask them about intent filters


Thanks,

Imas Deny 


Hello imas,

Just a question.
The intent filter you showed is defined by the application you are calling, or the application you are developing?

In any case, I took a look in your code.
There are some things strange.

1. In this JSON Launch2:

"{""packageName"":""com.smartpesa.visionet.dev/com.smartpesa.visionet.dev.intent.action.TRANSACT"",
 ""dataType"":""text/plain"", 
""extras"":[
{""name"":""android.intent.extra.TEXT"",""value"":""500"", ""dataType"":""String""}]}"

You are passing a android.intent.extra.TEXT to the application you are calling.
But are your application READING this value? You need to pass the parameters that your application is expecting (I remember something differently from your first posts).

Regarding the activity not found, you really need to check with them about the filters, if the intent filter you showed is not in the application. If one intent filter for the application is the one you showed, than it should work, even without the extras.

The branch where you call using the data structure has the same problem.

I would expect that the code in the Launch (JSON string) to work... 

2. To test if the ACTION really exists, add an Action that use the CanLaunch passing the action NAME. Use com.smartpesa.visionet.dev.intent.action.TRANSACT in the actionName property. Leave everything else (including packageName, dataType and extras) empty.

If the action exists and is registered, it should return TRUE.

Cheers,
Eduardo Jauch

P.S. The CanLaunch is successful because it is stripping out the activity name and looking only to the package name. :)

Also, from your first post, the code to launch that app would be like this:

Intent intent = getPackageManager().getLaunchIntentForPackage("com.startapss");
if (intent == null) {
  intent = new Intent(Intent.ACTION_VIEW);
  intent.setData(Uri.parse("market://details?id=" + "com.startapss.goodapps"));
}

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("com.startapss.intent.TransactionArgument.type_id", "0");
intent.putExtra("com.startapss.intent.TransactionArgument.amount", "20000");

setResult(Activity.RESULT_OK, intent);
startActivity(intent);

The JSON to launch using the plugin would be like this:

"{""packageName"":""com.startapss/android.intent.action.VIEW"",
  ""flags"":268435456, 
  ""extras"":[
        {""name"":""com.startapss.intent.TransactionArgument.type_id"",
         ""value"":""0"", 
         ""dataType"":""String""}, 
        {""name"":""com.startapss.intent.TransactionArgument.amount"",
         ""value"":""20000"", 
         ""dataType"":""String""}]
}"

In THINK it should work (not so sure about the FLAG, as I got the numerical value from the android site, and the extras, as they seem to be integers/decimal, but you are passing as strings in the original code.

Note that this action does not require any dataType.

Cheers,
Eduardo Jauch

Eduardo Jauch wrote:

P.S. The CanLaunch is successful because it is stripping out the activity name and looking only to the package name. :)

So i can't figure out my action is running or not?


Hi,

If in the CanLaunch, instead of passing the packageName, you pas ONLY the actionName, it will see if there is any package that can handle it :)

Hi Eduardo, 


Finally it's successful to integration Outsystems with mobay apps :)

Thanks for your support.


Regards,

Imas Deny

Ah!
Nice to hear!
Cool! :)

Hi Imas, 

It would be very helpful if you shared how you fix/done it. 

Hi Harlin, 


So i just follow eduardo with new plugin and apparently there is a shortage in nativ app,


Thanks,

Imas Deny 

Is there a list anywhere of URIs for the most popular apps?  Thanks!


  -- Joel

imas deny wrote:

Hi Eduardo,


when I run can launch using the existing package the result is successful, like the picture below:


Here's the intent filter in our visionet application:

<intent-filter>

<action android:name="com.smartpesa.intent.action.TRANSACT" />

<data android:mimeType="text/plain"/>

<category android:name="android.intent.category.DEFAULT" />

</intent-filter>


here I attach my .oml, while I ask them about intent filters


Thanks,

Imas Deny 


Hi imas,


i tried your oml. then i got "plugin not available". can you please help me out in this


thanks

Navaneethan M 


Hi Navaneethan, 

Have you generate apk/ipa then test in device using it?

You cannot test this using Outsystems Now. 

Harlin Setiadarma wrote:

Hi Navaneethan, 

Have you generate apk/ipa then test in device using it?

You cannot test this using Outsystems Now. 


Hi Harlin,


I didn't generate apk. Is this only works in apk?

I will try and share the result.


Thanks, 

Navaneethan M

navaneethan m wrote:

I didn't generate apk. Is this only works in apk?

Yes. Any plugin that is not one of the plugins already built in in the OutSystems Now will work only in the device.

Cheers.


Yes you need to generate apk or ipa to test almost all of cordova plugins.