1 app call web
package com.fan.test; import java.util.Timer; import java.util.TimerTask; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; public class TestActivity extends Activity { /** Called when the activity is first created. */ @Override //执行app时调用浏览器打开 baidu //设定一个定时器,防止不能跳转 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Uri uri = Uri.parse("http://www.baidu.com"); final Intent it = new Intent(Intent.ACTION_VIEW, uri); Timer timer = new Timer(); TimerTask task = new TimerTask() { @Override public void run() { startActivity(it); //执行 } }; timer.schedule(task, 1); //10秒后 } //返回时自动退出 public void onRestart() { super.onRestart(); System.exit(0); } }
Button bn = (Button)findViewById(R.id.button1); bn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub //doLogin(true,true); //printStringJNI("hello"); final Uri uri = Uri.parse("http://www.baidu.com"); final Intent it = new Intent(Intent.ACTION_VIEW, uri); //不用定时器也行, 不是必须的 Timer timer = new Timer(); TimerTask task = new TimerTask() { @Override public void run() { startActivity(it); //执行 } }; timer.schedule(task, 2000); //10秒后 } });
androidManifest.xml 文件中加入
<activity android:name=".TestActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </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="http" /> <data android:scheme="https" /> <data android:scheme="about" /> <data android:scheme="javascript" /> </intent-filter> </activity>
2 web call app