在Ionic / Cordova接收网址 [英] Receive URL in Ionic/Cordova

查看:164
本文介绍了在Ionic / Cordova接收网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置一种从其他应用程式接收网址的方法。喜欢,你在浏览器,点击共享,并发送链接到另一个应用程序(我的应用程序)。我找到这个cordova插件,并已将其集成到我的应用程序中,但我继续在我测试时不显示任何网址。

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.

我收到一条警告:


getUri url:null


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

这是webintent:

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>


推荐答案

我可以通过 Initsogar 使用此插件获取网址

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

插件可在此处找到 https://github.com/Initsogar/cordova-webintent

您可以按以下方式获取传入的URL:

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

希望这有助于应用程式的运气! Ionic真棒:)

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

这篇关于在Ionic / Cordova接收网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆