Android Lollipop - Check if a work profile is set up for the user - android-5.0-lollipop

I would like to find a way to know, from the user profile, if a work profile (profile owner) has been set up for the user.
I'm currently using this method:
public boolean isWorkProfileEnabled() {
UserManager um = (UserManager) getSystemService(USER_SERVICE);
return um.getUserProfiles().size() >= 2;
}
But this is not reliable. When it's equal 2, it can also mean a restricted profile is installed.
Someone has an idea?

Related

How to change language automatically using user browser language Yii2?

A user can change the language manually from the website. But for better user experience, I would like to change it automatically based on the users' browser language. I have a global Controller and can use init() and then redirect.
Please give me tips to do it right.
You should remember the chosen language for a user, if they had selected one previously, I store this in the database, in a user_preference table.
Then you need to intercept the request, it can be done in the application configuration file, using the on beforeRequest property.
If you don't have stored a preference for the current user, or the user is a guest, use the browser language to set the application language.
Configuration file
use app\models\User;
...
'on beforeRequest' => function ($event) {
$user_lang = '';
if (!Yii::$app->user->isGuest) {
// Check if you have stored a language preference for the user
$user_lang = User::findIdentity(Yii::$app->user->id)->getUserPreference('lang');
}
if (!empty($user_lang)) {
// If you have a stored preference for the user, use it
Yii::$app->language = $user_lang;
} else {
// If you don't have a preference, use the browser language
// Get the browser language from the headers
$browser_lang = Yii::$app->request->headers->get('accept-language');
// Alternatively get the headers from the event
// $event->sender->request->headers->get('accept-language')
// Calculate the language you want to provide based on the browser language
$language_code = LanguageHelper::calculatei18nCode($browser_lang);
Yii::$app->language = $language_code;
}
},
...
If you wanted to keep your configuration file clean, you could use filters instead to intercept the request.
Your LanguageHelper::calculatei18nCode($browser_lang) method would try to find a match for the browser language in the available languages, if it didn't find one it could return the closest match, or the default application language.
LanguageHelper
public static function calculatei18nCode ($browser_lang) {
// For example, if you are offering one translation file for french
if (stripos($browser_lang, 'fr')) {
return 'fr';
}
...
return 'en';
}

Removing collaborations from a user's account

We have a use case where we would like to remove a user's account in our enterprise. As part of the removal process we want to uncolloborate all of the folders the user owns but is sharing with others. I"m able to remove the user successfully but am stuck trying to uncolloborate all of the folders before removing their account. I've tried the following code but it doesn't seem to work. This is the code I'm using
List<BoxCollaboration> collabs = client.getFoldersManager()
.getFolderCollaborations(entry.getId(),
new BoxDefaultRequestObject());
for (BoxCollaboration collab : collabs) {
BoxUser collaboratorid = (BoxUser) collab.getAccessibleBy();
BoxDefaultRequestObject requestObject = new BoxDefaultRequestObject();
requestObject.getRequestExtras().addHeader("As-User", userwhoisgettingremived.getId());
client.getCollaborationsManager().deleteCollaboration(collaboratorid , requestObject);
}
Anyone have a suggestion of what else I can try.
Thanks in advance
Bill.
You don't need to use "As-User" header as now you are not acting as this user. So the code can be:
for (BoxCollaboration collab : collabs) {
String collaboratorid = collab.getId();
client.getCollaborationsManager().deleteCollaboration(collaboratorid , null);
}
OK I fixed this by adding the id of the Collaboration instead of the id of the user associated with the collaboration. so the deleteCollaboration line of code needed to be changed to
client.getCollaborationsManager().deleteCollaboration(collab.getId() , requestObject);

Windowns Phone 8 link to setting

Can I make link into setting in phone from my application? For example like a link to other page (NavigateTo)?
I would like to make buttun, witch navigate you to mobile setting....
thanks for the answer.
Check this link. You can do that by invoking LaunchUriAsync method passing one of available settings Uri as parameter :
public async void OpenSettings(string settingsName)
{
var op = await Windows.System.Launcher.LaunchUriAsync(new Uri(settingsName));
}
Available Uri :
1. ms-settings-airplanemode: .
2. ms-settings-bluetooth:
3. ms-settings-cellular:
4. ms-settings-emailandaccounts:
5. ms-settings-location:
6. ms-settings-power:
7. ms-settings-screenrotation:
8. ms-settings-wifi:

OWA Signature Update with Exchange Web Services

We're using Exchange Web Services to set user signature in Outlook Web Access. It works great, we see the signature under Options>Settings and the "Automatically include my signature on messages I send" check box is checked. We also set this programmatically.
However, when the user creates a new e-mail message in OWA the signature does not show up. A work around for this is to go to Options>Setting, uncheck the "Automatically include my signature on messages I send" check box , Save, check the check box again and save.
The code we use to set the signature looks something like this:
Folder rootFolder;
UserConfiguration OWAConfig;
rootFolder = Folder.Bind(service, WellKnownFolderName.Root);
OWAConfig = UserConfiguration.Bind(service, "OWA.UserOptions",rootFolder.ParentFolderId, UserConfigurationProperties.All);
OWAConfig.Dictionary["signaturehtml"] = "Hello World";
OWAConfig.Dictionary["autoaddsignature"] = "True";
OWAConfig.Update();
Any idea how to get around this problem?
I have some old code that does the same thing which is working fine. I have pasted the code below. There are a few minor differences between my code and yours. I am not sure if they make a difference but you may want to try it out. Here is an extract of my code with the differences highlighted with a comment:
private void SetSettingValue(UserConfiguration owaConfig, string propName, object propValue)
{
if (owaConfig.Dictionary.ContainsKey(propName))
{
owaConfig.Dictionary[propName] = propValue;
}
else
{
// Adds a key if it does not explicitly exist.
// I am not sure if it makes a difference.
owaConfig.Dictionary.Add(propName, propValue);
}
}
public void AddSignature()
{
// Extract
UserConfiguration OWAConfig = UserConfiguration.Bind(
service,
"OWA.UserOptions",
WellKnownFolderName.Root, // Binding to Root and not Root.ParentFolderId.
UserConfigurationProperties.Dictionary // Binds to Dictionary and not to All.
);
SetSettingValue(OWAConfig, "autoaddsignature", true);
SetSettingValue(OWAConfig, "signaturehtml", html);
OWAConfig.Update();
}

Codeigniter limit certain page elements to profile owner

I want to limit access to certain elements of a user's profile so that only the user can see them and not other logged in users. So far the is_logged_in function (see below) works fine, now I need to refine it so that it is limited to a specific user that is logged in.
I'm already including a user_id variable in my session data, so that's available for use.
function is_logged_in()
{
$is_logged_in = $this->session->userdata('is_logged_in');
if($is_logged_in)
{
$this->index();
}
else
{
redirect('fooview');
}
}
you will need to know the user_id of the profile you are viewing, lets assume in your controller you have it as $user_id.
in your controller you can do $is_owner = $this->session->userdata('user_id') == $user_id ? true : false;
then pass it to your view as e.g. $is_owner.
then in your view simply have
if($is_owner){
//show stuff
} else {
//message saying stuff is private!
}