- Sharing a File
- This lesson teaches you to
- You should also read
- Receive File Requests
- Create a File Selection Activity
- Define the file selection Activity in code
- Respond to a File Selection
- Grant Permissions for the File
- Share the File with the Requesting App
- Sharing Content between Android apps
- Sharing text
- Sharing HTML text
- Receiving text
- Sharing files and images
- Receiving files
- The Support Library is your friend
- Top 12 Best File Sharing Apps For Android | File Transfer App – 2021
- Best File Sharing App To Transfer File Fast And Secure For Android
- 1. inShare
- 2. JioSwitch
- 3. Send Anywhere
- 4. ShareMe
- 5. Zapya
- 6. XShare
- 7. WiFi File Transfer
- 8. Bluetooth File Transfer
- 9. AirDroid
- 10. MacDroid
- 11. Xender
- 12. SHAREit
Sharing a File
This lesson teaches you to
You should also read
Once you have set up your app to share files using content URIs, you can respond to other apps’ requests for those files. One way to respond to these requests is to provide a file selection interface from the server app that other applications can invoke. This approach allows a client application to let users select a file from the server app and then receive the selected file’s content URI.
This lesson shows you how to create a file selection Activity in your app that responds to requests for files.
Receive File Requests
To receive requests for files from client apps and respond with a content URI, your app should provide a file selection Activity . Client apps start this Activity by calling startActivityForResult() with an Intent containing the action ACTION_PICK . When the client app calls startActivityForResult() , your app can return a result to the client app, in the form of a content URI for the file the user selected.
To learn how to implement a request for a file in a client app, see the lesson Requesting a Shared File.
Create a File Selection Activity
To set up the file selection Activity , start by specifying the Activity in your manifest, along with an intent filter that matches the action ACTION_PICK and the categories CATEGORY_DEFAULT and CATEGORY_OPENABLE . Also add MIME type filters for the files your app serves to other apps. The following snippet shows you how to specify the new Activity and intent filter:
Define the file selection Activity in code
Next, define an Activity subclass that displays the files available from your app’s files/images/ directory in internal storage and allows the user to pick the desired file. The following snippet demonstrates how to define this Activity and respond to the user’s selection:
Respond to a File Selection
Once a user selects a shared file, your application must determine what file was selected and then generate a content URI for the file. Since the Activity displays the list of available files in a ListView , when the user clicks a file name the system calls the method , android.view.View, int, long)»>onItemClick() , in which you can get the selected file.
In , android.view.View, int, long)»>onItemClick() , get a File object for the file name of the selected file and pass it as an argument to getUriForFile() , along with the authority that you specified in the
element for the FileProvider . The resulting content URI contains the authority, a path segment corresponding to the file’s directory (as specified in the XML meta-data), and the name of the file including its extension. How FileProvider maps directories to path segments based on XML meta-data is described in the section Specify Sharable Directories.
The following snippet shows you how to detect the selected file and get a content URI for it:
Remember that you can only generate content URIs for files that reside in a directory you’ve specified in the meta-data file that contains the
element, as described in the section Specify Sharable Directories. If you call getUriForFile() for a File in a path that you haven’t specified, you receive an IllegalArgumentException .
Grant Permissions for the File
Now that you have a content URI for the file you want to share with another app, you need to allow the client app to access the file. To allow access, grant permissions to the client app by adding the content URI to an Intent and then setting permission flags on the Intent . The permissions you grant are temporary and expire automatically when the receiving app’s task stack is finished.
The following code snippet shows you how to set read permission for the file:
Caution: Calling setFlags() is the only way to securely grant access to your files using temporary access permissions. Avoid calling Context.grantUriPermission() method for a file’s content URI, since this method grants access that you can only revoke by calling Context.revokeUriPermission() .
Share the File with the Requesting App
To share the file with the app that requested it, pass the Intent containing the content URI and permissions to setResult() . When the Activity you have just defined is finished, the system sends the Intent containing the content URI to the client app. The following code snippet shows you how to do this:
Provide users with an way to return immediately to the client app once they have chosen a file. One way to do this is to provide a checkmark or Done button. Associate a method with the button using the button’s android:onClick attribute. In the method, call finish() . For example:
Источник
Sharing Content between Android apps
Sharing is caring, as they say, but sharing on Android means something perhaps slightly different. ‘Sharing’ is really shorthand for sending content such as text, formatted text, files, or images between apps.
So if ‘sharing’ == sending content, it makes slightly more sense that it is implemented using ACTION_SEND (or ACTION_SEND_MULTIPLE) Intents and its dozen extras.
While that approach is perfectly valid, I prefer to use ShareCompat, a set of classes in the v4 Support Library designed to make it easy to build intents for sharing content.
Sharing text
Sharing plain text is, as you might imagine, a good place to start. In fact, there’s not a whole lot to it:
ShareCompat.IntentBuilder uses a fluent API where you can chain together multiple method calls, using only the ones you need. For sharing, one of the most important parts is picking the right mime type — this is how apps filter what type of content they can receive. By using text/plain, we signify that our Intent will only contain plain text. Then, of course, setText() is how we actually add the CharSequence to the Intent to send. And while you can certainly send styled text using setText(), there’s no guarantee that the receiving app will honor that styling, so you should ensure that the text is legible with or without styling.
You’ll note we then use resolveActivity() before calling startActivity(). As mentioned in Protecting Implicit Intents with Runtime Checks, this is critical to prevent an ActivityNotFoundException when there is no Activity available to handle the mime type you have selected. While probably not as much of a concern with text/plain, it may be much more common with other types.
Note: when you use startActivity(shareIntent), that respects any default apps the user has set (i.e., if they’ve previously selected sharing all “text/plain” items to a certain app). If you’d like to instead always show a disambiguation chooser, use the intent generated from IntentBuilder.createChooserIntent() as explained in the ACTION_CHOOSER documentation.
Sharing HTML text
Some apps, most notably email clients, also support formatting with HTML. The changes, compared to plain text, are fairly minor:
The differences here are that we use of setHtmlText() in place of setText() and a mime type of text/html replacing text/plain. Here ShareCompat actually does a little bit extra: setHtmlText() also uses Html.fromHtml() to create a fallback formatted text to pass along to the receiving app if you haven’t previously called setText() yourself.
Given that many of the apps that can receive HTML text are email clients, there’s a number of helper methods to set the subject, to:, cc:, and bcc: email addresses as well — consider adding at least a subject to any share intent for best compatibility with email apps.
Of course, you’ll still want to call resolveActivity() just as before — nothing changes there.
Receiving text
While the focus so far has been on the sending side, it is helpful to know exactly what is happening on the other side (if not just to build a simple receiving app to install on your emulator for testing purposes). Receiving Activities add an intent filter to the Activity:
The action is obviously the more critical part — without that there’s nothing that would denote this as an ACTION_SEND (the action behind sharing). The mime type, same as with our sending code, is also present here. What isn’t as obvious are the two categories. From the element documentation:
Note: In order to receive implicit intents, you must include the CATEGORY_DEFAULT category in the intent filter. The methods startActivity() and startActivityForResult() treat all intents as if they declared the CATEGORY_DEFAULT category. If you do not declare it in your intent filter, no implicit intents will resolve to your activity.
So CATEGORY_DEFAULT is required for our use case. Then, CATEGORY_BROWSABLE allows web pages to natively share into apps without any extra effort required on the receiving side.
And to actually extract the information from the Intent, the useful ShareCompat.IntentReader can be used:
Similar to IntentBuilder, IntentReader is just a simple wrapper that make it easy to extract information.
Sharing files and images
While sending and receiving text is straightforward enough (create text, include it in Intent), sending files (and particularly images — the most common type by far) has an additional wrinkle: file permissions.
The simplest code you might try might look like
And that almost works — the tricky part is in getting a Uri to the File that other apps can actually read, particularly when it comes to Android 6.0 Marshmallow devices and runtime permissions (which include the now dangerous READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions).
My plea: don’t use Uri.fromFile(). It forces receiving apps to have the READ_EXTERNAL_STORAGE permission, won’t work at all if you are trying to share across users, and prior to KitKat, would require your app to have WRITE_EXTERNAL_STORAGE. And really important share targets, like Gmail, won’t have the READ_EXTERNAL_STORAGE permission — so it’ll just fail.
Instead, you can use URI permissions to grant other apps access to specific Uris. While URI permissions don’t work on file:// URIs as is generated by Uri.fromFile(), they do work on Uris associated with Content Providers. Rather than implement your own just for this, you can and should use FileProvider as explained in the File Sharing Training.
Once you have it set up, our code becomes:
Using FileProvider.getUriForFile(), you’ll get a Uri actually suitable for sending to another app — they’ll be able to read it without any storage permissions — instead, you are specifically granting them read permission with FLAG_GRANT_READ_URI_PERMISSION.
Note: we don’t call setType() anywhere when building our ShareCompat (even though in the video I did set it). As explained in the setDataAndType() Javadoc, the type is automatically inferred from the data URI using getContentResolver().getType(uriToImage). Since FileProvider returns the correct mime type automatically, we don’t need to manually specify a mime type at all.
If you’re interested in learning more about avoiding the storage permission, consider watching my Forget the Storage Permission talk or at least go through the slides, which covers this topic in depth at 14:55 (slide 11).
Receiving files
Receiving files isn’t too different from text because you’re still going to use ShareCompat.IntentReader. For example, to make a Bitmap out of an incoming file, it would look like:
Of course, you’re free to do whatever you want with the InputStream — watch out for images that are so large you hit an OutOfMemoryException. All of the things you know about loading Bitmaps still apply.
The Support Library is your friend
With both ShareCompat (and its IntentBuilder and IntentReader) and FileProvider in the v4 Support Library, you’ll be able to include sharing text, HTML text, and files in your app with the best practices by default.
Источник
Top 12 Best File Sharing Apps For Android | File Transfer App – 2021
Sharing files to another phone takes lots of time through an internet network or Bluetooth network. So here I have listed the best file sharing apps that transfer your files from one phone to another or from one phone to any computer very fast.
These file transfer apps send you files through a locally created WiFi network without using your internet. Check out below file sharing apps to transfer your files from an android mobile phone.
Best File Sharing App To Transfer File Fast And Secure For Android
Important Note: SHAREit and Xender apps are now banned in India from 29th June 2020 along with other 57 mobile apps.
1. inShare
If you want to share files from one mobile device to another device with lightning speed, even without the internet connection, give inShare a try. You are allowed to share videos, photos, music, apps, e-book and pdf files with over 40Mb/s speed in just one tap feature.
It has a clean and beautiful interface which makes it user friendly with more than 30 supported languages. It also has a feature to transfer data from an old mobile phone to a new one. inShare is free to use and lets you transfer multiple files and folders in one go.
2. JioSwitch
JioSwitch is one of the leading file transfer apps by Jio. It supports a wide range of file types to transfer from one mobile device to another. Transferring files between android mobile and iOS mobile are also possible with JioSwitch without any file size limit.
This app is over 100 times faster than Bluetooth and works without an internet or mobile data network. It has a simple, clean and user-friendly interface without any ads which makes people conformable using it.
10 million downloads with 4.3 ratings out of 5 on the play store make it a reliable file sharing app to give a try. JioSwitch is completely free to use and available on the play store as well as the App Store to download.
3. Send Anywhere
Send Anywhere is one of the best file sharing apps for the Android device that protects your data with strong 256bit encryption. To simply transfer a file, you just need to enter a one-time six-digit key for security purposes.
You can transfer any files between Android smartphones without even taking the help of an internet or mobile data connection. It also allows you to send the files to multiple people at once with the help of a custom link.
4. ShareMe
ShareMe is a great file transfer app by Xiaomi. With over 100 million downloads on the play store, it competes with SHAREit and Xender. With ShareMe you can share images, videos, music, apps and other files between mobile devices anytime anywhere you want.
The good thing about this app is it works without an internet connection. It supports fast file sharing features which are 200 times faster than Bluetooth.
It has a very simple, clean and user-friendly interface which makes you feel comfortable. This app is completely ad-free and doesn’t have any restrictions over the size of the files you want to transfer. ShareMe is available only on the play store for android users.
5. Zapya
Zapya is the world’s fastest file-sharing app that is now available in the market. It has been well received on multiple platforms since its launch. It is a web sharing application.
WebShare will allow the users to access all of the content of an Android Phone from any device that can connect to the Android phone with the help of 4G, WLAN, WiFi hotspot or WiFi, etc. Instead of downloading an app on your system, you can view the photos, watch videos, play songs, and access any folders on the phone.
You can even download the files from the phone. You can upload files on the phones. You can view the Android content from a web browser on another phone. You can even remote control the Android camera, as well.
6. XShare
XShare is another fastest file transfer app with over 10 million downloads on the play store. You don’t need an internet connection to transfer files from one mobile phone to another.
It enables a quick signup process and supports sharing images, videos, apps and documents anytime and anywhere. Sharing multiple files with a very fast speed can also be done with XShare file transfer app. 4.5 out of 5 ratings on the play store makes it a trustworthy app to give a try.
7. WiFi File Transfer
WiFi File Transfer can help you out to send or receive files over a local WiFI connection. You can share files between computers, tablets, and smartphones. All devices should be on the same network for this Android data transfer app to work.
You can easily download or even upload multiple files simultaneously and even transfer entire folder structures in the case of Google Chrome. The file manager in the app lets you to view, edit, delete, zip, and unzip files all from the same interface.
You can also easily set up password authentication to make sure that the right devices are connected. The only drawback of this app is that it only lets you transfer files of around 5 MB.
8. Bluetooth File Transfer
You can share the files over the Bluetooth connection with the help of this Android data transfer app. It offers a secure way to transfer your data as you can authorize all the incoming connections.
One unique advantage of this app is that it can use the infrared to connect to old cell phones such as Samsung, Sony, LG, and Nokia.
The app has an inbuilt fast file browser and features a clean and fast User Interface. You can also use the integrated explorer to cut, copy, move, and delete items. It can also perform both the zip and unzip of files with encryption.
9. AirDroid
AirDroid is such a beautiful file sharing app that is recommended by the CNET, Gizmodo, PCWorld, BGR, Phandroid, and some other technology media websites.
It allows you to access your computer, smartphone, tablet wirelessly. With this app, you can mirror a large computer screen. So, that you can type a physical keyboard and control it with the help of a mouse.
10. MacDroid
MacDroid app is a helpful solution for those who transfer files between Mac and Android devices, at the same time connecting an Android device to an iPhone.
Android and macOS doesn’t natively work together, hence there is a vital need for an app that would not only connect the 2 systems but also allow secure and smooth file transfer between them.
With MacDroid you get the option of connecting Mac and an Android phone or Android tablet and accessing the portable device’s content in the Finder.
You can transfer photos, music, videos as well as entire folders. You’ll only need a USB cable to connect your phone to the Mac computer.
11. Xender
Xender is another most useful Android and iOS file transfer app with more than 500 million users. You can transfer all types of files without any restriction over a hotspot connection that does not require any cables, wires, or data connection.
The app can also be used for cross-platform data transfers between the phone and a Mac or PC and Android, iOS, and Windows operating systems. Xender can also achieve a speed of around 40 MB/sec, which enables you to transfer files of any size without restrictions.
You can also transfer mobile data like games, music, videos, messages, pictures, and contacts from your old phone to a new one with the help of a simple step. It also comes with a file manager to view, delete, or move your files.
Note: Xender is not available in India.
12. SHAREit
This is perhaps the most popular file-sharing app, which is now banned in India from 29th June 2020.
The app comes from the Brand Lenovo so that you can expect this to be pretty well-tuned for the modern user. It was one of the first apps to arrive on the scene, and eventually, make it a big.
Just like the Bluetooth connectivity or USB and NFC connections, SHAREit saves a lot of time as the transfer speeds are incredible. The app comes with the ability to share practically any file you desire, which makes it incredibly versatile among the file-sharing apps.
Which is the Indian file sharing app?
JioSwitch is an India file sharing app from Reliance Jio.
What is the Best App for File sharing?
ShareMe is one of the best App for file sharing with over 500 million downloads.
What are the best alternatives to SHAREit and Xender?
JioSwitch, inShare and Send Anywhere are the best Non-Chinese alternative to SHAREit.
What can I use instead of SHAREit?
Check out the 12 best file sharing apps listed above. We recommend using ShareMe instead of SHAREit.
Источник