在开发中,发现好多应用,有直接跳转到应用市场的过程,后来也是请教别人才实现的,下面我就分享下小经验:
try{
Activity activity = getActivity();if(activity == null||activity.isFinishing()){
if(LogLevel.MARKET){
MarketLog.e(TAG,"activity is null or finishing");
}
return;
String packetName = activity.getPacketName();
Uri uri = Uri.parse("market://details?id="+packetName);
Intent intent_market = new Intent(Intent.ACTION_VIEW,uri);
getActivity.startActivity(intent_market);
}catch{...}
}
packetName 这里得到的包名是注册清单根节点的那个包名,唯一的。
有时,项目的需要,需要点击一个按钮弹出菜单,我们可以这样做:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_settings) {
// open settings option
doOpenSettings();
} else if (item.getItemId() == R.id.action_logout) {
// open logout option
doLogout();
} else if (item.getItemId() == R.id.action_graph) {
// open graph option
doCreateGraph();
} else if (item.getItemId() == R.id.action_syncUpload) {
// sync upload option
doSyncUpload();
}
return true;
};
// 呼出菜单
openOptionsMenu();