Issue
While sharing web-intent from one ionic capacitor app to another ionic capacitor app using https://github.com/darryncampbell/darryncampbell-cordova-plugin-intent/ for SDK 30 and above it is throwing "Error" without any other explanation. Please find sample code in comments
Steps to reproduce: Download the code base in comment, build app for : -
varable gradle file :-
compileSdkVersion = 32
targetSdkVersion = 32
androidxActivityVersion = '1.2.0'
androidxAppCompatVersion = '1.2.0'
androidxCoordinatorLayoutVersion = '1.1.0'
androidxCoreVersion = '1.3.2'
androidxFragmentVersion = '1.3.0'
coreSplashScreenVersion = '1.0.0-rc01'
androidxWebkitVersion = '1.4.0'
junitVersion = '4.13.1'
androidxJunitVersion = '1.1.2'
androidxEspressoCoreVersion = '3.3.0'
cordovaAndroidVersion = '7.0.0'```
Android Manifest file :-
`<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="io.ionic.starter">
<permission android:name="android.permission.QUERY_ALL_PACKAGES" />
<queries>
<package android:name="com.gameplay.app1" />
<package android:name="com.google.android.apps.youtube" />
<package android:name="com.google.android.youtube" />
<package android:name="com.android.twitter" />
<package android:name="com.flipkart.android" />
<package android:name="com.google.android.apps.youtube.music" />
<package android:name="com.google.android.gms.maps" />
<package android:name="com.google.android.gm" />
<package android:name="com.facebook.katana" />
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
</intent>
<intent>
<action android:name="android.intent.action.DIAL" />
<data android:scheme="tel" />
</intent>
<intent>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="*/*" />
</intent>
</queries>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
android:name="io.ionic.starter.MainActivity"
android:label="@string/title_activity_main"
android:theme="@style/AppTheme.NoActionBarLaunch"
android:launchMode="singleTask"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.darryncampbell.cordova.plugin.intent.ACTION"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
</activity>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"></meta-data>
</provider>
</application>
<!-- Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/>
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.LAUNCH_MULTI_PANE_SETTINGS_DEEP_LINK"/>
</manifest>
Related Sample code:
const options = {
action: this.webIntent.ACTION_VIEW,
url: 'http://www.google.com'
};
this.webIntent.startActivity(options).then(
intent => { console.log('Web Intent was successful', intent); },
error => { console.log('Error, Web Intent failed', error);
console.log('Error, Web Intent failed', error); });
Above code works & opens browser but i am unable to open any app & send data to it, be it custom or google app eg : -
const options: IntentOptions = {
// action: this.webIntent.ACTION_SEND,
component: {
package: 'com.gameplay.app1',
class: 'com.gameplay.app1.MainActivity'
},
extras: {
launchingAppPackage: 'io.ionic.starter',
launchingAppClass: 'io.ionic.starter.MainActivity'
}
};
this.webIntent.startActivity(options).then(
intent => { console.log('Web Intent was successful', intent); },
error => { console.log('Error, Web Intent failed', error); }
);
***
OR
***
const options = {
action: this.webIntent.ACTION_SEND,
url: 'geo:23.5264055,148.1594006',
package: 'com.google.android.gms.maps'
};
this.webIntent.startActivity(options).then(
() => { console.log('Intent Launched'); },
(e) => { console.log('Intent Error', e); }
);
Solution
To fix this issue, I upgraded to ionic 6 & sdk 33. And in AndroidManifest.xml included the the tag with the package names of the apps to which we need to share the intent
Answered By - N29
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.