Chinaunix首页 | 论坛 | 博客
  • 博客访问: 415355
  • 博文数量: 125
  • 博客积分: 2066
  • 博客等级: 大尉
  • 技术积分: 1032
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-16 14:06
文章分类

全部博文(125)

文章存档

2011年(125)

分类: LINUX

2011-06-08 10:21:22

http://blog.csdn.net/yufan1987/archive/2011/03/04/6222540.aspx 

 An原创droid App 调用自带浏览器 收藏

Android App 调用自带浏览器:

   简单的一个功能点,像桌面快捷方式一样,调用浏览器打开一个网页。

  1. package com.fan.test;  
  2.   
  3. import java.util.Timer;  
  4. import java.util.TimerTask;  
  5.   
  6. import android.app.Activity;  
  7. import android.content.Intent;  
  8. import android.net.Uri;  
  9. import android.os.Bundle;  
  10.   
  11. public class TestActivity extends Activity {  
  12.     /** Called when the activity is first created. */  
  13.     @Override  
  14.     //执行app时调用浏览器打开 baidu  
  15.     //设定一个定时器,防止不能跳转  
  16.     public void onCreate(Bundle savedInstanceState) {  
  17.         super.onCreate(savedInstanceState);  
  18.         final Uri uri = Uri.parse("");          
  19.         final Intent it = new Intent(Intent.ACTION_VIEW, uri);          
  20.           
  21.         Timer timer = new Timer();  
  22.         TimerTask task = new TimerTask() {  
  23.                @Override  
  24.                public void run() {  
  25.                 startActivity(it); //执行  
  26.                }  
  27.               };  
  28.             timer.schedule(task, 1); //10秒后  
  29.     }    
  30.       
  31.     //返回时自动退出  
  32.     public void onRestart()  
  33.     {  
  34.         super.onRestart();          
  35.         System.exit(0);  
  36.   
  37.     }  
  38. }  

 Android 浏览器的配置文件:

  packages\apps\Browser\AndroidManifest.xml

  1. xml version="1.0" encoding="utf-8"?>  
  2. <manifest xmlns:android=""  
  3.       package="com.fan.test"  
  4.       android:versionCode="1"  
  5.       android:versionName="1.0">  
  6.     <application android:icon="@drawable/clients" android:label="@string/app_name">  
  7.         <activity android:name=".TestActivity"  
  8.                   android:label="@string/app_name">  
  9.             <intent-filter>  
  10.                 <action android:name="android.intent.action.MAIN" />  
  11.                 <category android:name="android.intent.category.LAUNCHER" />  
  12.             intent-filter>             
  13.             <intent-filter>  
  14.                 <action android:name="android.intent.action.VIEW" />  
  15.                 <category android:name="android.intent.category.DEFAULT" />  
  16.                 <category android:name="android.intent.category.BROWSABLE" />  
  17.                 <data android:scheme="http" />  
  18.                 <data android:scheme="https" />  
  19.                 <data android:scheme="about" />  
  20.                 <data android:scheme="javascript" />  
  21.             intent-filter>  
  22.               
  23.         activity>  
  24.   
  25.     application>  
  26.     <uses-sdk android:minSdkVersion="8" />  
  27.   
  28. manifest>   

如果需要对file支持,则加上

  1. <intent-filter>  
  2.     <action android:name="android.intent.action.VIEW" />  
  3.     <category android:name="android.intent.category.DEFAULT" />  
  4.     <category android:name="android.intent.category.BROWSABLE" />  
  5.     <data android:scheme="file" />  
  6. intent-filter> 

阅读(987) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~