您的位置:首页 > 移动开发 > Android开发

Android创建快捷方式,Phonegap创建快捷方式

2014-04-22 14:27 459 查看
Android中创建快捷方式:

在主Activity的OnCreate中,

SharedPreferences preferences = getSharedPreferences("count",MODE_WORLD_READABLE);

int count = preferences.getInt("count", 0);

if (count == 0) {

//当前Activity的名字,显示的图标,app的名字

createShortCut(MainActivity.this,R.drawable.ic_launcher,R.string.app_name);

}

Editor editor = preferences.edit();

editor.putInt("count", ++count);

editor.commit();

public void createShortCut(Activity act, int iconResId, int appnameResId) {

Intent shortcutintent = new Intent(

"com.android.launcher.action.INSTALL_SHORTCUT");

shortcutintent.putExtra("duplicate", false);

shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME,

act.getString(appnameResId));

Parcelable icon = Intent.ShortcutIconResource.fromContext(

act.getApplicationContext(), iconResId);

shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);

shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,

new Intent(act.getApplicationContext(), act.getClass()));

act.sendBroadcast(shortcutintent);

}

AndroidManifest.xml中权限允许:

<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>

了解更多可以看:http://www.xmumu.com/post/2012-04-01/17357119

Phonegap创建快捷方式:

暂时没有方法,还在研究中,如果大家知道,麻烦能留言指导一下,非常感谢!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: