android - 使用cordova将android图库中的图片分享到cordova应用程序

标签 android ios android-intent cordova cordova-plugins

我可以在共享界面中添加我的 cordova 应用程序,但我不知道如何将共享图片添加到我的 cordova 应用程序中。

我使用了 com.borismus.webintent 插件

我在 deviceready 中调用下面的代码,但运气不好。

     function startActivity() {
        alert('start');
        window.plugins.webintent.startActivity({
            action: window.plugins.webintent.ACTION_VIEW,
            url: theFile.toURL(),
            type: 'application/vnd.android.package-archive'
        },
        function () { alert('success');},
        function () {
            alert('Failed to open URL via Android Intent.');
            console.log("Failed to open URL via Android Intent. URL: " +                      theFile.fullPath)
           }
          );
       }

    function broadcast() {
         window.plugins.webintent.sendBroadcast({
         action: 'com.dummybroadcast.action.triggerthing',
         extras: {
              'option': true
          }
         }, function (args) {
             alert(args);
         }, function (args) {
             alert(args);
       });
     }


    function getURI() {
        window.plugins.webintent.getUri(function (url) {
          if (url !== "") {
            // url is the url the intent was launched with
            alert(url);
          }
          else {
            alert('ddfsdf');
          }
        });
      }

我的要求是在图库中,如果我单击 sahre 图标,我的应用程序应该出现在那里,一旦我选择了我的应用程序,我应该能够在我的 cordova 应用程序中获取该图像。

我正在使用 cordova 3.4.0,android enter image description here

我的 AndroidManifest.xml 是

    <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:name="Share" 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" />
            <action android:name="android.intent.action.SEND_MULTIPLE" />
            <data android:mimeType="application/vnd.google.panorama360+jpg" />
            <data android:mimeType="image/*" />
            <data android:mimeType="video/*" />
            <data android:mimeType="text/plain" />
        </intent-filter>
      <intent-filter>
        <action android:name="com.creative.share.UNIQUESTRING" />
        <category android:name="android.intent.category.DEFAULT" />
      </intent-filter>
    </activity>
  <activity android:name="IntentTest" android:label="@string/app_name" android:configChanges="orientation|keyboardHidden">
    <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.VIEW"></action>
      <category android:name="android.intent.category.DEFAULT"></category>
      <category android:name="android.intent.category.BROWSABLE"></category>
      <data android:host="www.youtube.com" android:scheme="http"></data>
    </intent-filter>
  </activity>


  <activity android:name=".BrowserActivity" android:label="@string/app_name" >
    <intent-filter>
      <action android:name="android.intent.action.VIEW" />
      <category android:name="android.intent.category.DEFAULT" />
      <data android:scheme="http" />
    </intent-filter>
  </activity>


    <provider android:authorities="com.creative.share.plugin.emailcomposer.attachmentprovider" android:name="de.appplant.cordova.plugin.emailcomposer.AttachmentProvider" />
</application>

最佳答案

我想我可以部分回答这个问题。我相信您正在尝试将图像分享到您的应用程序,您可以在其中进行处理。

在撰写本文时,您提到的插件中存在错误,但是您可以尝试以下解决方法:https://github.com/Initsogar/cordova-webintent/issues/23

我的 AndroidManifest.xml 如下所示:

<application android:icon="@drawable/icon" android:label="@string/app_name"
    android:hardwareAccelerated="true">
    <activity android:name="Blah" android:label="@string/app_name"
            android:theme="@android:style/Theme.Black.NoTitleBar"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale">
        <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"/>
            <action android:name="android.intent.action.SEND_MULTIPLE"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <data android:mimeType="*/*"/>
        </intent-filter>
    </activity>
</application>

我的 index.js 如下所示:

window.plugins.webintent.getExtra(webintent.EXTRA_STREAM,
    function (url)
    {
        console.log('getExtra: EXTRA_STREAM');
        console.log(url);

    }, function()
    {
        console.log('getExtra: EXTRA_STREAM failed');
    });

我希望这是有用的。

为了完整起见,如果在阅读本文时还没有修复,您可以自己在 platforms/android/src/com/borismus/webintent 目录中手动应用更改。

建议的修复方法是将 WebIntent.java(第 94 行左右)更改为以下内容:

if (i.hasExtra(extraName)) {
    String r = i.getStringExtra(extraName);
    if (null === r) {
        r = ((Uri) i.getParcelableExtra(extraName)).toString();
    }

    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, r));
    return true;
}

关于android - 使用cordova将android图库中的图片分享到cordova应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23526502/

相关文章:

android - 使用 wget 从 RawGit 下载文件和文件夹

android - 通过在android中触摸在 Canvas 中拖动多个图像

ios - 从 UIBarButtonItem 触发 textFieldShouldReturn

ios - Restkit 发布不发送对象

java - Android 中单顶模式的 Intent 附加功能

Android studio 请求权限和 IMEI/MEID

android - 由于 Hilt 错误,应用程序未初始化

ios - 由于 CompileSwift 构建命令失败,Travis-CI 构建失败

Android 语言环境更改

java - 无法 Intent 下一个布局