I also needed to do similar stuff. I struggled in the beginning but now I have found the solution, happy to share this information, this could be useful for others
First you need to write a cordova plugin, this plugin should have
BroadcastReceiver implementation as shown below
public class IntentReceiver extends BroadcastReceiver {
public static final String EXTRA_NAME = "message";
@Override
public void onReceive(Context ctx, Intent intent) {
try{
Intent mainIntent = new Intent(ctx, Class.forName(ctx.getPackageName() + ".MainActivity"));
mainIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
String extra = intent.getStringExtra(EXTRA_NAME);
mainIntent.putExtra("message", extra);
ctx.startActivity(mainIntent);
}catch(Exception ex){ }
}
Plugin.xml
Add below nodes to plugin.xml file
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</config-file>
<config-file parent="/manifest/application" target="AndroidManifest.xml">
<receiver android:name="hcw.fi.phoniro.receiver.IntentReceiver" android:exported="true">
<intent-filter android:priority="999">
<action android:name="android.intent.action.SEND" />
</intent-filter>
</receiver>
</config-file>
htmlpage.ts
Add below code in platform ready
platform.ready().then(() => {
window.plugins.intent.setNewIntentHandler(this.HandleNewIntent);
window.plugins.intent.getCordovaIntent(this.HandleNewIntent, function () {
//alert("Error: Cannot handle open with file intent");
});
});
HandleNewIntent(intent){
if(intent && intent.extras){
intent.extras.myParams) {
// Do something with the File
document.getElementById("intentdata").innerHTML = "Data from Android app : " +intent.extras.message;
}else{
// this will happen in getCordovaIntent when the app starts and there's no
// active intent
console.log("The app was opened manually and there's not file to open");
//alert('The app was opened manually and there is not file to open' + intent);
}
}