本文整理匯總了Java中android.os.Process.myUserHandle方法的典型用法代碼示例。如果您正苦於以下問題:Java Process.myUserHandle方法的具體用法?Java Process.myUserHandle怎麽用?Java Process.myUserHandle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.os.Process
的用法示例。
在下文中一共展示了Process.myUserHandle方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: ComponentKey
import android.os.Process; //導入方法依賴的package包/類
/**
* Creates a new component key from an encoded component key string in the form of
* [flattenedComponentString#userId]. If the userId is not present, then it defaults
* to the current user.
*/
public ComponentKey(Context context, String componentKeyStr) {
int userDelimiterIndex = componentKeyStr.indexOf("#");
if (userDelimiterIndex != -1) {
String componentStr = componentKeyStr.substring(0, userDelimiterIndex);
Long componentUser = Long.valueOf(componentKeyStr.substring(userDelimiterIndex + 1));
componentName = ComponentName.unflattenFromString(componentStr);
user = UserManagerCompat.getInstance(context)
.getUserForSerialNumber(componentUser.longValue());
} else {
// No user provided, default to the current user
componentName = ComponentName.unflattenFromString(componentKeyStr);
user = Process.myUserHandle();
}
mHashCode = Arrays.hashCode(new Object[] {componentName, user});
}
示例2: markExistingUsersForNoFolderCreation
import android.os.Process; //導入方法依賴的package包/類
/**
* For each user, if a work folder has not been created, mark it such that the folder will
* never get created.
*/
public static void markExistingUsersForNoFolderCreation(Context context) {
UserManagerCompat userManager = UserManagerCompat.getInstance(context);
UserHandle myUser = Process.myUserHandle();
SharedPreferences prefs = null;
for (UserHandle user : userManager.getUserProfiles()) {
if (myUser.equals(user)) {
continue;
}
if (prefs == null) {
prefs = context.getSharedPreferences(
LauncherFiles.MANAGED_USER_PREFERENCES_KEY,
Context.MODE_PRIVATE);
}
String folderIdKey = USER_FOLDER_ID_PREFIX + userManager.getSerialNumberForUser(user);
if (!prefs.contains(folderIdKey)) {
prefs.edit().putLong(folderIdKey, ItemInfo.NO_ID).apply();
}
}
}
示例3: LauncherAppWidgetInfo
import android.os.Process; //導入方法依賴的package包/類
public LauncherAppWidgetInfo(int appWidgetId, ComponentName providerName) {
if (appWidgetId == CUSTOM_WIDGET_ID) {
itemType = LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET;
} else {
itemType = LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET;
}
this.appWidgetId = appWidgetId;
this.providerName = providerName;
// Since the widget isn't instantiated yet, we don't know these values. Set them to -1
// to indicate that they should be calculated based on the layout and minWidth/minHeight
spanX = -1;
spanY = -1;
// We only support app widgets on current user.
user = Process.myUserHandle();
restoreStatus = RESTORE_COMPLETED;
}
示例4: createPendingInfo
import android.os.Process; //導入方法依賴的package包/類
/**
* Verifies the intent and creates a {@link PendingInstallShortcutInfo}
*/
private static PendingInstallShortcutInfo createPendingInfo(Context context, Intent data) {
if (!isValidExtraType(data, Intent.EXTRA_SHORTCUT_INTENT, Intent.class) ||
!(isValidExtraType(data, Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.class)) ||
!(isValidExtraType(data, Intent.EXTRA_SHORTCUT_ICON, Bitmap.class))) {
return null;
}
PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(
data, Process.myUserHandle(), context);
if (info.launchIntent == null || info.label == null) {
return null;
}
return convertToLauncherActivityIfPossible(info);
}
示例5: createShortcutInfo
import android.os.Process; //導入方法依賴的package包/類
private static ShortcutInfo createShortcutInfo(Intent data, LauncherAppState app) {
Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Parcelable bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
if (intent == null) {
// If the intent is null, we can't construct a valid ShortcutInfo, so we return null
return null;
}
final ShortcutInfo info = new ShortcutInfo();
// Only support intents for current user for now. Intents sent from other
// users wouldn't get here without intent forwarding anyway.
info.user = Process.myUserHandle();
if (bitmap instanceof Bitmap) {
info.iconBitmap = LauncherIcons.createIconBitmap((Bitmap) bitmap, app.getContext());
} else {
Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
if (extra instanceof Intent.ShortcutIconResource) {
info.iconResource = (Intent.ShortcutIconResource) extra;
info.iconBitmap = LauncherIcons.createIconBitmap(info.iconResource, app.getContext());
}
}
if (info.iconBitmap == null) {
info.iconBitmap = app.getIconCache().getDefaultIcon(info.user);
}
info.title = Utilities.trim(name);
info.contentDescription = UserManagerCompat.getInstance(app.getContext())
.getBadgedLabelForUser(info.title, info.user);
info.intent = intent;
return info;
}
示例6: updateAndGetActiveSessionCache
import android.os.Process; //導入方法依賴的package包/類
@Override
public HashMap<String, Integer> updateAndGetActiveSessionCache() {
HashMap<String, Integer> activePackages = new HashMap<>();
UserHandle user = Process.myUserHandle();
for (SessionInfo info : mInstaller.getAllSessions()) {
addSessionInfoToCache(info, user);
if (info.getAppPackageName() != null) {
activePackages.put(info.getAppPackageName(), (int) (info.getProgress() * 100));
mActiveSessions.put(info.getSessionId(), info.getAppPackageName());
}
}
return activePackages;
}
示例7: getCustomShortcutActivityList
import android.os.Process; //導入方法依賴的package包/類
@Override
public List<ShortcutConfigActivityInfo> getCustomShortcutActivityList(
@Nullable PackageUserKey packageUser) {
List<ShortcutConfigActivityInfo> result = new ArrayList<>();
UserHandle myUser = Process.myUserHandle();
try {
Method m = LauncherApps.class.getDeclaredMethod("getShortcutConfigActivityList",
String.class, UserHandle.class);
final List<UserHandle> users;
final String packageName;
if (packageUser == null) {
users = UserManagerCompat.getInstance(mContext).getUserProfiles();
packageName = null;
} else {
users = new ArrayList<>(1);
users.add(packageUser.mUser);
packageName = packageUser.mPackageName;
}
for (UserHandle user : users) {
boolean ignoreTargetSdk = myUser.equals(user);
List<LauncherActivityInfo> activities =
(List<LauncherActivityInfo>) m.invoke(mLauncherApps, packageName, user);
for (LauncherActivityInfo activityInfo : activities) {
if (ignoreTargetSdk || activityInfo.getApplicationInfo().targetSdkVersion >=
Build.VERSION_CODES.O) {
result.add(new ShortcutConfigActivityInfoVO(activityInfo));
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
示例8: compareTo
import android.os.Process; //導入方法依賴的package包/類
@Override
public int compareTo(@NonNull WidgetItem another) {
if (sMyUserHandle == null) {
// Delay these object creation until required.
sMyUserHandle = Process.myUserHandle();
sCollator = Collator.getInstance();
}
// Independent of how the labels compare, if only one of the two widget info belongs to
// work profile, put that one in the back.
boolean thisWorkProfile = !sMyUserHandle.equals(user);
boolean otherWorkProfile = !sMyUserHandle.equals(another.user);
if (thisWorkProfile ^ otherWorkProfile) {
return thisWorkProfile ? 1 : -1;
}
int labelCompare = sCollator.compare(label, another.label);
if (labelCompare != 0) {
return labelCompare;
}
// If the label is same, put the smaller widget before the larger widget. If the area is
// also same, put the widget with smaller height before.
int thisArea = spanX * spanY;
int otherArea = another.spanX * another.spanY;
return thisArea == otherArea
? Integer.compare(spanY, another.spanY)
: Integer.compare(thisArea, otherArea);
}
示例9: Decoder
import android.os.Process; //導入方法依賴的package包/類
private Decoder(String encoded, Context context) throws JSONException, URISyntaxException {
super(encoded);
launcherIntent = Intent.parseUri(getString(LAUNCH_INTENT_KEY), 0);
user = has(USER_HANDLE_KEY) ? UserManagerCompat.getInstance(context)
.getUserForSerialNumber(getLong(USER_HANDLE_KEY))
: Process.myUserHandle();
if (user == null) {
throw new JSONException("Invalid user");
}
}
示例10: ItemInfo
import android.os.Process; //導入方法依賴的package包/類
public ItemInfo() {
user = Process.myUserHandle();
}
示例11: getUser
import android.os.Process; //導入方法依賴的package包/類
public UserHandle getUser() {
return isCustomWidget ? Process.myUserHandle() : getProfile();
}
示例12: ShortcutConfigActivityInfoVL
import android.os.Process; //導入方法依賴的package包/類
ShortcutConfigActivityInfoVL(ActivityInfo info, PackageManager pm) {
super(new ComponentName(info.packageName, info.name), Process.myUserHandle());
mInfo = info;
mPm = pm;
}
示例13: AppInfoComparator
import android.os.Process; //導入方法依賴的package包/類
AppInfoComparator(Context context) {
mUserManager = UserManagerCompat.getInstance(context);
mMyUser = Process.myUserHandle();
mLabelComparator = new LabelComparator();
}
示例14: FolderInfo
import android.os.Process; //導入方法依賴的package包/類
public FolderInfo() {
itemType = LauncherSettings.Favorites.ITEM_TYPE_FOLDER;
user = Process.myUserHandle();
}