Android share apps users

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.

Источник

11 Rea­sons You Must Try Android Mul­ti­ple Users Feature

Mehvish

18 Feb 2019

Back in the day when owning a computer was a privilege in itself, people shared a single computer where every user had its own profile. For a long time, a similar feature was missing in Android phones but things changed for good in 2014 when Google introduced multiple users with Android 5.0 Lollipop update.

Now, the feature is an essential part of every Android phone and tablets too — which reaped its benefits long before phones. So what is this feature and how does it work on Android? You will get all the answers here along with the reasons why you should start using this feature.

Let’s get started.

What Are User Profiles on Android

User profiles let you share your Android device (phone or tablet) with others without sharing any personal data. When you create a new user or guest profile, it’s exactly like creating another user account on your Windows-based PC. Each user gets an individual space linked to their own Google account where they have a different home screen, apps, settings, files, messages, and more.

There are three types of profiles — admin (owner of the phone), users, and guests.

Читайте также:  Часы android wear что это

What’s Shared and What’s Not

Be careful about the following things since they are shared with others:

  • App updates for common apps
  • Incoming phone calls
  • Storage usage
  • Data usage

Here are the things that aren’t shared:

  • Files (photos, videos, music, etc.)
  • Installed apps
  • App data such as chats, history, etc.
  • Notifications
  • SMS
  • Uninstallation of apps
  • Contacts and call history

For instance, if you have installed Netflix on your own profile, it will not be available on other profiles. However, if another user also installs Netflix, both of you will be able to update the app. But that doesn’t mean your Netflix watch history will be available to other users. Similarly, uninstalling Netflix from your own profile will not uninstall it from other users.

Now that you know a bit about user profiles, here are 11 reasons to use it.

Also on Guiding Tech

Top 21 Android Tips and Tricks You Must Know

1. Enjoy Your Private Space

Let’s say you love watching TikTok compilation videos on YouTube. Now imagine when your friend checks YouTube on your phone, and he/she gets ‘Best TikTok videos’ in suggestions. You get the hint. I would not wish that kind of embarrassment on even my enemies.

With multiple users, you are saved from such awkward moments for all your data (documents, videos, music, chats, etc.) including the synced app data is separate for each profile.

2. Keep Your Data Safe

If you have younger siblings or kids, they would usually pounce on your phone to play a game or watch a video on YouTube. While that’s okay, but phones nowadays hold important data. Any accidental tap will make us lose valuable content.

Even though Android phones come with an app pinning feature, it’s not entirely helpful for it’s easy to leave it and use other apps. But with multiple users, all your data is free from those tiny and dangerous hands for a new profile will not have access to your data.

3. Lock Your Content

What would be the use of multiple profiles if you couldn’t secure it? Android phones and tablets offer multiple ways to lock the screen such as pattern, pin, and password. Each user can choose a different unlock method to keep their data safe from prying eyes.

4. Be My Guest

User profiles are helpful when a family member or a friend regularly use your phone. What about situations when you need to share your phone for a short time? Meet guest profiles. A guest profile is for one-time users who use the phone for a while, and you don’t need to create yet another space.

Similar to user profiles, guest profiles have a separate space with no access to any data (installed apps, photos, videos, messages, etc.) of yours.

Guest profiles have several benefits over normal user profiles. Firstly, they are temporarily making it easy to delete them and start over for a new guest.

Secondly, guests can easily remove themselves once they are done using a phone. The feature can be quite handy when you want to use someone’s phone for a short time.

5. Restrict Content (Tablets Only)

Both user and guest profiles lack admin control for anyone using the phone through either of those profiles is free to browse any website, install apps, see mature content, etc. What if we want to restrict the usage to just a few apps or disable browsing for kids? For such situations, you can take advantage of restricted profiles.

With that, you can control the features and contents the profile is allowed to access. The feature is limited to the Nexus family of tablets only.

Also on Guiding Tech
# How-to/Guides

6. Don’t Let Time Stop You

Users other than guests need to add their Google account to set up their user profile. Sometimes, the user for which we are creating a profile isn’t with us so adding a Google account could be an issue, but that doesn’t mean you cannot keep a profile ready.

While creating a new user, you will be asked whether you want to set up the account right away or later. Tap on Not now. By doing this, the user profile will be created, but the user can set up it later.

7. Switch Profiles Easily

Any time a person asks for your phone, you don’t have to dig down into the settings to switch profiles for you can quickly do it right from any screen or even lock screen.

To do it from any screen, swipe down from the top to open the notification panel. Here tap on the tiny user icon and select a different user profile.

Читайте также:  Android view class attribute

To switch profiles from the lock screen, tap on the user icon usually present at the top-right corner.

8. Add Users from Lock Screen

Not only can you switch between profiles from the lock screen, but you can also add users directly from it.

For that, you need to first enable the Add users from lock screen setting. The setting location may vary. On some devices, it is present under Settings> Security and Location > Lock screen preferences, and on others, you will find it under Settings > Users.

9. View Storage and Data Quota

While profiles have their own individual space, they share the same device storage. So if your device has 6GB free storage, and you add a 1GB movie, the total available space for all users will be reduced to 5GB.

Now if your device is running low on memory, one might think it would be a confusing task to find out the owner occupying the maximum storage. But that’s not the case for users can easily check the amount of space occupied by other users. To do that, go to Settings > Storage. You will find details from different profiles under Other users.

Similarly, you can check other users Wi-Fi and mobile data usage under Settings > Data usage.

10. Restrict Calls and SMS

By default, user profiles can only receive calls. They aren’t able to make calls and send or receive SMS. Any text message received when a different profile is logged in will be shown to the phone owner when he/she logs in. However, if the phone owner wants, they can enable phone calls and SMS for each user profile separately.

For that, go to Settings > Users. Tap on the setting gear icon next to the username. Then enable the toggle for Turn on phone calls & SMS.

Also on Guiding Tech

How to Separate Ringtone and Notification Volume on Android

11. Admin Has the Supreme Power

Users and guest profiles cannot create or add users. The power lies solely with the phone owner. So you don’t need to worry about a user creating a new profile.

What’s the Catch?

As apparent, each profile takes up separate space for apps and files both. So more users will lead to less storage, which in turn affects the device performance. Moreover, all the profiles are simultaneously running in the background too affecting the overall device performance. Therefore, be careful and don’t go crazy with creating multiple profiles.

Next up: Love using gestures? Check these 5 hidden gestures on Android.

Last updated on 5 Jul, 2019
The above article may contain affiliate links which help support Guiding Tech. However, it does not affect our editorial integrity. The content remains unbiased and authentic.

Skype vs Zoom: Which Video Calling Service Is Better

# Zoom and # Skype are two of the best # video calling services for the professional use. Read the # comparison below to find the better software for you.

Top 7 Ways to Fix Camera App Not Working on Android

Are you facing issues accessing the # Camera app on # Android? Here’s how you can fix the issue and use the # camera again.

Top 8 Ways to fix Unfortunately File Manager Has Stopped on Android

# Android file manager stopping right in the middle of work may spoil the mood for you. Here’s how you can fix the issue.

Top 8 Ways to Fix WhatsApp Notification Sound Not Working

Are you getting # WhatsApp notifications without any # sound? Here’s how you can fix # WhatsApp notification sound not working on # iPhone and # Android.

Top 7 Ways to Fix Android Keyboard (AOSP) Has Stopped

Are you facing Android keyboard has stopped error on your phone? Here’s how you can troubleshoot Android keyboard (AOSP) has stopped.

How to Enable or Disable Smart Lock on Android

Want to unlock your # Android phone and open the respective app directly? Here’s how you can enable or disable the # Smart Lock on Android.

Top 7 Ways to Fix Android Phone Not Charging

Are you trying to charge an # Android phone and getting errors? Here’s how you can fix the Android phone not charging issue.

Top 8 Ways to Fix Android Phone Not Connecting to Wi-Fi

Is your # Android # phone failing to connect to a # Wi-Fi network? Read along to learn how to fix the Android # phone not connecting to the Wi-Fi issue.

Did You Know

Houseparty was bought by Epic Games in June 2019.

Источник

Оцените статью