darryncampbell / darryncampbell-cordova-plugin-intent

General purpose intent shim layer for cordova appliations on Android. Handles various techniques for sending and receiving intents.
MIT License
86 stars 130 forks source link

Possible to send custom android.intent.action.START_SOS intent ? #111

Closed jbennegent closed 4 years ago

jbennegent commented 4 years ago

Hello,

I'm quite new to Ionic, trying to make some experimentations with intents ; so this may be a simple / silly question, if so, I apologize in advance.

I'm using a phone that has a programmable hardware button ; you can select which action is linked to this button. The manufacturer of this phone has developped a custom SOS application, by default linked to this button ; when you press the button, it launches this SOS feature.

My goal is to be able to launch this SOS application from my own Ionic app (i.e., launch a SOS from my app).

For this, I have observed how this is done, and I have found a special intent for this : android.intent.action.START_SOS. This intent is fired when the SOS feature is launched.

So here is my question : can I launch this intent using this plugin?

I have tried a few things, but nothing works for now.

const options = {
      action: "android.intent.action.START_SOS",
    };
this.webIntent.startActivity(options).then(this.onSuccess, this.onError);

When doing this, the error handler is called, but I don't know how to get more info.

Can you help?

Regards

darryncampbell commented 4 years ago

What is the error? Your onError handler should take a single parameter - try logging that to the console.

jbennegent commented 4 years ago

Hello, thanks for helping.

Like this ?

onError(e){
    console.log(e);
  }

I get Error in the log.

darryncampbell commented 4 years ago

That's not the most descriptive error is it(?!) but it looks to be coming from https://github.com/darryncampbell/darryncampbell-cordova-plugin-intent/blob/master/src/android/IntentShim.java#L427 which indicates that the Intent could not be resolved. Are you sure that's the right action? Usually to launch an app you use ACTION_VIEW, https://developer.android.com/reference/android/content/Intent#ACTION_VIEW

jbennegent commented 4 years ago

I agree this is not the most descriptive error :)

Actually I have no idea if what I want can be achieved ; I have observed in logs (adb logcat) that this intent is fired, but I have no idea if I can fire it or not. I have no control or further info about this intent's app.

Do you have any advice for me to go further on this?

Thanks!

darryncampbell commented 4 years ago

If it was me I'd probably write a native app to find out how to format the Intent to invoke the SOS app before trying to do the equivalent in Ionic: https://stackoverflow.com/questions/3422758/start-application-knowing-package-name https://android.stackexchange.com/questions/28767/view-apps-full-package-name Then when you know the details of the Intent, invoke the app (something like this): https://github.com/darryncampbell/plugin-intent-api-exerciser/blob/master/www/js/index.js#L233

jbennegent commented 4 years ago

Thanks again for your help, I'll try this!