本文整理匯總了Java中android.content.pm.ShortcutManager.getDynamicShortcuts方法的典型用法代碼示例。如果您正苦於以下問題:Java ShortcutManager.getDynamicShortcuts方法的具體用法?Java ShortcutManager.getDynamicShortcuts怎麽用?Java ShortcutManager.getDynamicShortcuts使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.pm.ShortcutManager
的用法示例。
在下文中一共展示了ShortcutManager.getDynamicShortcuts方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createShortcut
import android.content.pm.ShortcutManager; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.N_MR1)
private void createShortcut(String label, String packageName, Bitmap icon, Intent intent) {
ShortcutManager shortcutManager;
shortcutManager = getSystemService(ShortcutManager.class);
ShortcutInfo shortcut = new ShortcutInfo.Builder(this, packageName)
.setShortLabel(label)
.setLongLabel(label)
.setIcon(Icon.createWithBitmap(icon))
.setIntent(intent)
.setRank(0)
.build();
List<ShortcutInfo> shortcutList = shortcutManager.getDynamicShortcuts();
int shortcutSize = shortcutList.size();
if (shortcutSize >= 5) {
for (int i = 0; i < shortcutSize - 4; i++) {
shortcutManager.removeDynamicShortcuts(Collections.singletonList(shortcutList.get(0).getId()));
}
}
shortcutManager.addDynamicShortcuts(Collections.singletonList(shortcut));
}
示例2: removeShortcut
import android.content.pm.ShortcutManager; //導入方法依賴的package包/類
/**
* Remove the given card id from the app shortcuts, if such a
* shortcut exists.
*/
@TargetApi(25)
static void removeShortcut(Context context, int cardId)
{
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1)
{
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
List<ShortcutInfo> list = shortcutManager.getDynamicShortcuts();
String shortcutId = Integer.toString(cardId);
for(int index = 0; index < list.size(); index++)
{
if(list.get(index).getId().equals(shortcutId))
{
list.remove(index);
break;
}
}
shortcutManager.setDynamicShortcuts(list);
}
}
示例3: addDynamicShortcut
import android.content.pm.ShortcutManager; //導入方法依賴的package包/類
private void addDynamicShortcut(Place place) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
String name = HTTextUtils.isEmpty(place.getName()) ? place.getAddress() : place.getName();
int count = 0;
if (shortcutManager.getDynamicShortcuts() != null) {
count = shortcutManager.getDynamicShortcuts().size();
}
if (count > 2) {
String id = shortcutManager.getDynamicShortcuts().get(0).getId();
List<String> shortcutIds = new ArrayList<>();
shortcutIds.add(id);
shortcutManager.removeDynamicShortcuts(shortcutIds);
}
List<ShortcutInfo> shortcut = new ArrayList<>();
shortcut.add(0, new ShortcutInfo.Builder(this, place.getLocation().getLatLng().toString())
.setShortLabel(name)
.setIcon(Icon.createWithResource(this, R.drawable.ic_marker_gray))
.setIntent(new Intent(Intent.ACTION_VIEW,
Uri.parse("share.location://hypertrack")))
.build());
shortcutManager.addDynamicShortcuts(shortcut);
}
} catch (Exception e) {
Crashlytics.logException(e);
}
}
示例4: disableExistingShortcuts
import android.content.pm.ShortcutManager; //導入方法依賴的package包/類
private void disableExistingShortcuts() {
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
List<String> shortcutIds = new ArrayList<>();
for (ShortcutInfo shortcutInfo: shortcutManager.getDynamicShortcuts()) {
shortcutIds.add(shortcutInfo.getId());
}
shortcutManager.disableShortcuts(shortcutIds);
}
示例5: doCreateView
import android.content.pm.ShortcutManager; //導入方法依賴的package包/類
@Override
protected void doCreateView(View view) {
setHasOptionsMenu(true);
mAppListActivity = ((AppListActivity) getActivity());
new AppsPresenter(mAppListActivity, this);
RecyclerView mRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
mRecyclerView.setHasFixedSize(true);
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.addItemDecoration(new DividerItemDecoration(mAppListActivity, layoutManager.getOrientation()));
mAppInfoDBController = new AppInfoDBController(mAppListActivity);
Set<String> appPackageSet = new HashSet<>();
if (mAppListActivity.getIntent().getBooleanExtra(EXTRA_MANUAL_SHORTCUT, false)) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
ShortcutManager manager = mAppListActivity.getSystemService(ShortcutManager.class);
for (ShortcutInfo shortcutInfo : manager.getDynamicShortcuts()) {
appPackageSet.add(shortcutInfo.getId());
}
}
} else {
List<AppInfo> appInfoSet = mAppInfoDBController.getDisableApps(AppInfoDBOpenHelper.TABLE_NAME_APP_INFO);
for (AppInfo appInfo : appInfoSet) {
appPackageSet.add(appInfo.getAppPackageName());
}
}
mAppListAdapter = new AppListAdapter(mAppListActivity, mRecyclerView, appPackageSet);
mRecyclerView.setAdapter(mAppListAdapter);
int tabCategory = getArguments().getInt(TAB_CATEGORY);
mPresenter.getApps(tabCategory == 0 ? AppsRepository.APPS_FLAG_USER : AppsRepository.APPS_FLAG_SYSTEM);
initListener();
}
示例6: getChannelIdsOfShortcuts
import android.content.pm.ShortcutManager; //導入方法依賴的package包/類
@TargetApi(25)
public static List<String> getChannelIdsOfShortcuts(Context context) {
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
if (shortcutManager == null) {
return Collections.emptyList();
}
List<ShortcutInfo> shortcuts = shortcutManager.getDynamicShortcuts();
List<String> ids = new ArrayList<>(shortcuts.size());
for (ShortcutInfo shortcut : shortcuts) {
ids.add(shortcut.getId());
}
return ids;
}
示例7: updateShortcuts
import android.content.pm.ShortcutManager; //導入方法依賴的package包/類
static void updateShortcuts(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
List<ShortcutInfo> existingShortcuts = shortcutManager.getDynamicShortcuts();
// create and set dynamic shortcuts
ShortcutInfo debugShortcut = createShortcut(context,
AppShortcutActivity.EXTRA_TOGGLE_DEBUG_AWAKE,
PrefUtils.isAwakeDebugEnabled(context),
DEBUG_SHORTCUT_ID,
context.getString(R.string.awake_debug_toggle_short),
context.getString(R.string.awake_debug_toggle_long),
1);
ShortcutInfo acShortcut = createShortcut(context,
AppShortcutActivity.EXTRA_TOGGLE_AC_AWAKE,
PrefUtils.isAwakeAcEnabled(context),
AC_POWER_SHORTCUT_ID,
context.getString(R.string.awake_ac_toggle_short),
context.getString(R.string.awake_ac_toggle_long),
0);
List<ShortcutInfo> shortcuts = Arrays.asList(debugShortcut, acShortcut);
if (existingShortcuts.isEmpty()) {
shortcutManager.setDynamicShortcuts(shortcuts);
} else {
shortcutManager.updateShortcuts(shortcuts);
}
}
}