androidintent浏览器
A. Android 从浏览器链接打开App
需求很简单,通过Html页面中的一个超链接打开我们的App,实现也很简单。
网页:
scheme:代表Scheme的协议名称(必要族模)
host和path可选择添加
query:代表URL传递的数据
简单的写一个页面:
接卸来开始配置AndroidManifest.xml文件,在有 <action android:name="android.intent.action.MAIN" /> 的actvity配置下新增一个filter,注意是新增一个filter,例如:
这里注意scheme里参数和我们在html页面猜卜里的对应关系,不要弄错,多了,我们在a标签里还传递了参数,接受也很穗穗穗简单,例如:
写完,我们来看看效果:
成功实现,控制台的日志也能看到我们的参数确实传递过来了:
就这样,记录下来,收工。
B. 如何在Android中调用浏览器打开网页
android打开系统默认的软件,通常使用的是inent意图这个类,如下打开浏览器: Intent
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// get the view web intent
Intent intent = this.getViewWebIntent();
this.(intent);
// set the className to use the specific browser to open the webpage.
intent.setClassName("com.tencent.mtt", "com.tencent.mtt.MainActivity");
startActivity(intent);
}
/*
*get the desired view web intent
*/
private Intent getViewWebIntent() {
Intent viewWebIntent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("http://www.2cto.com");
viewWebIntent.setData(uri);
return viewWebIntent;
}
里面可以填上任意的url,也可以利用inent发送信息、拨打电话,记日历
C. Android开发之Intent.Action Android中Intent的各种常见作用【转】
1 Intent.ACTION_MAIN
String: Android.intent.action.MAIN标识Activity为一个程序的开始。比较常用。Input:nothingOutput:nothing
2 Intent.Action_CALL
【直接呼叫,在6.0之后的版本需要获取权限,详见 Android开发学习之路-Android6.0运行时权限【转】 】
Stirng: android.intent.action.CALL呼叫指定的电话号码。Input:电话号码。数据格式为:tel:+phone number Output:Nothing
Intent intent=new Intent(); intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:1320010001");
startActivity(intent);
3 Intent.Action.DIAL
String: action.intent.action.DIAL调用拨号面板
Intent intent=new Intent();intent.setAction(Intent.ACTION_DIAL); //android.intent.action.DIAL
intent.setData(Uri.parse("tel:1320010001");
startActivity(intent);
Input:电话号码。数据格式为:tel:+phone number Output:Nothing说明:打开Android的拨号UI。如果没有设置数据,则打开一个空的UI,如果设置数据,action.DIAL则通过调用getData()获取电话号码。但设置电话号码的数据格式为 tel:+phone number.
4 Intent.Action.ALL_APPS
String: andriod.intent.action.ALL_APPS列出所有的应用。Input:Nothing.Output:Nothing.
5Intent.ACTION_ANSWER
Stirng:android.intent.action.ANSWER处理呼入的电话。Input:Nothing.Output:Nothing.
6 Intent.ACTION_ATTACH_DATA
String: android.action.ATTCH_DATA别用于指定一些数据应该附属于一些其他的地方,例如,图片数据应该附属于联系人Input: DataOutput:nothing
7 Intent.ACTION_BUG_REPORT
String: android.intent.action.BUG_REPORT显示Dug报告。Input:nothingoutput:nothing
8 Intent.Action_CALL_BUTTON
String: android.action.intent.CALL_BUTTON.相当于用户按下“拨号”键。经测试显示的是“通话记录”Input:nothingOutput:nothing
Intent intent = new Intent(Intent.ACTION_CALL_BUTTON);startActivity(intent);
9 Intent.ACTION_CHOOSER
String: android.intent.action.CHOOSER显示一个activity选择器,允许用户在进程之前选择他们想要的,与之对应的是Intent.ACTION_GET_CONTENT.
10. Intent.ACTION_GET_CONTENT
String: android.intent.action.GET_CONTENT允许用户选择特殊种类的数据,并返回(特殊种类的数据:照一张相片或录一段音)
Input: TypeOutput:URI
int requestCode = 1001;Intent intent = new Intent(Intent.ACTION_GET_CONTENT); // "android.intent.action.GET_CONTENT"
intent.setType("image/*"); // 查看类型,如果是其他类型,比如视频则替换成 video/*,或 */*
Intent wrapperIntent = Intent.createChooser(intent, null);startActivityForResult(wrapperIntent, requestCode);
11 Intent.ACTION_VIEW
String:android.intent.action.VIEW用于显示用户的数据。比较通用,会根据用户的数据类型打开相应的Activity。比如 tel:13400010001打开拨号程序,http://www.g.cn则会打开浏览器等。
Uri uri = Uri.parse("http://www.google.com"); //浏览器 Uri uri =Uri.parse("tel:1232333"); //拨号程序
Uri uri=Uri.parse("geo:39.899533,116.036476"); //打开地图定位
Intent it = new Intent(Intent.ACTION_VIEW,uri);
startActivity(it);
//播放视频
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("file:///sdcard/media.mp4");
intent.setDataAndType(uri, "video/*");
startActivity(intent);
//调用发送短信的程序
Intent it = new Intent(Intent.ACTION_VIEW);
it.putExtra("sms_body", "信息内容...");
it.setType("vnd.android-dirs-sms");
startActivity(it);
12 Intent.ACTION_SENDTO
String: android.intent.action.SENDTO
说明:发送短信息
//发送短信息 Uri uri = Uri.parse("smsto:13200100001");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "信息内容...");
startActivity(it);
//发送彩信,设备会提示选择合适的程序发送 Uri uri = Uri.parse("content://media/external/images/media/23");
//设备中的资源(图像或其他资源)
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra("sms_body", "内容");
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType("image/png");
startActivity(it);
//Email Intent intent=new Intent(Intent.ACTION_SEND);
String[] tos={"[email protected]"};
String[] ccs={"[email protected]"};
intent.putExtra(Intent.EXTRA_EMAIL, tos);
intent.putExtra(Intent.EXTRA_CC, ccs);
intent.putExtra(Intent.EXTRA_TEXT, "The email body text");
intent.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
intent.setType("message/rfc822");
startActivity(Intent.createChooser(intent, "Choose Email Client"));
13 Intent.ACTION_GET_CONTENT
//选择图片 requestCode 返回的标识
Intent intent = new Intent(Intent.ACTION_GET_CONTENT); //"android.intent.action.GET_CONTENT"
intent.setType(contentType); //查看类型 String IMAGE_UNSPECIFIED = "image/*";
Intent wrapperIntent = Intent.createChooser(intent, null);
((Activity) context).startActivityForResult(wrapperIntent, requestCode);
//添加音频
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(contentType); //String VIDEO_UNSPECIFIED = "video/*";
Intent wrapperIntent = Intent.createChooser(intent, null);
((Activity) context).startActivityForResult(wrapperIntent, requestCode);
//拍摄视频
int rationLimit = getVideoCaptureDurationLimit(); //SystemProperties.getInt("ro.media.enc.lprof.ration", 60);
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
intent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, sizeLimit);
intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, rationLimit);
startActivityForResult(intent, REQUEST_CODE_TAKE_VIDEO);
//视频
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(contentType); //String VIDEO_UNSPECIFIED = "video/*";
Intent wrapperIntent = Intent.createChooser(intent, null);
((Activity) context).startActivityForResult(wrapperIntent, requestCode);
//录音
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(ContentType.AUDIO_AMR); //String AUDIO_AMR = "audior";
intent.setClassName("com.android.soundrecorder",
"com.android.soundrecorder.SoundRecorder");
((Activity) context).startActivityForResult(intent, requestCode);
//拍照 REQUEST_CODE_TAKE_PICTURE 为返回的标识
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //"android.media.action.IMAGE_CAPTURE";
intent.putExtra(MediaStore.EXTRA_OUTPUT, Mms.ScrapSpace.CONTENT_URI); // output,Uri.parse("content:/s/scrapSpace");
startActivityForResult(intent, REQUEST_CODE_TAKE_PICTURE);
D. 安卓开发怎么在APP内部调用手机系统浏览器打开指定html并获取HTML的数据
Android开发_如何调用 浏览器访问网页和Html文件
一、启动android默认浏览器
Intent intent= new Intent();
intent.setAction('android.intent.action.VIEW');
Uri content_url = Uri.parse('http://www.cnblogs.com');
intent.setData(content_url);
startActivity(intent);
这样子,android就可以调用起手机默认的浏览器访问。
二、指定相应的浏览器访问
1、指定android自带的浏览器访问
( “com.android.browser”:packagename ;“com.android.browser.BrowserActivity”:启动主activity)
Intent intent= new Intent();
intent.setAction('android.intent.action.VIEW');
Uri content_url = Uri.parse('http://www.cnblogs.com');
intent.setData(content_url);
intent.setClassName('com.android.browser','com.android.browser.BrowserActivity');
startActivity(intent);
2、启动其他浏览器(当然该浏览器必须安装在机器上)
只要修改以下相应的packagename 和 主启动activity即可调用其他浏览器
intent.setClassName('com.android.browser','com.android.browser.BrowserActivity');
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'
三、打开本地html文件
打开本地的html文件的时候,一定要指定某个浏览器,而不能采用方式一来浏览,具体示例代码如下
Intent intent= new Intent();
intent.setAction('android.intent.action.VIEW');
Uri content_url = Uri.parse('content://com.android.htmlfileprovider/sdcard/help.html');
intent.setData(content_url);
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文件把加到相应的后面就可以了
2、重新编译打包,安装,这样子,新的浏览器就支持”file“这个形式了
有兴趣的可以去试试。
E. Android从浏览器中打开本地应用
开发中遇到的一些问题特此记录:
1、应用场景一 在浏览器中要求直接打开到安装的应用中
需要在该应用的启动Activity 清单文件中进行配置
<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:host="com..test"
android:scheme="text"/>
</Intent-filter>
此处对应的data数据 跟服务器人员进行交互的时候为:text://com..test
2、中前应用场景二 在浏览器中进行打开 并且要求打开指定的具体的页面
首先得在清单文件中进行上面一样的配置 接着和从其他跳转的activity中获取的一样 ,通过intent来进行数据的获取
if(intent !=null) {
Uri uri = intent.getData();
if(uri !=null) {
String host = uri.getHost();
帆扒 LogUtil.d(TAG,host);
String data = uri.getQueryParameter("code");
try{
jumpData= URLDecoder.decode(data,"UTF-8");
LogUtil.d(TAG,jumpData);
}catch(UnsupportedEncodingException e) {
e.printStackTrace();
卖轿清 }
}
}
这样获取到的数据就是需要的数据 所要跳转的具体信息具体跳转类型都会获取到,然后在跟以前一样进行跳转就可以了。
F. Android 调用手机浏览器的正确方式
intent-filter详解
前提: 本人通过手机默认浏览器及html查看器都可以成功调起本地app
调起App时,获取到html中的内容如下,该内容被封装到Intent中,并通过 intent.getData()获取(使用Uri表示),我们通过uri.getQueryParameter()获取具体字段的值。
1.当App已启动时,也可以调起app,只是获取不到Intent中的数据。我的大概理解是Android中Activity启动时通过Intent在传递数据,如果我们的Activity已经启动,没有再次获取Intent对象,android:launchMode="singleInstance";这个需要其它同学解答下。
2.为什么我把Activity启动模式设置为android:launchMode="singleInstance"?因为如果我们使用默认的standard模式,会发现被调起的app的Activity运行在浏览器的任务栈中了。这是Activity启动模式对调起App的影响。
3.有什么不足之处,希望大家指正。谢谢
G. android开发怎么调用浏览器打开一个链接
在安卓代码中调用浏览器来打开相应的网页,一般有以下几种方式
调用默认浏览器。
其他浏览器。
自定义一个简单的WebView浏览器。
【原理】
主要是通过代码进行调用已有或者未有的浏览器进行打开相应的网页进行浏览。
【详细实现步奏】
一.调用默认浏览器
优缺点:部分手机可能连默认的浏览器都没有。
java">Intentintent=newIntent();
//Intentintent=newIntent(Intent.ACTION_VIEW,uri);
intent.setAction("android.intent.action.VIEW");
Uricontent_url=Uri.parse("此处填链接");
intent.setData(content_url);
startActivity(intent);
二.其他浏览器,制定打开
缺点:必须知道打开的浏览器的包名,大部分用户可能没有安装这些浏览器
Intentintent=newIntent();
intent.setAction("android.intent.action.VIEW");
Uricontent_url=Uri.parse("此处填链接");
intent.setData(content_url);
intent.setClassName("浏览器包名","浏览器首页");
startActivity(intent);
三.自定义一个简单的WebView浏览器
优缺点:推荐使用,不必担心手机上是否有浏览器。
mWebView=(WebView)findViewById(R.id.baseweb_webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(newWebViewClient());
WebViewmyWebView=(WebView)findViewById(R.id.webview);
myWebView.loadUrl("xxx.com");
【最后】
每种方法根据个人需要进行选用,没其他特别因素推荐使用第三种方案。