- I’m trying to open an Ionic App by using its Package ID from my ionic App using Web-Intent.
- Send and Receive Data
– Im able to open another App but can not able to send and receive data,
– Im able to open another App but can not able to send and receive data,
Hello, please, thanks, You’re welcome!
What are you using ? Version of ionic and capacitor, cordova ?
Are you try this ? You can pass the data in the slug
you can share with me your code I am stuck in this part and on tt recover package since I work on local and thanks u <3
SENDING APP
1 | Plugins details |
---|---|
ionic cordova plugin add com-darryncampbell-cordova-plugin-intent | |
npm install --save @ionic-native/web-intent |
2. In AndroidManifest.xml
<intent-filter android:label="@string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="com.darryncampbell.cordova.plugin.intent.ACTION" /><category android:name="android.intent.category.DEFAULT" />
</intent-filter>
3 | In app.module.ts / page.module.ts |
---|---|
import { WebIntent } from ‘@ionic-native/web-intent/ngx’; | |
providers: [WebIntent] |
4 | page.ts |
---|---|
4.1 | import { RegisterBroadcastReceiverOptions, WebIntent } from ‘@ionic-native/web-intent/ngx’; |
import { Platform } from ‘@ionic/angular’; | |
4.2 | interface CustomBroadcastReceiverOptions extends RegisterBroadcastReceiverOptions { |
extras?: { [key: string]: any }; | |
} |
4.3 | constructor( |
---|---|
private webIntent: WebIntent, | |
private platform: Platform | |
){ | |
this.platform.ready().then(() => { | |
this.registerBroadcastReceiver(); | |
}); | |
} | |
4.4 | openApp(){ |
const data = { | |
key: ‘open APP’ | |
}; | |
this.webIntent.startActivityForResult({ | |
package: ‘packageid’, | |
extras: { | |
data: JSON.stringify(data) | |
} | |
}).then((intent) => { | |
const responseData = intent.extras && intent.extras.data ? intent.extras.data : null; | |
if (responseData) { | |
} | |
}); | |
} |
4.5 | registerBroadcastReceiver() { |
---|---|
const options: CustomBroadcastReceiverOptions = { | |
filterActions: [‘com.example.MY_ACTION’], | |
extras: { | |
‘param1’: ‘’, | |
‘param2’: ‘’ | |
} | |
}; | |
this.webIntent.registerBroadcastReceiver(options).subscribe((intent) => { | |
}, (error) => { | |
console.error(‘Error registering broadcast receiver:’, error); | |
}); | |
} | |
4.6 | <ion-button (click)=openApp()>Open App |
RECEIVING APP
1 | Plugins details |
---|---|
ionic cordova plugin add com-darryncampbell-cordova-plugin-intent | |
npm install --save @ionic-native/web-intent |
<intent-filter android:label="@string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="com.darryncampbell.cordova.plugin.intent.ACTION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
3 | In app.module.ts / page.module.ts |
---|---|
import { WebIntent } from ‘@ionic-native/web-intent/ngx’; | |
providers: [WebIntent] | |
4 | page.ts |
4.1 | import { WebIntent } from ‘@ionic-native/web-intent/ngx’; |
import { Platform } from ‘@ionic/angular’; | |
4.2 | interface MyIntent { |
action?: string; | |
extras: { | |
[key: string]: any; | |
}; | |
} | |
4.3 | constructor( |
— | — |
private webIntent: WebIntent, | |
private platform: Platform | |
) | |
4.4 | ionViewWillEnter() { |
this.receiveJivikaData(); } | |
4.5 | sendResponse(data) { |
let options = { | |
action: ‘com.example.MY_ACTION’, | |
extras: { | |
‘param1’: ‘abc’, | |
‘param2’: ‘xyz’ | |
} | |
}; | |
this.webIntent.sendBroadcast(options).then(() => { | |
console.log(‘Broadcast sent successfully’); | |
}).catch((error) => { | |
console.error(‘Error sending broadcast:’, error); | |
}); | |
} |
4.6 | receiveAppData(){ |
---|---|
if (this.platform.is(‘android’)) { | |
this.webIntent.getIntent().then((intent) => { | |
const data = intent.extras && (intent.extras as any).data ? (intent.extras as any).data : null; | |
if (data) { | |
this.sendResponse(data); | |
} | |
}); | |
} | |
} |