Reputation: 2609
My app has sharing functionality that stopped working in Android 11, and I don't know why. It works perfectly for any Android <= 10. My app targets API 29 to try not to fall into scoped storage problems. Sorry if this is well known by now, but I am basically ignorant regarding scoped storage.
The app folder in the external sdcard is /storage/58ED-1620/Android/data/com.floritfoto.apps.ave/
. Inside this folder I have a bunch of other folders.
If I try to share the file /storage/58ED-1620/Android/data/com.floritfoto.apps.ave/ornitologia/MyTracks/ave_140321_103008.csv
, say via WhatsApp, the file is not sent, and this is the logcat (>=Warn):
(EDIT: It seems I can share the file if it is inside the files/
folder?!)
18:26:08.468 15827-15827/? W/adbd: timeout expired while flushing socket, closing
18:26:09.472 803-1100/? E/BufferQueueProducer: [com.floritfoto.apps.ave/com.floritfoto.apps.xvf.FileChooser$_13168#1](id:323000009a3,api:0,p:-1,c:803) disconnect: not connected (req=1)
18:26:09.472 13168-14775/com.floritfoto.apps.ave W/libEGL: EGLNativeWindowType 0x708d001ec0 disconnect failed
18:26:09.495 736-758/? E/HYPER-HAL: [HandlerSysfs.cpp]doResourceHandling(): Couldn't Open Sysfs - /sys/power/cstate_control
18:26:09.498 736-758/? E/HYPER-HAL: [HandlerSysfs.cpp]doResourceHandling(): Couldn't Open Sysfs - /sys/power/cstate_control
18:26:09.501 1117-1257/? W/ActivityTaskManager: Tried to set launchTime (0) < mLastActivityLaunchTime (53651559)
18:26:09.504 1117-1257/? W/WindowManager: Execute app transition: mNextAppTransition=TRANSIT_ACTIVITY_OPEN, displayId: 0 Callers=com.android.server.wm.RootWindowContainer.executeAppTransitionForAllDisplay:2586 com.android.server.wm.ActivityStackSupervisor.reportResumedActivityLocked:2225 com.android.server.wm.ActivityRecord.completeResumeLocked:5646 com.android.server.wm.ActivityStack.minimalResumeActivityLocked:1212 com.android.server.wm.ActivityStackSupervisor.realStartActivityLocked:1135
18:26:09.512 5471-5471/? W/ChooserActivity: Ignoring intent's EXTRA_TITLE, deprecated in P. You may wish to set a preview title by using EXTRA_TITLE property of the wrapped EXTRA_INTENT.
18:26:09.512 1117-1379/? W/PkgPredictorService: background app without no launcher icon android for.uid: 1000 userId: 0
18:26:09.513 5471-5471/? E/ActivityThread: Failed to find provider info for com.samsung.android.app.sharestar.ShareStarProvider
18:26:09.560 1117-3258/? E/IntervalStats: Unable to parse usage stats package 1041
18:26:09.560 1117-3258/? E/IntervalStats: Unable to parse usage stats package 1520
18:26:09.560 1117-3258/? E/IntervalStats: Unable to parse usage stats package 1997
18:26:09.618 13168-14876/com.floritfoto.apps.ave E/DatabaseUtils: Writing exception to parcel
java.lang.SecurityException: Permission Denial: reading androidx.core.content.FileProvider uri content://com.floritfoto.apps.ave.provider/root/storage/58ED-1620/Android/data/com.floritfoto.apps.ave/ornitologia/MyTracks/ave_140321_103008.csv from pid=5471, uid=1000 requires the provider be exported, or grantUriPermission()
at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:841)
at android.content.ContentProvider.semEnforceReadPermission(ContentProvider.java:758)
at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:684)
at android.content.ContentProvider$Transport.query(ContentProvider.java:239)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:106)
at android.os.Binder.execTransactInternal(Binder.java:1190)
at android.os.Binder.execTransact(Binder.java:1159)
18:26:09.618 5471-5471/? W/ChooserActivity: Could not load (content://com.floritfoto.apps.ave.provider/root/storage/58ED-1620/Android/data/com.floritfoto.apps.ave/ornitologia/MyTracks/ave_140321_103008.csv) thumbnail/name for preview. If desired, consider using Intent#createChooser to launch the ChooserActivity, and set your Intent's clipData and flags in accordance with that method's documentation
18:26:09.619 2498-3360/? W/NearbySharing: Ignore registering DIRECT_SHARE_SERVICE send surface, due to disabled scanning mediums. [CONTEXT service_id=194 ]
18:26:09.619 2498-3360/? W/NearbySharing: NearbySharingService call registerSendSurface returned nonzero status code for calling package com.google.android.gms: STATUS_DISABLED [CONTEXT service_id=194 ]
18:26:09.643 1117-1145/? E/WindowManager: win=Window{a0df760 u0 com.floritfoto.apps.ave/com.floritfoto.apps.xvf.FileChooser EXITING} destroySurfaces: appStopped=false win.mWindowRemovalAllowed=true win.mRemoveOnExit=true win.mViewVisibility=0 caller=com.android.server.wm.ActivityRecord.destroySurfaces:5183 com.android.server.wm.ActivityRecord.destroySurfaces:5164 com.android.server.wm.WindowState.onExitAnimationDone:5570 com.android.server.wm.WindowStateAnimator.onAnimationFinished:332 com.android.server.wm.WindowState.onAnimationFinished:6035 com.android.server.wm.-$$Lambda$dwJG8BAnLlvKNGuDY9U3-haNY4M.onAnimationFinished:2 com.android.server.wm.SurfaceAnimator.lambda$getFinishedCallback$0$SurfaceAnimator:112
18:26:09.668 5471-5471/? W/View: requestLayout() improperly called by com.android.internal.widget.RecyclerView{d6a7c8a VFED..... ......ID 0,0-1289,1011 #102047e android:id/resolver_list} during layout: running second layout pass
18:26:09.671 13168-14876/com.floritfoto.apps.ave E/DatabaseUtils: Writing exception to parcel
java.lang.SecurityException: Permission Denial: reading androidx.core.content.FileProvider uri content://com.floritfoto.apps.ave.provider/root/storage/58ED-1620/Android/data/com.floritfoto.apps.ave/ornitologia/MyTracks/ave_140321_103008.csv from pid=5471, uid=1000 requires the provider be exported, or grantUriPermission()
at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:841)
at android.content.ContentProvider.semEnforceReadPermission(ContentProvider.java:758)
at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:684)
at android.content.ContentProvider$Transport.query(ContentProvider.java:239)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:106)
at android.os.Binder.execTransactInternal(Binder.java:1190)
at android.os.Binder.execTransact(Binder.java:1159)
18:26:09.672 5471-5471/? W/ChooserActivity: Could not load (content://com.floritfoto.apps.ave.provider/root/storage/58ED-1620/Android/data/com.floritfoto.apps.ave/ornitologia/MyTracks/ave_140321_103008.csv) thumbnail/name for preview. If desired, consider using Intent#createChooser to launch the ChooserActivity, and set your Intent's clipData and flags in accordance with that method's documentation
18:26:09.714 803-1100/? E/BufferQueueProducer: [com.floritfoto.apps.ave/com.floritfoto.apps.xvf.FileChooser$_13168#0](id:323000009a1,api:0,p:-1,c:803) disconnect: not connected (req=1)
18:26:09.714 13168-14775/com.floritfoto.apps.ave W/libEGL: EGLNativeWindowType 0x708cee8e80 disconnect failed
18:26:09.729 736-758/? E/HYPER-HAL: [HandlerSysfs.cpp]doResourceHandling(): Couldn't Open Sysfs - /sys/power/cstate_control
18:26:09.730 736-758/? E/HYPER-HAL: [Request.cpp]acquire(): Request:: id : 648112, No Resource to set
18:26:09.730 2339-2339/? E/pageboostd: Received HALT command code 2
18:26:09.730 736-758/? E/HYPER-HAL: [HandlerSysfs.cpp]doResourceHandling(): Couldn't Open Sysfs - /sys/power/cstate_control
18:26:09.731 803-823/? E/BufferQueueProducer: [android/com.android.internal.app.ChooserActivity$_5471#0](id:323000009a4,api:0,p:-1,c:803) disconnect: not connected (req=1)
18:26:09.731 5471-6304/? W/libEGL: EGLNativeWindowType 0x708cf88930 disconnect failed
18:26:09.749 13168-14938/com.floritfoto.apps.ave E/DatabaseUtils: Writing exception to parcel
java.lang.SecurityException: Permission Denial: reading androidx.core.content.FileProvider uri content://com.floritfoto.apps.ave.provider/root/storage/58ED-1620/Android/data/com.floritfoto.apps.ave/ornitologia/MyTracks/ave_140321_103008.csv from pid=5471, uid=1000 requires the provider be exported, or grantUriPermission()
at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:841)
at android.content.ContentProvider.semEnforceReadPermission(ContentProvider.java:758)
at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:684)
at android.content.ContentProvider$Transport.query(ContentProvider.java:239)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:106)
at android.os.Binder.execTransactInternal(Binder.java:1190)
at android.os.Binder.execTransact(Binder.java:1159)
18:26:09.749 5471-5471/? W/ChooserActivity: Could not load (content://com.floritfoto.apps.ave.provider/root/storage/58ED-1620/Android/data/com.floritfoto.apps.ave/ornitologia/MyTracks/ave_140321_103008.csv) thumbnail/name for preview. If desired, consider using Intent#createChooser to launch the ChooserActivity, and set your Intent's clipData and flags in accordance with that method's documentation
18:26:09.888 5471-6332/? E/SharedPreferencesImpl: Couldn't create directory for SharedPreferences file /data/system/shared_prefs/com.android.internal.app.ChooserActivity.xml
18:26:10.028 727-1236/? E/Sensors: Sensor : Meta event
18:26:10.030 736-17022/? E/HYPER-HAL: [HandlerSysfs.cpp]doResourceHandling(): Couldn't Open Sysfs - /sys/power/cstate_control
18:26:10.228 1452-1452/? E/ExpandableNotifRow: onNotificationUpdated() NSSL is null..
18:26:10.499 736-17015/? E/HYPER-HAL: [HandlerSysfs.cpp]doResourceHandling(): Couldn't Open Sysfs - /sys/power/cstate_control
As you can see, I get 3 times (why 3??) Permission Denial: ... requires the provider be exported, or grantUriPermission()
. But my sharing activity not only sets the flag Intent.FLAG_GRANT_READ_URI_PERMISSION
, but also this is present in the provider section of the manifest file as android:grantUriPermissions="true"
.
What is even stranger is that I can share files in the sdcard outside of the app folder or in subfolders (???!!!). For example, I can share the file /storage/58ED-1620/System Volume Information/WPSettings.dat
. Look at the logcat, even with the same 3 errors, but the file is sent:
18:29:50.302 803-824/? E/BufferQueueProducer: [com.floritfoto.apps.ave/com.floritfoto.apps.xvf.FileChooser$_13168#1](id:323000009a8,api:0,p:-1,c:803) disconnect: not connected (req=1)
18:29:50.302 13168-14775/com.floritfoto.apps.ave W/libEGL: EGLNativeWindowType 0x708d001ec0 disconnect failed
18:29:50.325 736-758/? E/HYPER-HAL: [HandlerSysfs.cpp]doResourceHandling(): Couldn't Open Sysfs - /sys/power/cstate_control
18:29:50.328 736-758/? E/HYPER-HAL: [HandlerSysfs.cpp]doResourceHandling(): Couldn't Open Sysfs - /sys/power/cstate_control
18:29:50.331 1117-2951/? W/ActivityTaskManager: Tried to set launchTime (0) < mLastActivityLaunchTime (54810092)
18:29:50.333 1117-2951/? W/WindowManager: Execute app transition: mNextAppTransition=TRANSIT_ACTIVITY_OPEN, displayId: 0 Callers=com.android.server.wm.RootWindowContainer.executeAppTransitionForAllDisplay:2586 com.android.server.wm.ActivityStackSupervisor.reportResumedActivityLocked:2225 com.android.server.wm.ActivityRecord.completeResumeLocked:5646 com.android.server.wm.ActivityStack.minimalResumeActivityLocked:1212 com.android.server.wm.ActivityStackSupervisor.realStartActivityLocked:1135
18:29:50.340 5471-5471/? W/ChooserActivity: Ignoring intent's EXTRA_TITLE, deprecated in P. You may wish to set a preview title by using EXTRA_TITLE property of the wrapped EXTRA_INTENT.
18:29:50.342 1117-1379/? W/PkgPredictorService: background app without no launcher icon android for.uid: 1000 userId: 0
18:29:50.343 5471-5471/? E/ActivityThread: Failed to find provider info for com.samsung.android.app.sharestar.ShareStarProvider
18:29:50.387 1117-1135/? E/IntervalStats: Unable to parse usage stats package 1041
18:29:50.387 1117-1135/? E/IntervalStats: Unable to parse usage stats package 1520
18:29:50.387 1117-1135/? E/IntervalStats: Unable to parse usage stats package 1997
18:29:50.436 2498-3360/? W/NearbySharing: Ignore registering DIRECT_SHARE_SERVICE send surface, due to disabled scanning mediums. [CONTEXT service_id=194 ]
18:29:50.436 2498-3360/? W/NearbySharing: NearbySharingService call registerSendSurface returned nonzero status code for calling package com.google.android.gms: STATUS_DISABLED [CONTEXT service_id=194 ]
18:29:50.438 13168-14876/com.floritfoto.apps.ave E/DatabaseUtils: Writing exception to parcel
java.lang.SecurityException: Permission Denial: reading androidx.core.content.FileProvider uri content://com.floritfoto.apps.ave.provider/root/storage/58ED-1620/System%20Volume%20Information/WPSettings.dat from pid=5471, uid=1000 requires the provider be exported, or grantUriPermission()
at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:841)
at android.content.ContentProvider.semEnforceReadPermission(ContentProvider.java:758)
at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:684)
at android.content.ContentProvider$Transport.query(ContentProvider.java:239)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:106)
at android.os.Binder.execTransactInternal(Binder.java:1190)
at android.os.Binder.execTransact(Binder.java:1159)
18:29:50.438 5471-5471/? W/ChooserActivity: Could not load (content://com.floritfoto.apps.ave.provider/root/storage/58ED-1620/System%20Volume%20Information/WPSettings.dat) thumbnail/name for preview. If desired, consider using Intent#createChooser to launch the ChooserActivity, and set your Intent's clipData and flags in accordance with that method's documentation
18:29:50.466 1117-1145/? E/WindowManager: win=Window{19b8866 u0 com.floritfoto.apps.ave/com.floritfoto.apps.xvf.FileChooser EXITING} destroySurfaces: appStopped=false win.mWindowRemovalAllowed=true win.mRemoveOnExit=true win.mViewVisibility=0 caller=com.android.server.wm.ActivityRecord.destroySurfaces:5183 com.android.server.wm.ActivityRecord.destroySurfaces:5164 com.android.server.wm.WindowState.onExitAnimationDone:5570 com.android.server.wm.WindowStateAnimator.onAnimationFinished:332 com.android.server.wm.WindowState.onAnimationFinished:6035 com.android.server.wm.-$$Lambda$dwJG8BAnLlvKNGuDY9U3-haNY4M.onAnimationFinished:2 com.android.server.wm.SurfaceAnimator.lambda$getFinishedCallback$0$SurfaceAnimator:112
18:29:50.494 5471-5471/? W/View: requestLayout() improperly called by com.android.internal.widget.RecyclerView{9370694 VFED..... ......ID 0,0-1289,1011 #102047e android:id/resolver_list} during layout: running second layout pass
18:29:50.497 13168-14876/com.floritfoto.apps.ave E/DatabaseUtils: Writing exception to parcel
java.lang.SecurityException: Permission Denial: reading androidx.core.content.FileProvider uri content://com.floritfoto.apps.ave.provider/root/storage/58ED-1620/System%20Volume%20Information/WPSettings.dat from pid=5471, uid=1000 requires the provider be exported, or grantUriPermission()
at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:841)
at android.content.ContentProvider.semEnforceReadPermission(ContentProvider.java:758)
at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:684)
at android.content.ContentProvider$Transport.query(ContentProvider.java:239)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:106)
at android.os.Binder.execTransactInternal(Binder.java:1190)
at android.os.Binder.execTransact(Binder.java:1159)
18:29:50.498 5471-5471/? W/ChooserActivity: Could not load (content://com.floritfoto.apps.ave.provider/root/storage/58ED-1620/System%20Volume%20Information/WPSettings.dat) thumbnail/name for preview. If desired, consider using Intent#createChooser to launch the ChooserActivity, and set your Intent's clipData and flags in accordance with that method's documentation
18:29:50.553 736-758/? E/HYPER-HAL: [HandlerSysfs.cpp]doResourceHandling(): Couldn't Open Sysfs - /sys/power/cstate_control
18:29:50.553 736-758/? E/HYPER-HAL: [Request.cpp]acquire(): Request:: id : 648112, No Resource to set
18:29:50.553 736-758/? E/HYPER-HAL: [HandlerSysfs.cpp]doResourceHandling(): Couldn't Open Sysfs - /sys/power/cstate_control
18:29:50.554 803-1997/? E/BufferQueueProducer: [android/com.android.internal.app.ChooserActivity$_5471#0](id:323000009a9,api:0,p:-1,c:803) disconnect: not connected (req=1)
18:29:50.554 5471-6304/? W/libEGL: EGLNativeWindowType 0x708cf6ac50 disconnect failed
18:29:50.557 2339-2339/? E/pageboostd: Received HALT command code 2
18:29:50.569 13168-14876/com.floritfoto.apps.ave E/DatabaseUtils: Writing exception to parcel
java.lang.SecurityException: Permission Denial: reading androidx.core.content.FileProvider uri content://com.floritfoto.apps.ave.provider/root/storage/58ED-1620/System%20Volume%20Information/WPSettings.dat from pid=5471, uid=1000 requires the provider be exported, or grantUriPermission()
at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:841)
at android.content.ContentProvider.semEnforceReadPermission(ContentProvider.java:758)
at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:684)
at android.content.ContentProvider$Transport.query(ContentProvider.java:239)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:106)
at android.os.Binder.execTransactInternal(Binder.java:1190)
at android.os.Binder.execTransact(Binder.java:1159)
18:29:50.569 5471-5471/? W/ChooserActivity: Could not load (content://com.floritfoto.apps.ave.provider/root/storage/58ED-1620/System%20Volume%20Information/WPSettings.dat) thumbnail/name for preview. If desired, consider using Intent#createChooser to launch the ChooserActivity, and set your Intent's clipData and flags in accordance with that method's documentation
18:29:50.703 5471-6332/? E/SharedPreferencesImpl: Couldn't create directory for SharedPreferences file /data/system/shared_prefs/com.android.internal.app.ChooserActivity.xml
18:29:50.725 727-1236/? E/Sensors: Sensor : Meta event
18:29:50.853 736-17345/? E/HYPER-HAL: [HandlerSysfs.cpp]doResourceHandling(): Couldn't Open Sysfs - /sys/power/cstate_control
18:29:50.919 1452-1452/? E/ExpandableNotifRow: onNotificationUpdated() NSSL is null..
18:29:51.329 736-17338/? E/HYPER-HAL: [HandlerSysfs.cpp]doResourceHandling(): Couldn't Open Sysfs - /sys/power/cstate_control
I fail to see anything really different between the two logcats!
I have no idea why this began happening in Android 11. What am I doing wrong? Has this something to do with Scoped Storage? Should I migrate to Scoped Storage?
This is the file sharing method:
public static void sharefile(Context context, String calledfrom, String filename) {
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
sharingIntent.putExtra(Intent.EXTRA_STREAM, (new SearchOut()).getUriFromFile(context, calledfrom, new File(filename)));
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, FName.file(filename));
sharingIntent.setType((new FileChooser()).getMimeType(filename));
context.startActivity(Intent.createChooser(sharingIntent, filename));
}
EDIT: In the above, the getUriFromFile
method is essentially the usual one for Android >=7: FileProvider.getUriForFile(context, auth + ".provider", file);
.
This is my provider data in the manifest:
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
and this is my provider_paths.xml
:
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path name="external_files" path="." />
<root-path name="root" path="." />
</paths>
Upvotes: 0
Views: 1434
Reputation: 2609
This is not a true solution, but a silly workaround. Sorry.
It seems that in Android 11 we cannot share files from the app own files in the external removable micro sdcard storage through FileProvider: the trick
<root-path name="root" path="." />
in the provider paths .xml file does not work anymore for the own app's folder in the removable storage (thanks @blackapps !). (Yet, it still works for the other folders in the removable storage, besides the ones in Android/data and Android/obb).
So my coward workaround is to copy the file to share into the app's Cache folder in the main storage ContextCompat.getExternalCacheDirs(context)[0]
, and share the file from there. When the app closes, I remove this file from cache. :/
Upvotes: 1