声明一个Activity,使用ACTION_MAIN作为Action,CATEGORY_DEFAULT作为Category,之后在调用Activity中,引入如下代码就可以自动生成所有匹配Action和Category的Activity的启动菜单了。
@Override
public boolean onCreateOptionsMenu(Menu menu){
Log.i("TestActivity", "Options Menu Created");
super.onCreateOptionsMenu(menu);
//menu.add(1, 0, 0, "EDIT");
// Create an Intent that describes the requirements to fulfill, to be included
// in our menu. The offering app must include a category value of Intent.CATEGORY_ALTERNATIVE.
Intent intent = new Intent(Intent.ACTION_MAIN, getIntent().getData());
intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
// Search for, and populate the menu with, acceptable offering applications.
menu.addIntentOptions(
1, // Menu group
0, // Unique item ID (none)
0, // Order for the items (none)
this.getComponentName(), // The current Activity name
null, // Specific items to place first (none)
intent, // Intent created above that describes our requirements
0, // Additional flags to control items (none)
null); // Array of MenuItems that corrolate to specific items (none)
return true;
}
---------------------------------------------------------
专注移动开发
Android, Windows Mobile, iPhone, J2ME, BlackBerry, Symbian
posted on 2010-01-31 19:32
TiGERTiAN 阅读(975)
评论(0) 编辑 收藏 所属分类:
Java 、
Android