Sending url to ionic android app via webintents from another app

前端 未结 3 1447
时光说笑
时光说笑 2020-12-15 11:24

Looking for an updated solution, running the latest ionic 1.1.0 release which uses Cordova 5.x. Trying to be able to browse a website in chrome and send that url to my ionic

3条回答
  •  天命终不由人
    2020-12-15 11:46

    This question is a bit aged. But i had a more or less similar challenge. I had no luck with the WebIntent plugin and therefore i developed my own plugin for dealing with Intents on Android.

    You may check this: https://github.com/napolitano/cordova-plugin-intent

    While i'm still working on this plugin for my own projects, it's yet almost usable and documentation should be good enough to get a foot into the door.

    Some background:

    To allow third party apps to send content to your app, you must add an intent-filter to your MainActivity in the AndroidManifest.xml.

    
        
        
        
        
    
    

    While you can do this manually, this has some disadvantages - so you probably want to have a hook or something similar. If you go to the repository above, you'll find and example for this.

    Additionally to the intent-filter, you currently need an plugin that allows you a) to access the cordova intent (that's important to get access to sent content on application startup) and to receive notifications if the onNewIntent event was triggered, which happens, if content is sent while your application is running.

    That's exaclty what my plugin does. It gives you access to the cordova intent and allows you to handle the onNewIntent event.

    Examples:

    window.plugins.intent.getCordovaIntent(function (Intent) {
        console.log(Intent);
    }, function () {
        console.log('Error');
    });
    
    window.plugins.intent.setNewIntentHandler(function (Intent) {
        console.log(Intent);
    });
    

    You will receive a limited intent object as result on success. This can be processed by your app.

    Example:

    {
        "action": "android.intent.action.SEND_MULTIPLE",
        "clipItems": [
            {
                "uri": "file:///storage/emulated/0/Download/example-document.pdf"
            },
            {
                "uri": "file:///storage/emulated/0/Download/example-archive.zip"
            }
        ],
        "flags": 390070273,
        "type": "*/*",
        "component": "ComponentInfo{com.example.droid/com.example.droid.MainActivity}",
        "extras": "Bundle[mParcelledData.dataSize=596]"
    }
    

    While this example actually shows JSON, you will receive a ready-to-use object.

    Please note that i develop the plugin currently only for my own needs. However it may work also for you. Currently no angular examples were added to the README, but i think that should not be a big problem.

提交回复
热议问题