份额从Android图库图片科尔多瓦应用程序中使用科尔多瓦 [英] Share the picture from android gallery to cordova app using cordova

查看:186
本文介绍了份额从Android图库图片科尔多瓦应用程序中使用科尔多瓦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以加我科尔多瓦的应用程序在共享接口,但我不就没怎么把那个共享图片在我的科尔多瓦的应用程序。

我用com.borismus.webintent插件

和我打电话低于deviceready code,但没有运气。

 函数startActivity(){
        警报('开始');
        window.plugins.webintent.startActivity({
            动作:window.plugins.webintent.ACTION_VIEW,
            网址:theFile.toURL()
            类型:应用程序/ vnd.android.package存档
        },
        函数(){警报('成功');},
        功能(){
            警报('无法通过Android的意图打开URL。');
            的console.log(无法通过Android的意图打开URL网址:。+ theFile.fullPath)
           }
          );
       }    功能广播(){
         window.plugins.webintent.sendBroadcast({
         动作:com.dummybroadcast.action.triggerthing',
         演员:{
              '选项':真
          }
         },功能(参数){
             警报(参数);
         },功能(参数){
             警报(参数);
       });
     }
    功能getURI(){
        window.plugins.webintent.getUri(函数(URL){
          如果(网址!==){
            // url是意图与推出的网址
            警报(URL);
          }
          其他{
            警报('ddfsdf');
          }
        });
      }

我的要求是在画廊,如果我在sahre点击图标,还有我的应用程序应该会出现,一旦我选择我的应用程序,我应该能够得到我的科尔多瓦的应用程序的形象。

我使用的科尔多瓦3.4.0,Android的

和我的Andr​​oidManifest.xml是

 <应用机器人:hardwareAccelerated =真正的机器人:图标=@绘制/图标机器人:标签=@字符串/ APP_NAME>
    <活动机器人:configChanges =方向| keyboardHidden |键盘|屏幕尺寸|区域机器人:标签=@字符串/ APP_NAME机器人:名字=分享安卓主题=@安卓风格/ Theme.Black.NoTitleBar >
        &所述;意图滤光器>
            <作用机器人:名字=android.intent.action.MAIN/>
            <类机器人:名字=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>
        &所述;意图滤光器>
            <作用机器人:名字=android.intent.action.SEND/>
            <类机器人:名字=android.intent.category.DEFAULT/>
            <作用机器人:名字=android.intent.action.SEND_MULTIPLE/>
            <数据机器人:mime类型=应用/ vnd.google.panorama360 + JPG/>
            <数据机器人:mime类型=图像/ */>
            <数据机器人:mime类型=视频/ */>
            <数据机器人:mime类型=text / plain的/>
        &所述; /意图滤光器>
      &所述;意图滤光器>
        <作用机器人:名字=com.creative.share.UNIQUESTRING/>
        <类机器人:名字=android.intent.category.DEFAULT/>
      &所述; /意图滤光器>
    < /活性GT;
  <活动机器人:名字=IntentTest机器人:标签=@字符串/ APP_NAME机器人:configChanges =方向| keyboardHidden>
    &所述;意图滤光器>
      <作用机器人:名字=android.intent.action.MAIN/>
      <类机器人:名字=android.intent.category.LAUNCHER/>
    &所述; /意图滤光器>
    &所述;意图滤光器>
      <作用机器人:名字=android.intent.action.VIEW>< /作用>
      <类机器人:名字=android.intent.category.DEFAULT>< /类别>
      <类机器人:名字=android.intent.category.BROWSABLE>< /类别>
      <数据机器人:主机=www.youtube.com机器人:计划=HTTP>< /数据>
    &所述; /意图滤光器>
  < /活性GT;
  <活动机器人:BrowserActivityNAME =机器人:标签=@字符串/ APP_NAME>
    &所述;意图滤光器>
      <作用机器人:名字=android.intent.action.VIEW/>
      <类机器人:名字=android.intent.category.DEFAULT/>
      <数据机器人:计划=HTTP/>
    &所述; /意图滤光器>
  < /活性GT;
    <供应商的android:当局=com.creative.share.plugin.emailcomposer.attachmentprovider机器人:名字=de.appplant.cordova.plugin.emailcomposer.AttachmentProvider/>
< /用途>


解决方案

我想我可以部分地回答这个问题。我相信,您要分享图片到你的应用程序,在那里你可以处理它。

在写这篇文章的时候,你所提到的插件中有一个错误,但是你可以尝试以下解决方法:的 https://github.com/Initsogar/cordova-webintent/issues/23

我的Andr​​oidManifest.xml中如下所示:

<应用机器人:图标=@绘制/图标机器人:标签=@字符串/ APP_NAME
    机器人:hardwareAccelerated =真正的>
    <活动机器人:名字=嗒嗒机器人:标签=@字符串/ APP_NAME
            机器人:主题=@安卓风格/ Theme.Black.NoTitleBar
            机器人:configChanges =方向| keyboardHidden |键盘|屏幕尺寸|区域>
        &所述;意图滤光器>
            <作用机器人:名字=android.intent.action.MAIN/>
            <类机器人:名字=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>
        &所述;意图滤光器>
            <作用机器人:名字=android.intent.action.SEND/>
            <作用机器人:名字=android.intent.action.SEND_MULTIPLE/>
            <类机器人:名字=android.intent.category.DEFAULT/>
            <数据机器人:mime类型=* / */>
        &所述; /意图滤光器>
    < /活性GT;
< /用途>

我的index.js看起来如下:

window.plugins.webintent.getExtra(webintent.EXTRA_STREAM,
    功能(URL)
    {
        的console.log('getExtra:EXTRA_STREAM');
        的console.log(URL);    },()的函数
    {
        的console.log('getExtra:EXTRA_STREAM失败');
    });

我希望这是有益的。

有关完整性,如果修订尚未被读取时拉,你可以自己手动应用更改的平台/安卓/ src目录/ COM / borismus / webintent。目录

建议的解决方法是改变WebIntent.java(约94行)于以下内容:

如果(i.hasExtra(extraName)){
    串R = i.getStringExtra(extraName);
    如果(空=== R){
        R =((URI)i.getParcelableExtra(extraName))的toString();
    }    callbackContext.sendPluginResult(新PluginResult(PluginResult.Status.OK,R));
    返回true;
}

I am able to add my cordova app in share interface, but i don't no how to bring that shared picture in my cordova application.

i used com.borismus.webintent plugin

and i am calling below code in deviceready,but no luck.

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

My requirement is in gallery if i click on sahre icon, there my application should appear and once i select my app , i should able to get that image in my cordova app.

I am using cordova 3.4.0, android

and my AndroidManifest.xml is

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

解决方案

I think I can partially answer this question. I believe that you are trying to share an image to your app, where you can process it.

At the time of writing, the plugin you mentioned has a bug in it, however you can try the following workaround: https://github.com/Initsogar/cordova-webintent/issues/23

My AndroidManifest.xml looks like the following:

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

My index.js looks like the following:

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

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

I hope this is useful.

For completeness, if the fix hasn't been pulled in by the time of reading, you can manually apply the change yourself in the platforms/android/src/com/borismus/webintent directory.

The suggested fix is to alter WebIntent.java (around line 94) to the following:

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图库图片科尔多瓦应用程序中使用科尔多瓦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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