Problem sending intent to 3rd party app

Kevin

Well-Known Member
Licensed User
Longtime User
I am trying to send an intent to a 3rd party app. I contacted the app's author and he told me how he sends shortcuts. I am sending my intent the same way, however it isn't working. If I use one of his home screen shortcuts, it all works fine. If I try sending an intent, I get a black screen from his app a few seconds after sending the intent. Once this happens, launching his app in any way causes the black screen to appear. The only way get his app to work again is to reboot the phone.

Below are some quotes from him on how to use it. To protect his privacy I have changed "key" information:

This Is In my Main Activity To create the Intent (package: my.packagepro OR For trial: my.packagetrial)

Intent shortcutIntent = new Intent(this,Launch2.class);
shortcutIntent.putExtra("shortcut", nr);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

the variable nr gives the function:
(Here he lists possible values of nr such as "Vol UP", etc.....)

Launch2 handles the intent.

This is in onCreate of Launch2

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MyApplicationClass.killit = true;

Bundle extras = getIntent().getExtras();

if (extras != null && extras.getInt("shortcut")>0) {
initMyApp(false);
int nrc = extras.getInt("shortcut")-1;
MySub.onecommand(nrc);
}

}

... And below is my code. Naturally the string sPackageName contains the name of his package and sCMD contains the command to send such as "Vol UP":

B4X:
Dim VCIntent As Intent
   
   Try
      VCIntent.Initialize("", "")
      VCIntent.SetComponent(sPackageName & "/" & sPackageName & ".Launch2")
      VCIntent.PutExtra("shortcut", sCMD)
      VCIntent.Flags = 268435456 'FLAG_ACTIVITY_NEW_TASK
      StartActivity (VCIntent)
      Catch
         Msgbox ("Failed to send command via intent to " & sPackageName & ".", "Uh-oh!")
   End Try

Any ideas on why this is crashing his app? :eek:
 

Kevin

Well-Known Member
Licensed User
Longtime User
The only difference in the logs is the flags sent with the intent. Even if I send no flags with the intent, it still crashes his app.

From what I was reading, Android sends different flags depending on how the activity is launched (from a shortcut/launcher, app intent, etc). When I send an intent to my own app it has the same flags as when I send an intent to his app. The only difference is mine works and his locks up. :BangHead:

I can post the actual log entries later (I'm at work right now).
 
Upvote 0

Kevin

Well-Known Member
Licensed User
Longtime User
I'll try from a service in a little while.

This is when I launch his shortcut:

Starting activity: Intent { act=android.intent.action.VIEW flg=0x10000000 cmp=his.apptrial/.Launch2 bnds=[120,410][237,528] (has extras) } from pid 315

Start proc his.apptrial for activity his.apptrial/.Launch2: pid=2124 uid=10148 gids={3003}

All works fine with his app. My problems start here though: My app sends an intent to another app of mine which then parses that intent and decides what to do with it. In this case, it needs to send a command to his app with another intent:

Starting activity: Intent { act= flg=0x10020000 cmp=com.cognitial.dtvvoltest/.shortcutexec (has extras) } from pid 2204 <---- My app

... then his activity launches and things turn bad.........

Starting activity: Intent { act= flg=0x10020000 cmp=his.apptrial/.Launch2 (has extras) } from pid 2204 <----- His app


** Activity (shortcutexec) Pause, UserClosed = true **
Start proc his.apptrial for activity his.apptrial/.Launch2: pid=2335 uid=10148 gids={3003}

.....

Key shortcut expected Integer but value was a java.lang.String. The default value 0 was returned.


Attempt to cast generated internal exception:


java.lang.ClassCastException: java.lang.String
at android.os.Bundle.getInt(Bundle.java:918)
at android.os.Bundle.getInt(Bundle.java:901)
at his.apptrial.Launch2.onCreate(Launch2.java:45)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1785)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1842)
at android.app.ActivityThread.access$1500(ActivityThread.java:132)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:4263)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)

What is strange is that the intent for my app and his app both use the same flags (flg=0x10020000), but something is obviously different about the way his works when called from an intent (vs. a normal shortcut intent).

I'll try sending from a service....


EDIT:
Starting from a service did affect the flag. It is now identical to when his activity is started from a shortcut (flg=0x10000000). However, the result was the same. I get a black screen from his app and I need to reboot the phone before it works correctly again. Strange.
 
Last edited:
Upvote 0

Kevin

Well-Known Member
Licensed User
Longtime User
I got in contact with the author of the other app again and after exchanging a couple emails we figured it out.

The activity that parses the intent was looking for an integer, not a string. The list he gave me (alluded to in my first post above) was "an array", but unfortunately he didn't mention that and it looked to me that the intent was using a string for the command. It seemed obvious to me so I didn't bother to ask and he never mentioned it.

Anyway, all should be well now. He is going to confirm the numbers that represent each command and get back to me later on.

A simple misunderstanding turned into hours of banging my head against the wall. :BangHead: :D
 
Upvote 0
Top