Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6567208
  • 博文数量: 1159
  • 博客积分: 12444
  • 博客等级: 上将
  • 技术积分: 12570
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-13 21:34
文章分类

全部博文(1159)

文章存档

2016年(126)

2015年(350)

2014年(56)

2013年(91)

2012年(182)

2011年(193)

2010年(138)

2009年(23)

分类: Android平台

2015-12-03 15:50:48



业务员有需求要将一个wap站在手机上以App的形式打开,还不要嵌套WebView,只能以浏览器打开.查了点资料,就有了下面这代码

点击(此处)折叠或打开

  1. package com.gzz.whyinzi;

  2. import android.net.Uri;
  3. import android.os.Bundle;
  4. import android.app.Activity;
  5. import android.content.Intent;
  6. import android.util.Log;
  7. import android.view.Menu;
  8. import android.view.View;

  9. public class MainActivity extends Activity {
  10.     private static final String TAG = "ActivityDemo";

  11.     @Override
  12.     protected void onCreate(Bundle savedInstanceState) {
  13.         super.onCreate(savedInstanceState);
  14.         setContentView(R.layout.activity_main);

  15.        
  16.         Intent intent = new Intent();
  17.         intent.setAction("android.intent.action.VIEW");
  18.         Uri content_url = Uri.parse(http://);
  19.         intent.setData(content_url);
  20.         startActivity(intent);

  21.        
  22.     }

  23.         @Override
  24.         protected void onResume() {
  25.             super.onResume();
  26.             Intent intent = new Intent();
  27.             intent.setAction("android.intent.action.VIEW");
  28.             Uri content_url = Uri.parse("");
  29.             intent.setData(content_url);
  30.             startActivity(intent);
  31.             Log.e(TAG, "start onResume~~~");
  32.         }

  33.         @Override
  34.         protected void onStop() {
  35.             super.onStop();
  36.             this.finish();
  37.             Log.e(TAG, "start onStop~~~");
  38.         }
  39. }

onResume()在没有默认浏览器的时候就起作用了,当没有默认浏览器的时候会弹出提示以哪个浏览器打开,如果点击取消就会出现黑色背景,为防止出现黑色背景,onsume()重新调用打开浏览器.

onStop()在选择浏览器后结束进程.



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