【android开发】桌面快捷方式
在桌面上添加一个组件的快捷方式很简单,只要长按桌面 或者点击menu键,就可弹出添加桌面组件的选项 shortcuts为添加快捷方式。下面通过代码将应用程序添加到shortcuts列表中1.首先在要设置为快捷方式的应用程序中,添加一个IntentFilter
在AndroidManifest.xml中
<activity android:name=".AlarmActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.action.CREATE_SHORTCUT" />
</intent-filter> </activity> 2.设置快捷方式的名字,图标,事件等属性,在组件的onCreate方法中设置
public void onCreate(Bundle b) { super.onCreate(b);// 要添加的快捷方式IntentIntent addShortcut;//判断是否要添加快捷方式if(getIntent().getAction().equals(Intent.ACTION_CREATE_SHORTCUT)) {addShortcut = new Intent();//设置名字addShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,"短信发送器");//快捷方式使用图片Parcelable icon = Intent.ShortcutResource.fromContext(this,R.drawable.icon);addShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,icon);//快捷方式要执行的IntentIntent intent = new Intent(Intent.ACTION_SENDTO,Uri.parse("mailto:xxx@xx.com"));addShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT,mailto);//oksetResult(RESULT_OK,addShortcut);} else {setResult(RESULT_CANCEL);}finish();}
页:
[1]