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

Android targeting API Level 30 needs permission #1150

Open
GloriaTM opened this issue Aug 3, 2021 · 20 comments
Open

Android targeting API Level 30 needs permission #1150

GloriaTM opened this issue Aug 3, 2021 · 20 comments

Comments

@GloriaTM
Copy link

GloriaTM commented Aug 3, 2021

Hi!

My App with targetSdkVersion=30 crashed on Android 11 calling shareViaEmail with java.lang.ArrayIndexOutOfBoundsException

I think the reason is that you now need permission to have full access to the list of all installed apps:
https://medium.com/androiddevelopers/package-visibility-in-android-11-cc857f221cd9

Solution:
Add the following to AndroidManifest.xml
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />

  • or -

Adding following permission to config.xml to generate AndroidManifest.xml with this permission.

<config-file parent="/manifest" target="AndroidManifest.xml" xmlns:android="http://schemas.android.com/apk/res/android">
   <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
</config-file>

I hope this helps someone,
GTM

@wilywork
Copy link

wilywork commented Aug 6, 2021

thanks. Exception for google Search..

java.lang.ArrayIndexOutOfBoundsException:
at java.util.ArrayList.remove (ArrayList.java:506)
at nl.xservices.plugins.SocialSharing$1.run (SocialSharing.java:199)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:641)
at java.lang.Thread.run (Thread.java:923)

@Sampath-Lokuge
Copy link

Yes, this solve the issue on Android 11

AndroidManifest.xml
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />

@HarelM
Copy link

HarelM commented Oct 4, 2021

I'm facing the same issue.
Thanks for posting the solution here!
The bug is basically that the list is empty and trying to remove an item from an empty list causes the app to crash.
I don't mind sending a PR to either check for an empty list and raise a toast or add the relevant permission to the manifest.
This plugin serves me really well and I'd like to contribute back a bit :-)

@HarelM
Copy link

HarelM commented Oct 27, 2021

Not sure I can help, I added the permission and it solved my issue, you'll probably need to debug and see where it fails... That's what I did...

@naushad-madakiya
Copy link

@chrisjdev when this fix will be released for cordova? https://www.npmjs.com/package/cordova-plugin-x-socialsharing

@chrisjdev
Copy link

chrisjdev commented Apr 25, 2022

@chrisjdev when this fix will be released for cordova? https://www.npmjs.com/package/cordova-plugin-x-socialsharing

@mad-na Sorry, in my comment referencing this issue, I was saying my change didn't completely solve the issue, so I wasn't planning to do a pull request. Also, for other reasons, I'm planning to switch to using share() instead of shareViaEmail(), so I likely won't spend any more time on this.

@HarelM
Copy link

HarelM commented Apr 29, 2022

Also worth mentioning that the solution to add a permission requires adding an explanation in the google play store as can be read here:
https://support.google.com/googleplay/android-developer/answer/9888170
This is the solution I went with as it didn't need any change in the plugin code to fix this.
I'm no longer sure, due to the above google restriction, that this is the right solution.
Having said that, I'm not sure what is the right solution in this case...

@GloriaTM
Copy link
Author

GloriaTM commented May 1, 2022

@HarelM Yes, setting global permission is therefore no longer a good option.

I have struggled through this (and ended up with @bhandaribhuminpfizer solution):

  1. Remove <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />

  2. add to config.xml:

 <config-file parent="/manifest" target="AndroidManifest.xml">
            <queries>
                <intent>
                    <action android:name="android.intent.action.SENDTO" />
                    <data android:scheme="mailto" />
                </intent>
            </queries>
        </config-file>
  1. Remove android platform and add it again to generate AndroidManifest.xml correctly:
cordova platform remove android
cordova platform add android

Tested with corova-android 9.1.0 on Android 10 and Android 11

Feedback is welcome

@HarelM
Copy link

HarelM commented May 2, 2022

@GloriaTM thanks for the info!!
I've tested this and it seems to work as expected in android 12 and 11.
Thanks!!

@plakerco
Copy link

plakerco commented Aug 16, 2022

In my case this works:

Procedure like @GloriaTM posted, but in config.xml:

<platform name="android">
  ...
    <config-file parent="/manifest" target="AndroidManifest.xml" xmlns:android="http://schemas.android.com/apk/res/android">
        <queries>
            <intent>
                <action android:name="android.intent.action.SENDTO" />
                <data android:scheme="mailto" />
            </intent>
        </queries>
    </config-file>
</platform>

Tested with cordova-android@11.0.0 on real Android 8.1 (API 27), Android 11 (API 30) and Android 12 (API 31) devices

@SailingSteve
Copy link

For me, I just removed the namespace tags, and it worked:

           <config-file parent="/manifest" target="AndroidManifest.xml">
                <queries>
                    <intent>
                        <action name="android.intent.action.SENDTO" />
                       <data scheme="mailto" />
                   </intent>
               </queries>
        </config-file>

@leorsida
Copy link

To sharing on Fb and email with Android 12, i need to add fb package

<config-file parent="/manifest" target="AndroidManifest.xml"> <queries> <intent> <action name="android.intent.action.SENDTO" /> <data scheme="mailto" /> </intent> <package android:name="com.facebook.katana" /> </queries> </config-file>

@tavojavi
Copy link

tavojavi commented Oct 7, 2022

@HarelM Yes, setting global permission is therefore no longer a good option.

I have struggled through this (and ended up with @bhandaribhuminpfizer solution):

  1. Remove <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
  2. add to config.xml:
 <config-file parent="/manifest" target="AndroidManifest.xml">
            <queries>
                <intent>
                    <action android:name="android.intent.action.SENDTO" />
                    <data android:scheme="mailto" />
                </intent>
            </queries>
        </config-file>
  1. Remove android platform and add it again to generate AndroidManifest.xml correctly:
cordova platform remove android
cordova platform add android

Tested with corova-android 9.1.0 on Android 10 and Android 11

Feedback is welcome

This worked for me! Thanks!

@Sampath-Lokuge
Copy link

Ionic/Angular/Capacitor app:

\android\app\src\main\AndroidManifest.xml

I have removed <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />

and added this:

<queries>
           <intent>
            <action android:name="android.intent.action.SENDTO" />
            <data android:scheme="mailto" />
        </intent>
    </queries>

@durgamalleswariyeruva
Copy link

Still, it is not working in android 12 and above devices. app is getting crashed

@HarelM
Copy link

HarelM commented Jul 6, 2023

I have a working app targeted to Android 13.
I don't know if I'm doing something different, but it's working for me.
If it helps, the following is my repo:
https://github.com/IsraelHikingMap/Site/tree/3997912dc56df39cd84a6100c06241364eab7d05/IsraelHiking.Web

@durgamalleswariyeruva
Copy link

durgamalleswariyeruva commented Jul 6, 2023

Thanks for the quick response. Currently, I am using angular 12.1.4 and cordova -11. It was working fine in ios. In android, greater than 11 android versions getting crashed.
this.socialSharing.shareViaEmail(body, subject, []).then(()=>{
});
app was closing automatically after calling then()

Error:
java.lang.ArrayIndexOutOfBoundsException:
at java.util.ArrayList.remove (ArrayList.java:506)
at nl.xservices.plugins.SocialSharing$1.run (SocialSharing.java:199)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:641)
at java.lang.Thread.run (Thread.java:923)

@HarelM
Copy link

HarelM commented Jul 6, 2023

Did you follow the above suggestion?
#1150 (comment)
Here's my commit that solved this:
IsraelHikingMap/Site@bb95028
I believed this crashed for me too before this fix.

@durgamalleswariyeruva
Copy link

I tried to update social-sharing plugin -6.3.0 and also followed the above procedure which you suggested.Still, no luck in result.

@GMuthuraja
Copy link

Hi!

My App with targetSdkVersion=30 crashed on Android 11 calling shareViaEmail with java.lang.ArrayIndexOutOfBoundsException

I think the reason is that you now need permission to have full access to the list of all installed apps: https://medium.com/androiddevelopers/package-visibility-in-android-11-cc857f221cd9

Solution: Add the following to AndroidManifest.xml <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />

  • or -

Adding following permission to config.xml to generate AndroidManifest.xml with this permission.

<config-file parent="/manifest" target="AndroidManifest.xml" xmlns:android="http://schemas.android.com/apk/res/android">
   <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
</config-file>

I hope this helps someone, GTM

If you add this persmission in Manifest file, app may got rejected due to the play console policy.
Please refer below link for complete fixes...
https://stackoverflow.com/a/73151052

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