How to manage restricted profiles in an Android app?

The limited profile is now available in Android from 4.3, I found out that some applications, such as camera, gmail, etc., are not available in these profiles. How can I manage these types of conditions in my application? Also how to manage applications and profile settings restrictions according to my application?

+6
source share
3 answers

Thanks to user370305 even if I already visited

http://developer.android.com/about/versions/android-4.3.html#RestrictedProfiles

I would like to improve it with a link using

https://www.youtube.com/watch?v=pdUcANNm72o

Limited profiles is a new feature introduced in Android Jelly Bean 4.3, which allows users to improve application management when sharing their tablet.

These limited profiles use the application, google account, the main user account, but in a limited way. They do not get access to gmail, game store, calendar, etc. The primary user can select restrictions for each application.

The UserManager class has been extended to manage these restrictions.

UserManager.getUserRestrictions returns user restrictions imposed by the user

UserManager.getApplicationRestrictions returns a package containing any saved application restrictions for this user for the given package name. This method can only call an application with this package name.

If you need specific settings, use this intent filter

<receiver android:name="GetRestrictionsReceiver"> <intent-filter> <action android:name="android.intent.action.GET_RESTRICTION_ENTRIES "/> </intent-filter> </receiver> 

now implements a broadcast receiver with a list of restrictions list, as shown

 public class GetRestrictionsReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub final PendingResult result=goAsync(); new Thread(){ public void run(){ final Bundle extras=new Bundle(); ArrayList<RestrictionEntry> newEntries = initRestricions(context); extras.putParcelableArrayList(Intent.EXTRA_RESTRICTIONS_LIST, newEntries); result.setResult(Activity.RESULT_OK, null, extras); result.finish(); } }.start(); } } 

RestrictionEntry

Any application that wants to expose such restrictions does this by implementing a receiver that processes the ACTION_GET_RESTRICTION_ENTRIES action. The recipient then returns a result set containing an entry called "constraints" whose value is an ArrayList.

There are 3 types of restriction entries

  • Boolean
  • Single choice
  • Several variants

You can use different RestrictionEntry methods to set and get different types of restrictions.

To access an account from a restricted profile, you must add the android: limitedAccountType attribute to the tag:

 <application ... android:restrictedAccountType="com.example.account.type" > 
+5
source

The user interface that controls your restrictions is controlled by System Settings. In order for your application restriction settings to be displayed to the user, you must declare the restrictions offered by your application by creating a BroadcastReceiver that receives the intent ACTION_GET_RESTRICTION_ENTRIES . The system invokes this intention to request all applications for available restrictions, and then creates a user interface to allow the primary user to manage the restrictions for each restricted profile.

See http://developer.android.com/about/versions/android-4.3.html#RestrictedProfiles for details

+1
source

you can use the following section of code to determine if your application is running in restricted profile mode!

 import android.content.pm.UserInfo; import android.os.UserHandle; import android.os.UserManager; public static boolean isRestrictedProfileInEffect(Context context) { UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE); UserInfo restrictedUserInfo = null; for (UserInfo userInfo : userManager.getUsers()) { if (userInfo.isRestricted()) { restrictedUserInfo = userInfo; } } boolean isOwner = UserHandle.myUserId() == UserHandle.USER_OWNER; boolean isRestrictedProfileOn = restrictedUserInfo != null && !isOwner; return isRestrictedProfileOn; } 
+1
source

Source: https://habr.com/ru/post/950256/


All Articles