intent跳转

实现跳转到网页,到本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;
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值