12

I'm trying to set up a way to receive a url from another app. Like, you are in browser, click share, and send the link to another app (my app). I found this cordova plugin, and have integrated it in my app, but I continue to not show any url when I test it.

I get an alert that says:

getUri url:null

Any help would be great. Happy to add more code if helpful.

app.js:

'use strict';

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', [
  'ionic',
   'firebase',
   'starter.services',
   'starter.directives',
   'starter.controllers',
   'ngSanitize'
 ])
.run(function($rootScope, $state, $ionicPlatform, Post) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory
    // bar above the keyboard for form inputs)
    if (window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }

    if (window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleDefault();
    }

This is the webintent:

    if (window.plugins && window.plugins.webintent) {
      window.plugins.webintent.getUri(function(url) {
      alert("getUri url:"+url);
      });
    }

    $rootScope.$on('$stateChangeError', function(event, toState, toParams,
                                                 fromState, fromParams, error) {
      $state.go(error);
    });
  });
})
angular.module('starter.services', []);
angular.module('starter.directives', []);
angular.module('starter.controllers', []);

AndroidManifest.xml:

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" android:windowSoftInputMode="adjustPan" package="com.ionicframework.wefeed949805" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:launchMode="singleTop" android:name="wefeed" android:theme="@android:style/Theme.Black.NoTitleBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="text/plain" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
</manifest>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Shaun
  • 583
  • 5
  • 19

2 Answers2

6

I've been working on something similar. I was able to get the url by using this plugin by Initsogar

The plugin can be found here https://github.com/Initsogar/cordova-webintent

You can get the incoming url as follows:

var incomingURL
window.plugins.webintent.getExtra(window.plugins.webintent.EXTRA_TEXT,
      function(url) {
        incomingURL = url
        console.log(incomingURL);
      }, function() {
        incomingURL = false;
      }
  );

Hope this helps, and good luck on the app! Ionic is awesome :)

Tom McGurl
  • 76
  • 2
  • I swear I tried this before and it didn't work. Anyway thanks! – Shaun Oct 16 '14 at 15:00
  • No problem! I had the same problem at first when trying the getURI. This one works well too for apps that share more than just the URL like Flipboard for example which passes a heading and a URL when you 'share' and article. – Tom McGurl Oct 18 '14 at 03:40
  • when launching via http / https link, it works for me when using `.getUri()` instead of `.getExtra()`. It depends on type of intent it seems. – jakub.g Feb 03 '16 at 15:03
  • I got it to working using your answer and the code in the question. Now I have a problem because every time I share with my app it creates a new instance, so there can be many instances of my application in the recent tasks view. I've tried to add `android:documentLaunchMode="intoExisting"` to the activity, but it doesn't seem to be doing anything differentl. Additionally if I change `android:LaunchMode="singleTask"` it gets overwritten everytime I build for android. – Gabe O'Leary Nov 23 '16 at 23:43
  • sorry, i have this error: "plugins does not exist on type widow". I place this line of code in the constructor (i use cordova and typescript).I try to place in a method but there is the same error. Have you an idea? – Francesco Taioli Dec 26 '16 at 12:36
0

For general help and recent developments I want to add an answer to this.

There is a cordova plugin called Custom URL scheme. For the documentation of plugin is solid I don't add any further information.

engincancan
  • 2,442
  • 2
  • 28
  • 43