1.iOS
NSString *urlstr = @"www.baidu.com";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlstr]];
2.android
final Uri uri = Uri.parse("www.baidu.com"); final Intent it = new Intent(Intent.ACTION_VIEW, uri); startActivity(it);
或者
- import java.util.Timer;
- import java.util.TimerTask;
- import android.net.Uri;
- //执行app时调用浏览器打开 baidu
- //设定一个定时器,防止不能跳转
- 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秒后
- }