2014-09-24 6 views
10

Ich versuche einen Weg zu finden, eine URL von einer anderen App zu erhalten. Sie befinden sich beispielsweise im Browser, klicken auf Freigabe und senden den Link an eine andere App (meine App). Ich habe this cordova plugin gefunden und habe es in meine App integriert, aber ich zeige weiterhin keine URL, wenn ich es teste.URL in Ionic/Cordova empfangen

Ich erhalte eine Warnung, die sagt:

getUri url:null

Jede Hilfe wäre toll. Gerne fügen Sie mehr Code hinzu, wenn hilfreich.

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(); 
    } 

Dies ist 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> 
+0

versuchen Sie die URL zu öffnen? –

+0

Ich werde mit der URL "Sachen machen". In meiner App werde ich mit einer API interagieren, um Daten von der URL-Seite zu ziehen. Im Moment kann ich keinen Zugriff auf die URL erhalten, also wird es hilfreich sein, sie zu bekommen. – Shaun

+0

@Shaun: Können Sie das tun? Kannst du mir sagen, welche Schritte du verfolgt hast? –

Antwort

7

Ich habe auf etwas Ähnliches gearbeitet. Ich konnte die URL erhalten, indem Sie dieses Plugin von Initsogar

Das Plugin finden Sie hier https://github.com/Initsogar/cordova-webintent

Sie können die eingehende URL erhalten wie folgt:

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

hoffe, das hilft und gut Glück auf der App! Ionic ist genial :)

+0

Ich schwöre, ich habe es vorher versucht und es hat nicht funktioniert. Trotzdem danke! – Shaun

+0

Kein Problem! Ich hatte das gleiche Problem beim ersten Versuch mit dem getURI. Dieser funktioniert auch gut für Apps, die mehr als nur die URL teilen, wie zum Beispiel Flipboard, das beim Teilen und Artikel eine Überschrift und eine URL übergibt. –

+0

beim Starten über http/https-Link, funktioniert es für mich, wenn Sie '.getUri()' anstelle von '.getExtra()' verwenden. Es hängt von der Art der Absicht ab, die es scheint. –

1

Für allgemeine Hilfe und aktuelle Entwicklungen möchte ich eine Antwort hinzufügen.

Es gibt ein Cordova-Plugin namens Custom URL scheme. Für die Dokumentation des Plugins ist solide ich füge keine weiteren Informationen hinzu.