Ionic / Cordova:使用config.xml添加意图过滤器 [英] Ionic/Cordova: Add intent-filter using config.xml

查看:343
本文介绍了Ionic / Cordova:使用config.xml添加意图过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ionic Framework(基于Cordova)开发移动应用程序。

I'm developing a mobile app using Ionic Framework (based on Cordova).

在Android中,我注册我的应用程序以打开* .txt文件。
我在平台/ android / AndroidManifest.xml中添加了intent-filter,它工作。
但平台文件夹在.gitignore:我想使用config.xml。

In Android I register my app to open *.txt files. I do it adding intent-filter in platforms/android/AndroidManifest.xml and it works. But platform folder is in .gitignore: I want to do it using config.xml.

我试图在config.xml中添加:

I tried adding in config.xml:

 <platform name="android">
    <config-file target="AndroidManifest.xml" parent="/*/application/activity">
      <intent-filter><!-- ... --></intent-filter>
    </config-file>
    <!-- ... -->
 </platform>

我也尝试添加:

 <platform name="android">
    <config-file target="AndroidManifest.xml" parent="/manifest/application">
      <activity android:name="CordovaApp"> 
        <intent-filter><!-- ... --></intent-filter>
      </activity>
    </config-file>
    <!-- ... -->
 </platform>

然后我尝试更新AndroidManifest启动

Then I tried to update AndroidManifest launching

ionic prepare

或者:

ionic remove platform android && ionic add platform android

但是AndroidManifest.xml始终不变。
我做错了什么?

But AndroidManifest.xml is always unchanged. What am I doing wrong?

我使用Ionic 1.3.2和Cordova 4.2.0。

I'm using Ionic 1.3.2 and Cordova 4.2.0.

编辑
这里是整个config.xml:

Edit Here the entire config.xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.ionicframework.myapp551932" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
  <name>MyApp</name>
  <description>
        myApp
    </description>
  <author email="xxx@yyy.it" href="http://www.example.com/">
      A Team
    </author>
  <content src="index.html"/>
  <access origin="*"/>
  <preference name="webviewbounce" value="false"/>
  <preference name="UIWebViewBounce" value="false"/>
  <preference name="DisallowOverscroll" value="true"/>
  <preference name="BackupWebStorage" value="none"/>
  <preference name="SplashScreen" value="screen"/>
  <preference name="SplashScreenDelay" value="3000"/>
  <feature name="StatusBar">
    <param name="ios-package" value="CDVStatusBar" onload="true"/>
  </feature>
  <platform name="android">
    <config-file target="AndroidManifest.xml" parent="/manifest/application/activity">
      <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="file" />
        <data android:mimeType="*/*" />
        <data android:pathPattern=".*\\.txt" />
        <data android:host="*" />
      </intent-filter>
      <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:scheme="content" />
        <data android:pathPattern=".*\\.txt" />
        <data android:mimeType="*/*" />
      </intent-filter>
    </config-file>
    <icon src="resources/android/icon/drawable-ldpi-icon.png" density="ldpi"/>
    <icon src="resources/android/icon/drawable-mdpi-icon.png" density="mdpi"/>
    <icon src="resources/android/icon/drawable-hdpi-icon.png" density="hdpi"/>
    <icon src="resources/android/icon/drawable-xhdpi-icon.png" density="xhdpi"/>
    <icon src="resources/android/icon/drawable-xxhdpi-icon.png" density="xxhdpi"/>
    <icon src="resources/android/icon/drawable-xxxhdpi-icon.png" density="xxxhdpi"/>
    <splash src="resources/android/splash/drawable-land-ldpi-screen.png" density="land-ldpi"/>
    <splash src="resources/android/splash/drawable-land-mdpi-screen.png" density="land-mdpi"/>
    <splash src="resources/android/splash/drawable-land-hdpi-screen.png" density="land-hdpi"/>
    <splash src="resources/android/splash/drawable-land-xhdpi-screen.png" density="land-xhdpi"/>
    <splash src="resources/android/splash/drawable-land-xxhdpi-screen.png" density="land-xxhdpi"/>
    <splash src="resources/android/splash/drawable-land-xxxhdpi-screen.png" density="land-xxxhdpi"/>
    <splash src="resources/android/splash/drawable-port-ldpi-screen.png" density="port-ldpi"/>
    <splash src="resources/android/splash/drawable-port-mdpi-screen.png" density="port-mdpi"/>
    <splash src="resources/android/splash/drawable-port-hdpi-screen.png" density="port-hdpi"/>
    <splash src="resources/android/splash/drawable-port-xhdpi-screen.png" density="port-xhdpi"/>
    <splash src="resources/android/splash/drawable-port-xxhdpi-screen.png" density="port-xxhdpi"/>
    <splash src="resources/android/splash/drawable-port-xxxhdpi-screen.png" density="port-xxxhdpi"/>
  </platform>
  <icon src="resources/android/icon/drawable-xhdpi-icon.png"/>
</widget>


推荐答案

已解决!

我无法使用Ionic或Cordova:这是一个PhoneGap功能(请参阅此 Stackoverflow答案

I can't do it using Ionic or Cordova: it's a PhoneGap feature (see this Stackoverflow answer)

我可以通过其他两种方式实现:

I can do it in two other ways:


  1. Cordova插件

  2. 使用钩子

我喜欢第二种方式。为了我的目的,我找到了一个有趣的挂钩
注意:Rembember要安装一些软件包:

I prefered the second way. I found an interesting hook for my purposes. Note: Rembember to install some packages:

npm install lodash elementtree plist --save-dev

很遗憾,这个钩子合并了标签。
所以我写了一个小改动版本的这个钩子:见这里。您可以将此钩子放在/ hooks / after_platform_add中。

Sadly this hook merges tags. So I wrote a little changed version of this hook: see here. You can put this hook in /hooks/after_platform_add.

现在我在config.xml中有我的intent-filter配置:

Now I have my intent-filter configuration in config.xml:

  <platform name="android">
    <config-file target="AndroidManifest.xml" parent="application/activity">
      <intent-filter><!-- ... --></intent-filter>
    </config-file>
    <!-- ... -->
  </platform>

我可以更新AndroidManifest.xml重新生成Android平台:

And I can update AndroidManifest.xml regenerating android platform:

ionic platform remove android && ionic platform add android

这篇关于Ionic / Cordova:使用config.xml添加意图过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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