Activity starter Vs Intent

I coded In AI an activity starter to start an other app sending it a text.
image

I want to code same in Java
So i used Intent like that:

            Intent intent = new Intent();
            intent.putExtra("MessageRecu", message);
            intent.setPackage("jml.test");
            startActivity(intent);

but I have then an error:
android.content.ActivityNotFoundException: No Activity found to handle Intent { pkg=jml.test }

I tried to add intent.SetClass("jml.test.MainActivity") but it is not accepted

Could you help me with it ?

What happens when you initialize intent like this:

Intent intent = new Intent(context, Class.forName("jml.test.MainActivity"));

Or if you only want to launch main screen of other app then try this:

Intent intent = context.getPackageManager().getLaunchIntentForPackage("jml.test");

with this i got :
android.content.ActivityNotFoundException: No Activity found to handle Intent { pkg=jml.test (has extras) }

This starts jml :+1: .
I just have to write it befor putExtra...

this works very well :

            Intent intent = new Intent();
            intent = getBaseContext().getPackageManager().getLaunchIntentForPackage("jml.test");
            intent.putExtra("MessageRecu", "message");
            intent.setPackage("jml.test");
            startActivity(intent);

thanks a lot ! :+1: :+1:

It means Main activity is not actually named as MainActivity.

Good.
Btw, your code contains a redundant intent initializer.
Initialize it directly.

ok thank's for this preccision