Android 里的intent 比较好玩,那么什么是系统意图?就是调用个浏览器,拨号盘等等。
这个实例比较简洁,请自行脑补 or 创建 一个hello world 项目。
打开系统浏览器
编辑主 Activity 的onCreate 方法。
Intent intent = new Intent(Intent.ACTION_VIEW);
获取Android 的intent
intent.setData(Uri.parse("http://www.baidu.com"));
设置数据
startActivity(intent);
开始个intent
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.baidu.com"));
startActivity(intent);
}
});
}
自己创建个打开方式
如何自己创建个intent, 当用户点击一个http请求时,会启动我们的Activity。
很简单其实将我们自己的Activity 添加个过滤就可以,只要程序在运行,用户只要符合过滤的就能够激活我们的活动。
AndroidManifest.xml <Activity>...</Activity>
<action android:name="android.intent.action.VIEW"/>
指定一个intent 的打开系统Intent(可多个)
<category android:name="android.intent.category.DEFAULT"/>
指定个类别(可多个)
<data android:scheme="http"/>
指定打开方式(可多个)
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="http"/>
<data android:scheme="https"/>
</intent-filter>