Skip to content
This repository has been archived by the owner on Mar 1, 2022. It is now read-only.

Issues sending intent to a specific app #116

Open
jeremy-power opened this issue Aug 17, 2020 · 12 comments
Open

Issues sending intent to a specific app #116

jeremy-power opened this issue Aug 17, 2020 · 12 comments

Comments

@jeremy-power
Copy link

jeremy-power commented Aug 17, 2020

Hey Darryn,

I am trying to start another activity with some simple extras, however I am unsure where to point to the specific application.

Currently it is defined as such:

image

(The app I am trying to open is com.nymi.nbeservice)
However, this is causing a completely separate app to open called TickTick (no idea how).

The logs are here:

image

Hope you can take a quick look and let me know what I'm doing wrong.

Thanks so much,

Jeremy Power

@darryncampbell
Copy link
Owner

content://com.nymi.nbeservice is not the package name of the app you are calling, it will invoke whatever has registered an intent filter for that data object, in this case TickTick. Here is an example of calling via an explicit intent: https://github.com/darryncampbell/plugin-intent-api-exerciser/blob/master/www/js/index.js#L81. Also, your colleague seems to be doing something very similar, #115

@jeremy-power
Copy link
Author

Hi thank you very much for the response. It is true my coworker and I are working on the same issue but I thought this was a separate enough problem that it should be in a separate issue for anyone searching the problem.

I understand now where to put the package name, but I am now getting web intent error: Error

These are my current web intent options.
image

This is the manifest of the app I am trying to send intent to:
image

and these are the logs:
image

Thank you so much for your help,
Jeremy Power

@darryncampbell
Copy link
Owner

You may get a more verbose error message if you access the plugin directly rather than going through WebIntent, (window).plugins.intentShim.startActivity(...)

@darryncampbell
Copy link
Owner

Do you have documentation for what you are trying to call? How would you call this with a native app?

@jeremy-power
Copy link
Author

image

This is how the intent is sent natively inside the app I am trying to send the same intent to externally.

image

I am sorry if this is vague, I am new to intents and I do not have very good documentation to go off of.

Also could you expand on the more verbose error message?
image
I can't seem to get that syntax to work, perhaps because I am using capacitor and not cordova.

Thank you so much for the help,

Jeremy

@darryncampbell
Copy link
Owner

It looks like you will need to fork and modify this plugin.

The plugin does not support either getLaunchIntentForPackage(...) or startForegroundService. There is a good case for adding these but I have no immediate plans to do so myself.

The other observation is you are not specifying the component in your javascript: https://github.com/darryncampbell/darryncampbell-cordova-plugin-intent/blob/master/src/android/IntentShim.java#L499 but even if you specified it, you can't call startForegroundService.

@sohelmk
Copy link

sohelmk commented Sep 1, 2020

Hi @darryncampbell ,
We forked the plugin to add the two methods we needed, but we are unable to use startForeground service. It does not show any error either. Here is the code we are trying. Similar code (except cordova line works in android native). Can you please advise any other changes?

        Intent i = new Intent();
        i.setComponent(new ComponentName(NBE_SERVICE_PACKAGE_NAME, NBE_SERVICE_CLS_NAME));
        i.putExtra(AGENT_IP, "192.168.2.11");
        i.putExtra(AGENT_PORT, "1234");
        Context context=this.cordova.getActivity().getApplicationContext(); 
        context.startForegroundService(i);

        //set result
        cordova.getActivity().setResult(Activity.RESULT_OK, result);
        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
        //finish the activity
        cordova.getActivity().finish();

Thanks,
Sohel

@darryncampbell
Copy link
Owner

I don't know... it seems to match the native code you put earlier that worked. Have you tried just putting the startService bit and see if that works:

        Intent i = new Intent();
        i.setComponent(new ComponentName(NBE_SERVICE_PACKAGE_NAME, NBE_SERVICE_CLS_NAME));
        i.putExtra(AGENT_IP, "192.168.2.11");
        i.putExtra(AGENT_PORT, "1234");
        Context context=this.cordova.getActivity().getApplicationContext(); 
        context.startForegroundService(i);

@sohelmk
Copy link

sohelmk commented Sep 1, 2020

Thanks @darryncampbell , yes i tried startService, did not work...no error etc in log...

I also tried following but could not compile as could not find android support class ContextCompat
// Intent serviceIntent = new Intent();
// serviceIntent.setComponent(new ComponentName(NBE_SERVICE_PACKAGE_NAME, NBE_SERVICE_CLS_NAME));
// serviceIntent.putExtra(AGENT_IP, "192.168.2.11");
// serviceIntent.putExtra(AGENT_PORT, "1234");
// ContextCompat.startForegroundService(this.cordova.getActivity(), serviceIntent);

Any other place/forum/specs to seek help on this issue?

Thanks,
Sohel

@darryncampbell
Copy link
Owner

According to your image at https://user-images.githubusercontent.com/17508664/90535322-c52a4c80-e148-11ea-9747-094e57b516c6.png the service needs to have been granted some permissions before you can call the service, have you tried implementing that entire code block?

You might try reaching out to the program author for more help

@sohelmk
Copy link

sohelmk commented Sep 2, 2020

Thanks @darryncampbell issue resolved, it needs SDK level > 26 to work.
So it is not working on some phones. Trying to see if we can check this in code to give a proper error message when it will not work. I wonder why cordova does not log such issues.

Thanks a lot

@darryncampbell
Copy link
Owner

darryncampbell commented Sep 2, 2020

Eureka! Typically you should surround code with if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.X) if it is an API that only works on certain Android versions, then you can log an error if the Android version is not high enough, so it is not really something Cordova would typically check for in the framework

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants