`
007007jing
  • 浏览: 41268 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

android2.3 api demo 学习系列(19)--App/Intent and Launcher Shortcuts

阅读更多

第一个demo:Intent,根据指定的类型,枚举出所有符合条件的activity,让用户选择

 

 Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
 intent.setType("audio/*");
 startActivity(Intent.createChooser(intent, "Select music"));

 

 效果图:


第二个demo:为activity创建快捷方式:

1、首先需要在manifest中为activity配置action

 

<action android:name="android.intent.action.CREATE_SHORTCUT"/>

 

2、实现代码

 

Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
shortcutIntent.setClassName(this, this.getClass().getName());
shortcutIntent.putExtra(EXTRA_KEY, "ApiDemos Provided This Shortcut");

// Then, set up the container intent (the response to the caller)

Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_shortcuts_name));
Parcelable iconResource = Intent.ShortcutIconResource.fromContext(
	                this,R.drawable.launcher);
 intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
// Now, return the result to the launcher
setResult(RESULT_OK, intent);

代码中设置了快捷方式打开的activity,以及快捷方式的图片、名称,需要特别注意的是使用项目内的drawable资源需要使用Intent.ShortcutIconResource来包裹下。

如果使用bitmap可以直接放入就可以了

我们可以给任何activity添加快捷方式,方便用户快捷的使用某一常用功能

效果如:



  • 大小: 61.4 KB
  • 大小: 131 KB
  • 大小: 452.4 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics