本文整理汇总了Java中android.content.pm.ShortcutManager.requestPinShortcut方法的典型用法代码示例。如果您正苦于以下问题:Java ShortcutManager.requestPinShortcut方法的具体用法?Java ShortcutManager.requestPinShortcut怎么用?Java ShortcutManager.requestPinShortcut使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.pm.ShortcutManager
的用法示例。
在下文中一共展示了ShortcutManager.requestPinShortcut方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pinShortcutToHomeScreen
import android.content.pm.ShortcutManager; //导入方法依赖的package包/类
private void pinShortcutToHomeScreen(Context context) {
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
if (shortcutManager.isRequestPinShortcutSupported()) {
ShortcutInfo pinShortcutInfo = createShortcutInfo(this);
Intent resultIntent = shortcutManager.createShortcutResultIntent(pinShortcutInfo);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, resultIntent, 0);
shortcutManager.requestPinShortcut(pinShortcutInfo, pendingIntent.getIntentSender());
} else {
Toast.makeText(context, R.string.device_does_not_support_shortcut_pinning, Toast.LENGTH_SHORT).show();
}
}
示例2: createPinnedShortcut
import android.content.pm.ShortcutManager; //导入方法依赖的package包/类
@TargetApi(26)
private void createPinnedShortcut(Card card, Icon icon) {
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
if (shortcutManager.isRequestPinShortcutSupported()) {
ShortcutInfo pin = new ShortcutInfo.Builder(context, card.getName() + "_pin")
.setShortLabel(card.getName())
.setIntent(createCardShortcutIntent(card))
.setIcon(icon)
.build();
shortcutManager.requestPinShortcut(pin, null);
}
}
示例3: sendShortcutBroadcast
import android.content.pm.ShortcutManager; //导入方法依赖的package包/类
private static void sendShortcutBroadcast(Context context, String shortcutId, Intent shortcutIntent, String title, Bitmap bitmap) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Icon icon = Icon.createWithBitmap(bitmap);
ShortcutInfo shortcutInfo = new ShortcutInfo.Builder(context, shortcutId)
.setIcon(icon)
.setShortLabel(title)
.setIntent(shortcutIntent)
.build();
ShortcutManager manager = context.getSystemService(ShortcutManager.class);
if (manager != null) {
manager.requestPinShortcut(shortcutInfo, null);
}
} else {
final Context app = context.getApplicationContext();
Intent intent = new Intent();
intent.setAction(SHURTCUT_ACTION);
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap);
context.sendBroadcast(intent);
Completable.complete()
.observeOn(Injection.provideMainThreadScheduler())
.subscribe(() -> Toast.makeText(app, R.string.success, Toast.LENGTH_SHORT).show());
}
}
示例4: pinAppShortcut
import android.content.pm.ShortcutManager; //导入方法依赖的package包/类
public static void pinAppShortcut(Context context) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
ShortcutManager mShortcutManager = context.getSystemService(ShortcutManager.class);
if(mShortcutManager.isRequestPinShortcutSupported()) {
ShortcutInfo pinShortcutInfo = new ShortcutInfo.Builder(context, "freeform_mode").build();
mShortcutManager.requestPinShortcut(pinShortcutInfo, null);
} else
U.showToastLong(context, R.string.pin_shortcut_not_supported);
} else
U.pinAppShortcut(context);
}
示例5: createOrRemoveRenameShortcutApi26
import android.content.pm.ShortcutManager; //导入方法依赖的package包/类
/**
* Create or remove rename shortcut from the home screen using ShortcutManager from API 25.
*
* @param create True if the shortcut should be created.
*/
@TargetApi(26)
private void createOrRemoveRenameShortcutApi26(boolean create) {
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
if (shortcutManager.isRequestPinShortcutSupported()) {
if (create) {
String label = mApplication.getApplicationContext().getString(R.string.rename_shortcut_name);
ShortcutInfo shortcut = new ShortcutInfo.Builder(this, DSCApplication.ID_SHORTCUT_RENAME)
.setShortLabel(label)
.setLongLabel(label)
.setIcon(Icon.createWithResource(mApplication.getApplicationContext(),
R.drawable.ic_manual_rename))
.setIntent(getActivityIntent())
.build();
try {
shortcutManager.requestPinShortcut(shortcut, null);
mApplication.updateShortcutPref(TYPE.INSTALL);
updateShortcutFields();
} catch (IllegalArgumentException e) {
showAlertDialog(android.R.drawable.ic_dialog_info,
mApplication.getApplicationContext().getString(R.string.create_rename_shortcut_v26_error),
DO_NOT_SHOW_IGNORED);
}
} else {
shortcutManager.disableShortcuts(Arrays.asList(DSCApplication.ID_SHORTCUT_RENAME));
mApplication.updateShortcutPref(TYPE.UNINSTALL);
updateShortcutFields();
}
}
}