Can you download a messsging app for android

August 25, 2021 / Rating: 4.6 / Views: 657

Related Images "Can you download a messsging app for android" (42 pics):

Chrome won't download files android

Lets say I'm developing a chat app that is able to share with others ANY kind of files (no mimetype restriction): like images, videos, documents, but also compressed files like zip, rar, apk or even less frequent types of files like photoshop or autocad files, for example. In Android 9 or lower I directly download those files to Download directory, but that's now impossible in Android 10 without showing an Intent to the user to ask where to download them... but then why Google Chrome or other browsers are able to do that? They in fact still download files to Download directory without asking user in Android 10. I first analyzed Whatsapp to see how they achieve it but they make use of request Legacy External Storage attribute on Android Manifest. But then I analyzed Chrome and it targets Android 10 without using request Legacy External Storage. I have been googling for some days already how apps can download a file directly to Download directory on Android 10 (Q) without having to ask user where to place it, the same way Chrome does. I have read android for developers documentation, lots of questions on Stackoverflow, blog posts over the Internet and Google Groups but still I haven't found a way to keep doing exactly the same as in Android 9 nor even a solution that plenty satisfies me. What I've tried so far: My temporary solution: I've found a workaround that makes it possible to download wherever you want without adding request Legacy External Storage="false". It consists on obtaining an Uri from a File object by using: val download Dir = External Storage Public Directory(Environment. DIRECTORY_DOWNLOADS) val file = File(download Dir, file Name) val authority = "$.provider" val accessible Uri = File Uri For File(context, authority, file) The problem: It make use of get External Storage Public Directory method which is deprecated as of Android Q and extremmely likely will be removed on Android 11. You could think that you can make your own path manually as you know the real path (/storage/emulated/0/Download/) and keep creating a File object, but what if Google decices to change Download directory path on Android 11? I'm afraid this is not a long term solution, so My question: How can I achieve this without using a deprecated method? EXTERNAL_CONTENT_URI and save a file by using Content Resolver.insert()" is supposed to be the solution. And a bonus question How the hell Google Chrome accomplish getting access to Download directory? I double checked and found out this is true and I was wrong saying it doesn't work. I found it tricky to use Content Resolver and I was unable to make it work properly. More than 10 months have passed and yet not a satisfying answer for me have been made. As @Commons Ware states in a comment, "get Media Store. I'll make a separate question with it but I kept investigating and found a somehow satisfying solution. MY SOLUTION: Basically you have to download to any directory owned by your app and then copy to Downloads folder. From Android 10/ Q and above it will not need any permission (it seems it handle the permission itself). If you want to open the file afterwards, you will need the user's permission instead (also if you only want to open it within an external app (e.g. You can use the download manager like this: ); Request Header("Accept", "application/pdf"); // Save the file in the "Downloads" folder of SDCARD Destination In External Public Dir(Environment. DIRECTORY_DOWNLOADS,filename); Download Manager download Manager = (Download Manager) get Activity()System Service(Context. String) https://developer.android.com/training/data-storage I thought that it would best be to write the answer in java, as a lot of legacy code exists out there which would have to be updated. DOWNLOAD_SERVICE); download Manager.enqueue(request); This are the references: https://developer.android.com/reference/kotlin/android/app/Download Manager. hl=en#set Destination In External Public Dir(kotlin. Also I have no idea what kind of file you want to store and so, here, I took an example of a bitmap. If you want to save any other kind of file you just have to create an Output Stream of it, and for the remaining part of it you can follow the code I write below. Now, here, this function is only going to handle the saving for Android 10 and hence the annotation. I hope you have the prerequisite knowledge on how to save files in lower android versions This will create a folder named "Folder Name" and store "Test.jpg" inside that folder. Also do note this doesn't require any permissions in the manifest which implies it doesn't need runtime permissions as well. If you want the Kotlin version do ask me in the comments. I would happily and readily provide the Kotlin method for the same. Lets say I'm developing a chat app that is able to share with others ANY kind of files (no mimetype restriction): like images, videos, documents, but also compressed files like zip, rar, apk or even less frequent types of files like photoshop or autocad files, for example. In Android 9 or lower I directly download those files to Download directory, but that's now impossible in Android 10 without showing an Intent to the user to ask where to download them... but then why Google Chrome or other browsers are able to do that? They in fact still download files to Download directory without asking user in Android 10. I first analyzed Whatsapp to see how they achieve it but they make use of request Legacy External Storage attribute on Android Manifest. But then I analyzed Chrome and it targets Android 10 without using request Legacy External Storage. I have been googling for some days already how apps can download a file directly to Download directory on Android 10 (Q) without having to ask user where to place it, the same way Chrome does. I have read android for developers documentation, lots of questions on Stackoverflow, blog posts over the Internet and Google Groups but still I haven't found a way to keep doing exactly the same as in Android 9 nor even a solution that plenty satisfies me. What I've tried so far: My temporary solution: I've found a workaround that makes it possible to download wherever you want without adding request Legacy External Storage="false". It consists on obtaining an Uri from a File object by using: val download Dir = External Storage Public Directory(Environment. DIRECTORY_DOWNLOADS) val file = File(download Dir, file Name) val authority = "$.provider" val accessible Uri = File Uri For File(context, authority, file) The problem: It make use of get External Storage Public Directory method which is deprecated as of Android Q and extremmely likely will be removed on Android 11. You could think that you can make your own path manually as you know the real path (/storage/emulated/0/Download/) and keep creating a File object, but what if Google decices to change Download directory path on Android 11? I'm afraid this is not a long term solution, so My question: How can I achieve this without using a deprecated method? EXTERNAL_CONTENT_URI and save a file by using Content Resolver.insert()" is supposed to be the solution. And a bonus question How the hell Google Chrome accomplish getting access to Download directory? I double checked and found out this is true and I was wrong saying it doesn't work. I found it tricky to use Content Resolver and I was unable to make it work properly. More than 10 months have passed and yet not a satisfying answer for me have been made. As @Commons Ware states in a comment, "get Media Store. I'll make a separate question with it but I kept investigating and found a somehow satisfying solution. MY SOLUTION: Basically you have to download to any directory owned by your app and then copy to Downloads folder. From Android 10/ Q and above it will not need any permission (it seems it handle the permission itself). If you want to open the file afterwards, you will need the user's permission instead (also if you only want to open it within an external app (e.g. You can use the download manager like this: ); Request Header("Accept", "application/pdf"); // Save the file in the "Downloads" folder of SDCARD Destination In External Public Dir(Environment. DIRECTORY_DOWNLOADS,filename); Download Manager download Manager = (Download Manager) get Activity()System Service(Context. String) https://developer.android.com/training/data-storage I thought that it would best be to write the answer in java, as a lot of legacy code exists out there which would have to be updated. DOWNLOAD_SERVICE); download Manager.enqueue(request); This are the references: https://developer.android.com/reference/kotlin/android/app/Download Manager. hl=en#set Destination In External Public Dir(kotlin. Also I have no idea what kind of file you want to store and so, here, I took an example of a bitmap. If you want to save any other kind of file you just have to create an Output Stream of it, and for the remaining part of it you can follow the code I write below. Now, here, this function is only going to handle the saving for Android 10 and hence the annotation. I hope you have the prerequisite knowledge on how to save files in lower android versions This will create a folder named "Folder Name" and store "Test.jpg" inside that folder. Also do note this doesn't require any permissions in the manifest which implies it doesn't need runtime permissions as well. If you want the Kotlin version do ask me in the comments. I would happily and readily provide the Kotlin method for the same.

date: 25-Aug-2021 22:03next


2020-2021 © c.mediasoft-rp.com
Sitemap