Android_如何创建桌面快捷方式
2013-11-01 10:16
465 查看
在Android官方的room(当然其他room有可能是,有可能不是,如MiUi就不是)程序安装之后,程序的图片是放到主界面抽屉里面的。
用户每次使用的时候都需要先打开抽屉然后选择应用程序,这样相当的不方面,当然用户可以自己将程序图标放到桌面上去,但是如果,
我们想再程序中去实现这个问题,那该如何呢?
[java] view plaincopy
public static void createShortCut(Context context) {
final Intent addIntent = new Intent(
"com.android.launcher.action.INSTALL_SHORTCUT");
final Parcelable icon = Intent.ShortcutIconResource.fromContext(
context, R.drawable.icon); // 获取快捷键的图标
addIntent.putExtra("duplicate", false);
final Intent myIntent = new Intent(context,XX.class);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
context.getString(R.string.mobile_site_shortcut_name));// 快捷方式的标题
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);// 快捷方式的图标
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, myIntent);// 快捷方式的动作
context.sendBroadcast(addIntent);
}
代码中如此,然后在AndroidMainifest.xml中添加一个权限:
[java] view plaincopy
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
这样即可。
你使用的时候,你可能会发现这样的方式来创建快捷方式,只是对程序的主Activity其作用,也就是含有:
[java] view plaincopy
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
这样标签的Activity其作用,那么如何给指定的一个Acitivity创建一个快捷方式呢?
其实也很简单,你只需要给你的Activity种添加:
[java] view plaincopy
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT" />
</intent-filter>
该标签即可。
///////////////////////////////////另一种方式///////////////////////////////////
用户每次使用的时候都需要先打开抽屉然后选择应用程序,这样相当的不方面,当然用户可以自己将程序图标放到桌面上去,但是如果,
我们想再程序中去实现这个问题,那该如何呢?
[java] view plaincopy
public static void createShortCut(Context context) {
final Intent addIntent = new Intent(
"com.android.launcher.action.INSTALL_SHORTCUT");
final Parcelable icon = Intent.ShortcutIconResource.fromContext(
context, R.drawable.icon); // 获取快捷键的图标
addIntent.putExtra("duplicate", false);
final Intent myIntent = new Intent(context,XX.class);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
context.getString(R.string.mobile_site_shortcut_name));// 快捷方式的标题
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);// 快捷方式的图标
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, myIntent);// 快捷方式的动作
context.sendBroadcast(addIntent);
}
代码中如此,然后在AndroidMainifest.xml中添加一个权限:
[java] view plaincopy
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
这样即可。
你使用的时候,你可能会发现这样的方式来创建快捷方式,只是对程序的主Activity其作用,也就是含有:
[java] view plaincopy
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
这样标签的Activity其作用,那么如何给指定的一个Acitivity创建一个快捷方式呢?
其实也很简单,你只需要给你的Activity种添加:
[java] view plaincopy
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT" />
</intent-filter>
该标签即可。
///////////////////////////////////另一种方式///////////////////////////////////
private void creatdeskicon() {//创建桌面图标 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 //注意: ComponentName的第二个参数必须加上点号(.),否则快捷方式无法启动相应程序 ComponentName comp = new ComponentName(this.getPackageName(), "."+this.getLocalClassName()); shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp)); //快捷方式的图标 ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes); sendBroadcast(shortcut); }
相关文章推荐
- Android应用开发之(如何自动在桌面创建快捷方式)
- Android应用开发之(如何自动在桌面创建快捷方式)
- Android_如何为一个app创建桌面快捷方式
- Android如何创建桌面快捷方式
- Android_如何创建桌面快捷方式
- Android 为应用程序创建桌面快捷方式
- Android学习之程序创建桌面快捷方式
- Android用程序在桌面创建app快捷方式
- Ubuntu下如何在桌面创建一个应用程序的“快捷方式”?
- Android应用启动后自动创建桌面快捷方式
- Android创建桌面快捷方式几种方法
- 如何在Linux的桌面上创建快捷方式或启动器
- Android 创建桌面快捷方式
- [Android]为指定的应用创建桌面快捷方式
- ACCESS 中如何用 WSH 创建桌面快捷方式
- Android应用启动后自动创建桌面快捷方式
- Android创建桌面快捷方式几种方法
- Android创建桌面快捷方式
- android 检查是否创建桌面快捷方式
- Android应用启动后自动创建桌面快捷方式