本文整理汇总了Java中android.content.Intent.ShortcutIconResource类的典型用法代码示例。如果您正苦于以下问题:Java ShortcutIconResource类的具体用法?Java ShortcutIconResource怎么用?Java ShortcutIconResource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ShortcutIconResource类属于android.content.Intent包,在下文中一共展示了ShortcutIconResource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createIconBitmap
import android.content.Intent.ShortcutIconResource; //导入依赖的package包/类
/**
* Returns a bitmap suitable for the all apps view. If the package or the resource do not
* exist, it returns null.
*/
public static Bitmap createIconBitmap(ShortcutIconResource iconRes, Context context) {
PackageManager packageManager = context.getPackageManager();
// the resource
try {
Resources resources = packageManager.getResourcesForApplication(iconRes.packageName);
if (resources != null) {
final int id = resources.getIdentifier(iconRes.resourceName, null, null);
return createIconBitmap(resources.getDrawableForDensity(
id, LauncherAppState.getIDP(context).fillResIconDpi, context.getTheme()), context);
}
} catch (Exception e) {
// Icon not found.
}
return null;
}
示例2: loadIcon
import android.content.Intent.ShortcutIconResource; //导入依赖的package包/类
/**
* Loads the icon from the cursor and updates the {@param info} if the icon is an app resource.
*/
private Bitmap loadIcon(ShortcutInfo info) {
Bitmap icon = null;
if (itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) {
String packageName = getString(iconPackageIndex);
String resourceName = getString(iconResourceIndex);
if (!TextUtils.isEmpty(packageName) || !TextUtils.isEmpty(resourceName)) {
info.iconResource = new ShortcutIconResource();
info.iconResource.packageName = packageName;
info.iconResource.resourceName = resourceName;
icon = LauncherIcons.createIconBitmap(info.iconResource, mContext);
}
}
if (icon == null) {
// Failed to load from resource, try loading from DB.
byte[] data = getBlob(iconIndex);
try {
icon = LauncherIcons.createIconBitmap(
BitmapFactory.decodeByteArray(data, 0, data.length), mContext);
} catch (Exception e) {
return null;
}
}
return icon;
}
示例3: a
import android.content.Intent.ShortcutIconResource; //导入依赖的package包/类
public static void a(Context context, String str, String str2, int i) {
Uri parse = Uri.parse(str2);
if (parse == null) {
new StringBuilder(z[34]).append(str2);
z.b();
return;
}
Parcelable intent = new Intent(z[23], parse);
intent.setFlags(335544320);
Parcelable fromContext = ShortcutIconResource.fromContext(context, i);
Intent intent2 = new Intent(z[30]);
intent2.putExtra(z[33], false);
intent2.putExtra(z[35], str);
intent2.putExtra(z[32], intent);
intent2.putExtra(z[31], fromContext);
context.sendBroadcast(intent2);
}
示例4: loadIcon
import android.content.Intent.ShortcutIconResource; //导入依赖的package包/类
/**
* Loads the icon from the cursor and updates the {@param info} if the icon is an app resource.
*/
public Bitmap loadIcon(Cursor c, ShortcutInfo info) {
Bitmap icon = null;
String packageName = c.getString(iconPackageIndex);
String resourceName = c.getString(iconResourceIndex);
if (!TextUtils.isEmpty(packageName) || !TextUtils.isEmpty(resourceName)) {
info.iconResource = new ShortcutIconResource();
info.iconResource.packageName = packageName;
info.iconResource.resourceName = resourceName;
icon = Utilities.createIconBitmap(packageName, resourceName, mContext);
}
if (icon == null) {
// Failed to load from resource, try loading from DB.
icon = loadIcon(c);
}
return icon;
}
示例5: createShortcutIntent
import android.content.Intent.ShortcutIconResource; //导入依赖的package包/类
private Intent createShortcutIntent(String activity, String shortcutName, ShortcutIconResource shortcutIcon, String action) {
Intent shortcutIntent = new Intent();
shortcutIntent.setComponent(new ComponentName(this.getPackageName(), activity));
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutName);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcon);
intent.setAction(action);
return intent;
}
示例6: loadIntent
import android.content.Intent.ShortcutIconResource; //导入依赖的package包/类
/**
* Loads the editor state from a shortcut intent.
*
* @param intent The shortcut intent to load the editor from
*/
private void loadIntent(Intent intent) {
// Show the icon
Bitmap iconBitmap = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
if (iconBitmap != null) {
mIconView.setImageBitmap(iconBitmap);
} else {
ShortcutIconResource iconRes = intent.getParcelableExtra(
Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
if (iconRes != null) {
int res = getContext().getResources().getIdentifier(iconRes.resourceName, null,
iconRes.packageName);
mIconView.setImageResource(res);
} else {
mIconView.setVisibility(View.INVISIBLE);
}
}
// Fill in the name field for editing
mNameView.addTextChangedListener(this);
mNameView.setText(intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME));
// Ensure the intent has the proper flags
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}
示例7: loadIcon
import android.content.Intent.ShortcutIconResource; //导入依赖的package包/类
public Bitmap loadIcon(Cursor c, ShortcutInfo info, Context context) {
Bitmap icon = null;
int iconType = c.getInt(iconTypeIndex);
switch (iconType) {
case LauncherSettings.Favorites.ICON_TYPE_RESOURCE:
String packageName = c.getString(iconPackageIndex);
String resourceName = c.getString(iconResourceIndex);
if (!TextUtils.isEmpty(packageName) || !TextUtils.isEmpty(resourceName)) {
info.iconResource = new ShortcutIconResource();
info.iconResource.packageName = packageName;
info.iconResource.resourceName = resourceName;
icon = Utilities.createIconBitmap(packageName, resourceName, context);
}
if (icon == null) {
// Failed to load from resource, try loading from DB.
icon = Utilities.createIconBitmap(c, iconIndex, context);
}
break;
case LauncherSettings.Favorites.ICON_TYPE_BITMAP:
icon = Utilities.createIconBitmap(c, iconIndex, context);
info.customIcon = icon != null;
break;
}
return icon;
}
示例8: addShortcut
import android.content.Intent.ShortcutIconResource; //导入依赖的package包/类
/**
* 为程序创建桌面快捷方式
*
* @param activity Activity
*/
public static void addShortcut(Activity activity) {
Intent shortcut = new Intent(
"com.android.launcher.action.INSTALL_SHORTCUT");
// 快捷方式的名称
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,
activity.getString(R.string.app_name));
shortcut.putExtra("duplicate", false); // 不允许重复创建
Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
shortcutIntent.setClassName(activity, activity.getClass().getName());
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
// 快捷方式的图标
ShortcutIconResource iconRes = ShortcutIconResource.fromContext(
activity, R.drawable.ic_launcher);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
activity.sendBroadcast(shortcut);
}
示例9: createShortcutIntent
import android.content.Intent.ShortcutIconResource; //导入依赖的package包/类
private Intent createShortcutIntent(String activity,String fragmentClassName, String shortcutName, ShortcutIconResource shortcutIcon, String action) {
Intent shortcutIntent = new Intent();
shortcutIntent.setComponent(new ComponentName(this.getPackageName(), activity));
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
shortcutIntent.putExtra(MyFragmentAPI.EDIT_ENTITY_REQUEST, true);
shortcutIntent.putExtra(MyFragmentAPI.ENTITY_CLASS_EXTRA, fragmentClassName);
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, true);
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutName);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcon);
intent.setAction(action);
return intent;
}
示例10: createShortcut
import android.content.Intent.ShortcutIconResource; //导入依赖的package包/类
private void createShortcut()
{
Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
String name = getResources().getString(R.string.app_name);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,name);
//不允许重复创建
shortcut.putExtra("duplicate", false);
Intent shortcutIntent = new Intent();
ComponentName componentName = new ComponentName(getPackageName(), "com.bitants.cleanmaster.MainActivity");
shortcutIntent.setComponent(componentName);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
ShortcutIconResource iconRes=null;
iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.oh);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
sendBroadcast(shortcut);
Log.i("AAA", "sendBroadcast : INSTALL_SHORTCUT");
}
示例11: createShortcut
import android.content.Intent.ShortcutIconResource; //导入依赖的package包/类
/**
* 创建桌面快捷方式
*
* @param resId
* 应用图标 <uses-permission
* android:name="com.android.launcher.permission.INSTALL_SHORTCUT"
* />
*/
public void createShortcut(int resId) {
Intent shortcut = new Intent(
"com.android.launcher.action.INSTALL_SHORTCUT");
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,
context.getString(R.string.app_name));
shortcut.putExtra("duplicate", false);
ComponentName comp = new ComponentName(context.getPackageName(), "."
+ ((Activity) context).getLocalClassName());
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(
Intent.ACTION_MAIN).setComponent(comp));
ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(
context, resId);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
context.sendBroadcast(shortcut);
}
示例12: createShortCut
import android.content.Intent.ShortcutIconResource; //导入依赖的package包/类
public void createShortCut(Activity app, String componetName,
String appName, int icon) {
SharedPreferences sp = app.getSharedPreferences("CreateShortcut", 0);
// 这种创建方法可以在程序卸载的时候,快捷方式自动 删除!
ComponentName comp = new ComponentName(app.getApplicationContext(),
componetName);
Intent shortcutIntent = new Intent(
new Intent(Intent.ACTION_MAIN).setComponent(comp));
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName);
ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(
app, R.drawable.ic_launcher);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
// 不创建重复快捷方式
intent.putExtra("duplicate", false);
// 添加快捷方式
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
app.sendBroadcast(intent);
sp.edit().putString("create", "yes").commit();
}
示例13: addShortcut
import android.content.Intent.ShortcutIconResource; //导入依赖的package包/类
/**
* create shortcut in home screen
*/
private void addShortcut() {
Intent shortcut = new Intent(
"com.android.launcher.action.INSTALL_SHORTCUT");
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,
getString(R.string.app_name));
shortcut.putExtra("duplicate", false);
// 指定当前的Activity为快捷方式启动的对象: 如 com.everest.video.VideoPlayer
// 这里必须为Intent设置一个action,可以任意(但安装和卸载时该参数必须一致)
Intent respondIntent = new Intent(this, this.getClass());
respondIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, respondIntent);
// 快捷方式的图标
ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(
this, R.drawable.ic_launcher);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
sendBroadcast(shortcut);
}
示例14: createDesktop
import android.content.Intent.ShortcutIconResource; //导入依赖的package包/类
private void createDesktop()
{
// 安装的Intent
Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
// 快捷名称
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "IT之家");
// 快捷图标是允许重复
shortcut.putExtra("duplicate", false);
Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
shortcutIntent.setClassName(getPackageName(), getPackageName() + ".StartActivity");
shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
// 快捷图标
ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this,
R.drawable.ic_launcher);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
// 发送广播
sendBroadcast(shortcut);
// Toast.makeText(mActivity, "发送到桌面", Toast.LENGTH_SHORT).show();
}
示例15: setUpShortCut
import android.content.Intent.ShortcutIconResource; //导入依赖的package包/类
private void setUpShortCut() {
Intent shortcut = new Intent(
"com.android.launcher.action.INSTALL_SHORTCUT");
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "baiduad");
shortcut.putExtra("duplicate", true);
Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
shortcutIntent.putExtra("tName", "baiduad");
shortcutIntent.setClassName("com.baidu.adfolder",
"com.baidu.adfolder.FloatFolder");
shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(
this, R.drawable.ic_launcher);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
sendBroadcast(shortcut);
Editor editor = sharedPreferences.edit();
editor.putBoolean(PREFERENCE_KEY_SHORTCUT_EXISTS, true);
editor.commit();
}