Java Code Examples for android.content.pm.ShortcutInfo#getId()
The following examples show how to use
android.content.pm.ShortcutInfo#getId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShortcutsUtils.java From shortrain with MIT License | 6 votes |
public static int getNextRailNumber(ShortcutManager shortcutManager) { List<ShortcutInfo> shortcuts = shortcutManager.getPinnedShortcuts(); int newRailId = -1; for (ShortcutInfo shortcutInfo : shortcuts) { String id = shortcutInfo.getId(); if (isRailShortcut(id)) { int railId = getRailNumber(id); if (railId > newRailId) { newRailId = railId; } } } newRailId++; return newRailId; }
Example 2
Source File: ShortcutPackage.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void ensureNotImmutable(@Nullable ShortcutInfo shortcut, boolean ignoreInvisible) { if (shortcut != null && shortcut.isImmutable() && (!ignoreInvisible || shortcut.isVisibleToPublisher())) { throw new IllegalArgumentException( "Manifest shortcut ID=" + shortcut.getId() + " may not be manipulated via APIs"); } }
Example 3
Source File: ShortcutService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Handles {@link #requestPinShortcut} and {@link ShortcutServiceInternal#requestPinAppWidget}. * After validating the caller, it passes the request to {@link #mShortcutRequestPinProcessor}. * Either {@param shortcut} or {@param appWidget} should be non-null. */ private boolean requestPinItem(String packageName, int userId, ShortcutInfo shortcut, AppWidgetProviderInfo appWidget, Bundle extras, IntentSender resultIntent) { verifyCaller(packageName, userId); verifyShortcutInfoPackage(packageName, shortcut); final boolean ret; synchronized (mLock) { throwIfUserLockedL(userId); Preconditions.checkState(isUidForegroundLocked(injectBinderCallingUid()), "Calling application must have a foreground activity or a foreground service"); // If it's a pin shortcut request, and there's already a shortcut with the same ID // that's not visible to the caller (i.e. restore-blocked; meaning it's pinned by // someone already), then we just replace the existing one with this new one, // and then proceed the rest of the process. if (shortcut != null) { final ShortcutPackage ps = getPackageShortcutsForPublisherLocked( packageName, userId); final String id = shortcut.getId(); if (ps.isShortcutExistsAndInvisibleToPublisher(id)) { ps.updateInvisibleShortcutForPinRequestWith(shortcut); packageShortcutsChanged(packageName, userId); } } // Send request to the launcher, if supported. ret = mShortcutRequestPinProcessor.requestPinItemLocked(shortcut, appWidget, extras, userId, resultIntent); } verifyStates(); return ret; }
Example 4
Source File: MainActivity.java From ui with Apache License 2.0 | 5 votes |
@Override protected void onResume() { super.onResume(); Log.v(TAG, "Intent action is " + getIntent().getAction()); if (mShortcutManager.getDynamicShortcuts().size() == 0) { //there are no dynamic shortcuts, so lets add two of them. Log.v(TAG, "no shortcuts, adding 2"); logthis("no shortcuts, adding 2"); addshortcuts(); } else { //log the shortcuts to the screen. for (ShortcutInfo shortcut : mShortcutManager.getDynamicShortcuts()) { String temp = "ID: " + shortcut.getId() + " ShortLabel:" + shortcut.getShortLabel(); Log.v(TAG, temp); logthis(temp); } //we should refresh them, in case things changed in dynamic. (or in debugging, if we changed something. doesn't auto update addshortcuts(); } if (getIntent().getAction().compareTo("edu.cs4730.appshortcutsdemo.CustomAction") ==0) { //this is our custom intent fromt he xml file logthis("Custom Action intent from the Static shortcut."); } }
Example 5
Source File: ShortcutRequestPinProcessor.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * The last step of the "request pin shortcut" flow. Called when the launcher accepted a * request. */ public boolean directPinShortcut(PinShortcutRequestInner request) { final ShortcutInfo original = request.shortcutOriginal; final int appUserId = original.getUserId(); final String appPackageName = original.getPackage(); final int launcherUserId = request.launcherUserId; final String launcherPackage = request.launcherPackage; final String shortcutId = original.getId(); synchronized (mLock) { if (!(mService.isUserUnlockedL(appUserId) && mService.isUserUnlockedL(request.launcherUserId))) { Log.w(TAG, "User is locked now."); return false; } final ShortcutLauncher launcher = mService.getLauncherShortcutsLocked( launcherPackage, appUserId, launcherUserId); launcher.attemptToRestoreIfNeededAndSave(); if (launcher.hasPinned(original)) { if (DEBUG) { Slog.d(TAG, "Shortcut " + original + " already pinned."); // This too. } return true; } final ShortcutPackage ps = mService.getPackageShortcutsForPublisherLocked( appPackageName, appUserId); final ShortcutInfo current = ps.findShortcutById(shortcutId); // The shortcut might have been changed, so we need to do the same validation again. try { if (current == null) { // It doesn't exist, so it must have all necessary fields. mService.validateShortcutForPinRequest(original); } else { validateExistingShortcut(current); } } catch (RuntimeException e) { Log.w(TAG, "Unable to pin shortcut: " + e.getMessage()); return false; } // If the shortcut doesn't exist, need to create it. // First, create it as a dynamic shortcut. if (current == null) { if (DEBUG) { Slog.d(TAG, "Temporarily adding " + shortcutId + " as dynamic"); } // Add as a dynamic shortcut. In order for a shortcut to be dynamic, it must // have a target activity, so we set a dummy here. It's later removed // in deleteDynamicWithId(). if (original.getActivity() == null) { original.setActivity(mService.getDummyMainActivity(appPackageName)); } ps.addOrReplaceDynamicShortcut(original); } // Pin the shortcut. if (DEBUG) { Slog.d(TAG, "Pinning " + shortcutId); } launcher.addPinnedShortcut(appPackageName, appUserId, shortcutId, /*forPinRequest=*/ true); if (current == null) { if (DEBUG) { Slog.d(TAG, "Removing " + shortcutId + " as dynamic"); } ps.deleteDynamicWithId(shortcutId, /*ignoreInvisible=*/ false); } ps.adjustRanks(); // Shouldn't be needed, but just in case. } mService.verifyStates(); mService.packageShortcutsChanged(appPackageName, appUserId); return true; }