【问题标题】:Share the picture from android gallery to cordova app using cordova使用cordova将图片从android画廊分享到cordova应用程序
【发布时间】:2014-05-07 19:21:59
【问题描述】:

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

我使用了 com.borismus.webintent 插件

我正在设备中调用下面的代码,但没有运气。

     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

我的 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>

【问题讨论】:

    标签: android ios android-intent cordova cordova-plugins


    【解决方案1】:

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

    在撰写本文时,您提到的插件存在错误,但是您可以尝试以下解决方法: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;
    }
    

    【讨论】:

    • 它可以用于多张图片共享吗?因为当我选择多个图像并单击共享图标时,我的应用程序变得可见,但它没有向应用程序提供内容并抛出“尝试调用虚拟方法'java.lang.String android.net.Uri.toString()' on空对象引用”错误。它适用于单个图像共享。请帮帮我。
    • 嘿@Mr_Green,我真的不知道。您最好在原始 GitHub 存储库上提出这个问题:github.com/Initsogar/cordova-webintent/issues/23
    猜你喜欢
    • 1970-01-01
    • 2016-02-17
    • 2012-03-11
    • 2021-06-02
    • 1970-01-01
    • 2015-09-09
    • 1970-01-01
    • 2020-02-06
    • 1970-01-01
    相关资源
    最近更新 更多