ani
ani

Reputation: 121

Share the picture from android gallery to cordova app using cordova

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, androidenter image description here

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>

Upvotes: 0

Views: 1686

Answers (1)

Mike
Mike

Reputation: 43

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

Upvotes: 2

Related Questions