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

Unable to make Intent call to startActivity #105

Closed RizwanArifHanfi closed 4 years ago

RizwanArifHanfi commented 4 years ago

HI @darryncampbell

I'm integrating your plugin to invoke web intent to make Intent call to startActivity to choose UPI enabled app through chooser in my ionic-capacitor app

Code I'm calling below method to invoke web intent.

const options = {
  action: this.webIntent.ACTION_VIEW,
  url: 'path/to/file',
  type: 'application/vnd.android.package-archive'
}
this.webIntent.startActivity(options).then(onSuccess, onError);

My IONIC environment

Ionic:

   Ionic CLI                     : 6.8.0 (/usr/local/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.1.0
   @angular-devkit/build-angular : 0.803.26
   @angular-devkit/schematics    : 8.3.26
   @angular/cli                  : 8.3.26
   @ionic/angular-toolkit        : 2.2.0

Capacitor:

   Capacitor CLI   : 2.1.0
   @capacitor/core : 2.1.0

Cordova:

   Cordova CLI       : 8.1.2 (cordova-lib@8.1.1)
   Cordova Platforms : none
   Cordova Plugins   : no whitelisted plugins (3 plugins total)

Utility:

   cordova-res                          : not installed
   native-run (update available: 1.0.0) : 0.2.9

System:

   Android SDK Tools : 26.1.1 (/home/pc-rizwan/Android/Sdk)
   NodeJS            : v10.19.0 (/usr/bin/node)
   npm               : 6.14.5
   OS                : Linux 5.4

After Compilation When i compile to run on my device i'm getting following error: com/darryncampbell/plugin/intent/IntentShim.java uses or overrides a deprecated API and this.webIntent.startActivity(options).then(onSuccess, onError); always give error.

Also tried patching with cordova-plugin-androidx-adapter, but no luck.

Run Log

D/Cordova Intents Shim: Action: startActivity
I/Capacitor/Console: File: http://localhost/home-home-module-es2015.js - Line 137 - Msg: Error:  Error

Please suggest what I can do to make it wotking.

darryncampbell commented 4 years ago

Hi, I do not know what could be causing that I'm afraid - I get a bit confused what the team did when they created the WebIntent plugin. You can call my plugin directly with:

(<any>window).plugins.intentShim.startActivity(options).then(onSuccess, onError);

which may avoid any conflicts with WebIntent

RizwanArifHanfi commented 4 years ago

I tried your suggestion: (<any>window).plugins.intentShim.startActivity(options).then(onSuccess, onError);

But unfortunately, it says (<any>window).plugins undefined

RizwanArifHanfi commented 4 years ago

Always getting this error when running in android studio:

Task :capacitor-cordova-android-plugins:compileDebugJavaWithJavac Note: /home/pc-rizwan/ionic/capacitor/app/android/capacitor-cordova-android-plugins/src/main/java/com/darryncampbell/plugin/intent/IntentShim.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details.

Task :capacitor-android:generateDebugRFile

Task :capacitor-android:compileDebugJavaWithJavac Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details.

RizwanArifHanfi commented 4 years ago

After trying different ways, managed to work with your suggestion: (<any>window).plugins.intentShim.startActivity(options).then(onSuccess, onError);

used in my code as:

const options = {
  action: (<any>window).plugins.intentShim.ACTION_VIEW,
  url: 'path'
};
(<any>window).plugins.intentShim.startActivity(options).then(
  (onSuccess) => {
    console.log('Intent success: ', onSuccess);
    alert('Intent success: ' + onSuccess);
  }, (onError) => {
    console.log('Intent failed: ', onError);
    alert('Intent failed: ' + onError);
  });

I got following error:

Wrong type for parameter "successCallback" of IntentShim.startActivity: Expected Function, but got Undefined.

Where i'm doing wrong?

RizwanArifHanfi commented 4 years ago

Hi, I do not know what could be causing that I'm afraid - I get a bit confused what the team did when they created the WebIntent plugin. You can call my plugin directly with:

(<any>window).plugins.intentShim.startActivity(options).then(onSuccess, onError);

which may avoid any conflicts with WebIntent

Still gives error

darryncampbell commented 4 years ago

After trying different ways, managed to work with your suggestion: (<any>window).plugins.intentShim.startActivity(options).then(onSuccess, onError);

used in my code as:

const options = {
  action: (<any>window).plugins.intentShim.ACTION_VIEW,
  url: 'path'
};
(<any>window).plugins.intentShim.startActivity(options).then(
  (onSuccess) => {
    console.log('Intent success: ', onSuccess);
    alert('Intent success: ' + onSuccess);
  }, (onError) => {
    console.log('Intent failed: ', onError);
    alert('Intent failed: ' + onError);
  });

I got following error:

Wrong type for parameter "successCallback" of IntentShim.startActivity: Expected Function, but got Undefined.

Where i'm doing wrong?

You are calling .then() but startActivity(...) does not return a promise. There is similar code for sending a broadcast at https://github.com/ZebraDevs/DataWedge-Ionic-Demo/blob/master/src/providers/barcode/barcode.ts#L92

RizwanArifHanfi commented 4 years ago

Now working!

Thanks for support @darryncampbell :+1: