PC SOFT

PROFESSIONAL NEWSGROUPS
WINDEVWEBDEV and WINDEV Mobile

Home → WINDEV Mobile 2024 → Communication via intent
Communication via intent
Started by Mirte, Mar., 15 2018 2:23 PM - 6 replies
Posted on March, 15 2018 - 2:23 PM
Hello

I'm trying to communicate with an app via intents. The app is self made and in Android studio we've managed to get this code working:

Intent myIntent = new Intent();
myIntent.setClassName("xx.xxxx.xxx", "xx.xxx.xxx.MainActivity");
if (myIntent.resolveActivity(getPackageManager()) != null)
{
startActivityForResult(myIntent, 1);
}
@Override
public void onActivityResult(int reqCode, int resCode, Intent data)
{
switch (reqCode)
{
case (1):
{
if (resCode == Activity.RESULT_OK)
{
if (data != null)
{
String rs = data.getStringExtra("txt");
}
}
break;
}
}
}

How can I get this code to work in Windev? The Java compiler gives these errors

cannot find symbol
if (myIntent.resolveActivity(getPackageManager()) != null)
^
symbol: method getPackageManager()

cannot find symbol
startActivityForResult(myIntent, 1);
^
symbol: method startActivityForResult(Intent,int)


Any help would be very much appreciated!
Posted on March, 16 2018 - 1:06 PM
Hi Mirte,

Basicallyn, this means that you need to reference some packages/classes
in your windev mobile project...

You'll find a basic explanation and I hope a starting point in my
article here:

http://fabriceharari.com/UK/Page_Article.awp…

This should let you find out what packages or classes you need to
reference, and if it's classes we are talking about, the help says :

The Java classes used in the native Java code must be specified in the
wizard for generating the Android application:

"Integrating libraries" step for the classes included in ".jar" or
".aar" libraries.
"Integrating Maven dependencies" step for the Maven dependencies.
Note: The test of these classes cannot be run in GO mode. The
application must be generated and started.


Hope this helps, best regards

--
Fabrice Harari
International WinDev, WebDev and WinDev mobile Consulting

Ready for you: WXShowroom.com, WXReplication (open source) and now WXEDM
(open source)

More information on http://www.fabriceharari.com
Registered member
7 messages
Posted on March, 29 2018 - 10:13 AM
Thank you for your reply.
We've been able to get the intent to work, so for now we are good.
We'll have to do some more work in order for onActivityResult to work.

There are two new issues that we've encountered:

1) We now have to do a similar thing for iOS.
We need to make it possible to open another app and also allow that other app to call to us.
Is there anything you can suggest or you can explain so we'll be able to do this?

I'm still very new to this environment and to innerapp communication ...

2) Thread handling
Since recent Android updates, there have been more and more errors on HTTP requests.
We figured out that this is a thread policy problem.
In Android studio, the following code solveed the problem:

import android.os.StrictMode;

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);

But in Windev it didn't seem to have any effect.
Is there anything on this matter you could help me with?
I've looked at https://doc.windev.com/… but haven't been able to get it to work so far.

Kind regards

Mirte
Posted on March, 29 2018 - 2:13 PM
Hi,

Le 3/29/2018 à 2:13 AM, Mirte VANBERGHEN a écrit :
Thank you for your reply.
We've been able to get the intent to work, so for now we are good.
We'll have to do some more work in order for onActivityResult to work.

There are two new issues that we've encountered:

1) We now have to do a similar thing for iOS.
We need to make it possible to open another app and also allow that
other app to call to us.
Is there anything you can suggest or you can explain so we'll be able to
do this?

I'm still very new to this environment and to innerapp communication ...


Can't help you there... I try to stay clear of IOS as much as I can...

2) Thread handling
Since recent Android updates, there have been more and more errors on
HTTP requests.
We figured out that this is a thread policy problem.
In Android studio, the following code solveed the problem:


Really ? I'm doing TONS of httprequest in android apps, and I've been
testing that part extensively with androids phones version 4 to 7
without ANY problem, with my httprequest being either in the main thread
or in a secondary one.

Are you sure it's not a problem in your code instead?

Best regards

--
Fabrice Harari
International WinDev, WebDev and WinDev mobile Consulting

Free Video Courses, free WXShowroom.com, open source WXReplication, open
source WXEDM.

More information on http://www.fabriceharari.com



import android.os.StrictMode;

       StrictMode.ThreadPolicy policy = new
StrictMode.ThreadPolicy.Builder().permitAll().build();
       StrictMode.setThreadPolicy(policy);

But in Windev it didn't seem to have any effect.
Is there anything on this matter you could help me with? I've looked at
https://doc.windev.com/… but haven't been able to get it to work
so far.

Kind regards
Mirte
Posted on October, 09 2018 - 1:52 PM
Hi Mirte,

Would you be willing to share the java code (and the imports)?
Because I keep getting errors on the getPackageManger()

What I've got so far is:

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.content.pm.PackageManager;

public static void CCVCall()
{
Uri uri = Uri.parse("ccvpay://www.ccvmini.be/sale/EUR/0.01");

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PackageManager pm = getPackageManager();

// if (intent.resolveActivity(getPackageManager()) != null) {
// startActivity(intent);
// }


The line (intent.resolveActivity(getPackageManager()) gave errors, so I'm trying to get a PackageManager as suggested in some sites, but the comment lines have to become active.

Thanks in advance for any suggestions

Mark
Posted on October, 11 2018 - 9:34 AM
For those interested I got it working thanks to some other threads on getPackageManager()
In these case I'm sending a command like this:

sCommand is string = "ccvpay://www.ccvmini.be/sale/EUR/" + EDT_BEdrag
CCVCall(sCommand)

and the Java code sends the command to the app of CCV which manages payment on a mobile terminal.

Here's the code:

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.content.pm.PackageManager;

public static boolean CCVCall(String paramCommand)
{
Uri uri = Uri.parse(paramCommand);

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

if (intent.resolveActivity(getContexteApplication().getPackageManager()) != null) {
getContexteApplication().startActivity(intent);
return true;
}
return false;
}
Posted on August, 04 2021 - 7:33 AM
Very useful,
Thanks for sharing!!