Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems sharing images with Android(X) #1062

Open
vandres opened this issue Oct 4, 2019 · 9 comments
Open

Problems sharing images with Android(X) #1062

vandres opened this issue Oct 4, 2019 · 9 comments

Comments

@vandres
Copy link

vandres commented Oct 4, 2019

For one of our plugins I needed to upgrade all dependencies which also included cordova-android 8.1 and AndroidX.

Now we have trouble to get the sharing work on Android, if the share includes images. Without images, the share works fine.

this.socialSharing.shareWithOptions({
    subject: 'Subject',
    files: [base64Image],
    message: 'Message'
}))
Ionic:

   Ionic CLI          : 5.4.2 (/usr/local/lib/node_modules/ionic)
   Ionic Framework    : ionic-angular 3.9.8
   @ionic/app-scripts : 3.2.4

Cordova:

   Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
   Cordova Platforms : android 8.1.0, ios 5.0.1
   Cordova Plugins   : cordova-plugin-ionic 5.4.4, cordova-plugin-ionic-webview 4.1.2, (and 35 other plugins)

Utility:

   cordova-res : 0.6.0 (update available: 0.7.0)
   native-run  : 0.2.8 

System:

   ios-deploy : 1.9.4
   ios-sim    : 8.0.2
   NodeJS     : v10.16.3 (/usr/local/bin/node)
   npm        : 6.11.3
   OS         : macOS Mojave
   Xcode      : Xcode 11.0 Build version 11A420a

Plugins:
    "cordova": "^9.0.0",
    "cordova-android": "8.1.0",
    "cordova-background-geolocation": "3.2.2",
    "cordova-ios": "5.0.1",
    "cordova-plugin-add-swift-support": "^2.0.2",
    "cordova-plugin-advanced-http": "^2.2.0",
    "cordova-plugin-androidx": "^1.0.2",
    "cordova-plugin-androidx-adapter": "^1.1.0",
    "cordova-plugin-app-version": "^0.1.9",
    "cordova-plugin-appavailability": "^0.4.2",
    "cordova-plugin-background-fetch": "^5.6.0",
    "cordova-plugin-badge": "^0.8.8",
    "cordova-plugin-camera": "^4.1.0",
    "cordova-plugin-cocoalumberjack": "0.0.4",
    "cordova-plugin-device": "^1.1.7",
    "cordova-plugin-dialogs": "^1.3.4",
    "cordova-plugin-facebook4": "^6.1.0",
    "cordova-plugin-file": "^6.0.2",
    "cordova-plugin-file-transfer": "^1.7.1",
    "cordova-plugin-filepath": "^1.5.6",
    "cordova-plugin-firebase-analytics": "^2.0.4",
    "cordova-plugin-inappbrowser": "^2.0.0",
    "cordova-plugin-intercom": "^7.1.1",
    "cordova-plugin-ionic": "^5.4.4",
    "cordova-plugin-ionic-webview": "^4.1.2",
    "cordova-plugin-ios-disableshaketoedit": "^1.0.0",
    "cordova-plugin-local-notification": "^0.9.0-beta.2",
    "cordova-plugin-media": "^5.0.3",
    "cordova-plugin-nativestorage": "^2.3.2",
    "cordova-plugin-splashscreen": "^5.0.3",
    "cordova-plugin-statusbar": "^2.4.3",
    "cordova-plugin-stripe": "^1.5.3",
    "cordova-plugin-tts": "git+https://github.com/vandres/cordova-plugin-tts.git#patch-1",
    "cordova-plugin-vibration": "^3.1.1",
    "cordova-plugin-whitelist": "^1.3.4",
    "cordova-plugin-x-socialsharing": "^5.6.0",
    "cordova-plugin-zip": "^3.1.0",
    "cordova-support-android-plugin": "^1.0.1",
    "cordova-support-google-services": "^1.3.1",
@vandres
Copy link
Author

vandres commented Oct 4, 2019

I managed to remove AndroidX, but still no success.

@vandres
Copy link
Author

vandres commented Oct 4, 2019

I found the solution. In the current cordova there seems to be a bug, that when two plugins or the config.xml write to the same file and on the same node with edit-file or config-file, then configs may get lost. In this case we have written to /manifest/application and lost parts of your config.

@viking2917
Copy link

@vandres I have the same symptoms, (share works fine unless base64 images are passed in) but I have never used (and don't have installed) AndroidX. Were you able to get this working, and if so, did you have to do anything else besides remove AndroidX? Manual edits of AndroidManifest for example?

(for reference, my Ionic info)

Ionic:

   Ionic CLI         : 5.4.2 (/Users/markwatkins/.nvm/versions/node/v8.9.4/lib/node_modules/ionic)
   Ionic Framework   : ionic1 1.3.3
   @ionic/v1-toolkit : 1.0.8

Cordova:

   Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
   Cordova Platforms : android 8.0.0, browser 5.0.4
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.0.5, cordova-plugin-ionic-webview 1.1.1, (and 19 other plugins)

Utility:

   cordova-res : 0.6.0 (update available: 0.8.0)
   native-run  : 0.2.8 

System:

   Android SDK Tools : 26.1.1 (/Users/markwatkins/Library/Android/sdk)
   ios-deploy        : 1.9.4
   NodeJS            : v8.9.4 (/Users/markwatkins/.nvm/versions/node/v8.9.4/bin/node)
   npm               : 5.6.0
   OS                : macOS Mojave
   Xcode             : Xcode 11.1 Build version 11A1027

@vandres
Copy link
Author

vandres commented Oct 11, 2019

@viking2917 We had a edit-config entry in our config.xml:

<edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application">
    <application android:allowBackup="false" />
</edit-config>

Because the SocialPlugin also wants to write to this file, it gives a "conflict" (Bug) and only the config.xml changes will be taken. This is what the plugin.xml tries to do:

    <config-file target="AndroidManifest.xml" parent="/*/application">
      <receiver android:name="nl.xservices.plugins.ShareChooserPendingIntent" android:enabled="true">
        <intent-filter>
          <action android:name="android.intent.action.SEND"/>
        </intent-filter>
      </receiver>
    </config-file>

    <config-file target="AndroidManifest.xml" parent="/*">
      <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    </config-file>

    <config-file target="AndroidManifest.xml" parent="/manifest/application">
      <provider android:authorities="${applicationId}.sharing.provider" android:exported="false" android:grantUriPermissions="true" android:name="nl.xservices.plugins.FileProvider">
        <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/sharing_paths" />
      </provider>
    </config-file>

If you look into the generated AndroidManifest.xml in platforms/android, most of these things were missing for us. You can manually edit the AndroidManifest and it will work, we moved our changes to an own local plugin and are using hooks to manipulate the AndroidManifest after die Plugins are finished. The issue is described here and there is already a PR to fix it: apache/cordova-common#89

@viking2917
Copy link

@vandres thanks for the quick response! I will have a look and see if this fixes my issue.

@viking2917
Copy link

@vendres that did the trick, thank you!!! My AndroidManifest was missing the

 <provider android:authorities="${applicationId}.sharing.provider" android:exported="false" android:grantUriPermissions="true" android:name="nl.xservices.plugins.FileProvider">
        <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/sharing_paths" />
      </provider>

Manually adding that allowed images to share.

As it happens I had the email composer plugin which was conflicting. I don't use it any more, so I removed it, and then don't even need the manual edits.

Thanks!

@vandres
Copy link
Author

vandres commented Oct 11, 2019

Good to hear :)

@chandraahmad
Copy link

chandraahmad commented Sep 16, 2020

@viking2917 We had a edit-config entry in our config.xml:

<edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application">
    <application android:allowBackup="false" />
</edit-config>

Because the SocialPlugin also wants to write to this file, it gives a "conflict" (Bug) and only the config.xml changes will be taken. This is what the plugin.xml tries to do:

    <config-file target="AndroidManifest.xml" parent="/*/application">
      <receiver android:name="nl.xservices.plugins.ShareChooserPendingIntent" android:enabled="true">
        <intent-filter>
          <action android:name="android.intent.action.SEND"/>
        </intent-filter>
      </receiver>
    </config-file>

    <config-file target="AndroidManifest.xml" parent="/*">
      <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    </config-file>

    <config-file target="AndroidManifest.xml" parent="/manifest/application">
      <provider android:authorities="${applicationId}.sharing.provider" android:exported="false" android:grantUriPermissions="true" android:name="nl.xservices.plugins.FileProvider">
        <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/sharing_paths" />
      </provider>
    </config-file>

If you look into the generated AndroidManifest.xml in platforms/android, most of these things were missing for us. You can manually edit the AndroidManifest and it will work, we moved our changes to an own local plugin and are using hooks to manipulate the AndroidManifest after die Plugins are finished. The issue is described here and there is already a PR to fix it: apache/cordova-common#89

no that is not solution for me , because there is FILE_PROVIDER_PATHS on my androidmanifest and i cannot build or run my app on devices

@viking2917
Copy link

@chandraahmad I also had FILE_PROVIDER_PATHS in my androidmanifest; I am not quite sure why your situation might be different from mine. In any case it's been some time since I did this and I have forgotten the details; the main thing is, there does seem to be a bug where config.xml/plugin.xml declarations sometimes do not make their way into the final androidmanifest and in my case the solution was to hand edit the androidmanifest file (yuck) to make sure I had all needed declarations, solve the problem. Your needed edits might be different...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants