实现跳转到网页,到本app的其他页面,以及到其他的app的代码:
1. 跳转到浏览器网页
private void jumpToUrl() {
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
Uri content_url = Uri.parse("http://fir.im/microtest");
intent.setData(content_url);
startActivity(intent);
}
2. 跳转到本app的一个activity
private void jumpToFeedBack(Intent intent)
{
try {
intent.putExtra("fromActivity", "ScreenShotActivity");
intent.putExtra("picturePath", DoScreenShot.screenShotFilePath);
this.startActivity(intent);
}
catch(Throwable throwable)
{
Log.getStackTraceString(throwable);
}
}
3. 跳转到其他app的一个页面
private void jumpToMicroTest(String version, String buildNumber) {
try {
ComponentName componentName = new ComponentName("com.tmall.test.microtest", "com.tmall.test.microtest.module.bug.TMBugEditActivity");
// ComponentName componentName=new ComponentName("com.lany.screenshot","com.lany.screenshot.MainActivity");
Intent intent = new Intent();
intent.setComponent(componentName);
intent.setAction(Intent.ACTION_VIEW);
intent.putExtra("tmallVersion", version);//TMVersionUtil.getSimpleVersionInfo());
intent.putExtra("buildNumber", buildNumber);//BaseConfig.buildNumber);
intent.putExtra("picturePath", DoScreenShot.screenShotFilePath);
Log.d("tingxiangIntent", intent.getStringExtra("tmallVersion") + " " + intent.getStringExtra("buildNumber") + " " + intent.getStringExtra("picturePath"));
ComponentName cn = intent.resolveActivity(getPackageManager());
if(cn != null) {
startActivity(intent);
}
}
catch (Throwable throwable)
{
Toast.makeText(this,"您的版本过低",Toast.LENGTH_SHORT).show();
Log.getStackTraceString(throwable);
}
}
4. 检测手机上是否安装了某个app
private boolean appIsInstalled(String appName) {
List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
try {
for (int i = 0; i < packs.size(); i++) {
PackageInfo p = packs.get(i);
if (p.versionName == null) {
continue;
}
String app = p.applicationInfo.loadLabel(getPackageManager())
.toString();
if(app.equals(appName))
{
return true;
}
}
}
catch (Throwable throwable)
{
Log.getStackTraceString(throwable);
}
finally {
packs=null;
}
return false;
}