如何用手机浏览器去下载app?


package com.example.text;



import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
/**
* 启动浏览器去下载app
* 或打开网页
* @author androidstartjack
*
*/
public class MainActivity extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.clickMyDown1).setOnClickListener(new OnClickListener() {


@Override
public void onClick(View v) {
/**
* setAction方法设置指定那个浏览器启动:如
* 1. 系统默认浏览器 android.intent.action.VIEW
**/
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
Uri content_url = Uri.parse("http://gdown.baidu.com/data/wisegame/3c00add7144d3915/kugouyinle.apk");
intent.setData(content_url);
intent.setClassName("com.android.browser","com.android.browser.BrowserActivity");
startActivity(intent);


}
});
/**
* 2、启动其他浏览器(当然该浏览器必须安装在机器上)
*  (“com.android.browser”:packagename;“com.android.browser.BrowserActivity”:启动主activity)
*
*/




findViewById(R.id.clickMyDown2).setOnClickListener(new OnClickListener() {


@Override
public void onClick(View v) {
/**
* setAction方法设置指定那个浏览器启动:如
* 1. 系统默认浏览器 android.intent.action.VIEW
**/
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
Uri content_url = Uri.parse("http://gdown.baidu.com/data/wisegame/3c00add7144d3915/kugouyinle.apk");
intent.setData(content_url);
//intent.setClassName("com.uc.browser", "com.uc.browser.ActivityUpdate");
startActivity(intent);


}
});




/**
* 用浏览器加载本地html
*/
// uc浏览器":"com.uc.browser", "com.uc.browser.ActivityUpdate"
//  opera:"com.opera.mini.android", "com.opera.mini.android.Browser"
// qq浏览器:"com.tencent.mtt", "com.tencent.mtt.MainActivity"
findViewById(R.id.clickMyDown3).setOnClickListener(new OnClickListener() {


@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
Uri content_url = Uri.parse("content://com.android.htmlfileprovider/sdcard/user_treaty.html");
intent.setData(content_url);
//intent.setClassName("com.uc.browser", "com.uc.browser.ActivityUpdate");//启动uc浏览器
//intent.setClassName("com.opera.mini.android", "com.opera.mini.android.Browser");//启动opera
//intent.setClassName("com.tencent.mtt", "com.tencent.mtt.MainActivity");//启动qq浏览器:
intent.setClassName("com.android.browser","com.android.browser.BrowserActivity");//启动默认的浏览器
startActivity(intent);


}
});
}


/*
* 注意:
*
* 关键点是调用了”content“这个filter。
以前有在win32编程的朋友,可能会觉得用这种形式”file://sccard/help.html“是否可以,可以很肯定的跟你说,默认的浏览器设置是没有对”file“这个进行解析的,如果要让你的默认android浏览器有这个功能需要自己到android源码修改manifest.xml 文件,然后自己编译浏览器代码生成相应的apk包来重新在机器上安装。
大体的步骤如下:
1、打开 packages/apps/Browser/AndroidManifest.xml文件把加到相应的<intent-filter>后面就可以了
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" />
</intent-filter>
2、重新编译打包,安装,这样子,新的浏览器就支持”file“这个形式了。*/

}

更多相关文章

  1. android 布局文件 layout_weight用法
  2. android 中xml文件中出现 Attr.value missing 错误
  3. 获得Android Linux系统增删文件的权限
  4. android 文件系统(
  5. 关于声明文件中android:process属性说明
  6. Android 自定义View及其在布局文件中的使用示例(三):结合Android
  7. Android 4.4 SD卡文件读写变化
  8. Android 自动编译、打包生成apk文件 2 - 使用原生Ant方式
  9. Android学习之路(一)之 Android文件简单介绍

随机推荐

  1. android 获取设备真实ip地址
  2. anroid 7.1添加自定义api服务
  3. Android圆角自定义View
  4. Android调试工具 —— TraceView [整理]
  5. Writing code that captures videos on A
  6. Android中使用HttpURLConnection和HttpCl
  7. android 5.0之后利用Intent传递Serializa
  8. Android面试宝典2020-持续更新
  9. Android(安卓)编译SurfaceFlinger测试程
  10. Android五种隐藏状态栏和标题栏的方法