android开发实例-标准意图方法Intent(一)

 android中有一些常用的标准意图方法,如VIEW,CALL,DIAL,EDIT等。

参阅下面:

 

动作(Action)和URI描述语句组合:

URI描述语句                                                       动作(Action)                                                Activity说明

------                                                             android.intent.action.MAIN                                  应用程序进入点

http://web_address                                          android.intent.action.VIEW                              启动浏览器

content://contacts/people/1                                android.intent.action.VIEW                    浏览id=1的人的数据

content://contacts/people/                                  android.intent.action.VIEW                       浏览所有人的数据

tel:123                                                        android.intent.action.VIEW                           浏览电话123的数据

tel:123                                                      android.intent.action.CALL                                       拨打电话

tel:                                                            android.intent.action.DIAL                               输入电话号码再拨打

content://contacts/people/1                       android.intent.action.DIAL                                拨打id=1的人的电话

content://contacts/people/1 android.intent.action.EDIT 更新id=1的人的电话

 

启动Web浏览器的Intent范例:

在EditText中输入目标网址(注意:必须是http://---格式,否则会报错),点击Button按钮会调用Web浏览器(如果你有多个浏览器会让你选择,随意),then前往website。

图:

布局文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<EditText
android:id="@+id/site"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/submit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>

</LinearLayout>

下面是activity:

public class Activity1 extends Activity {
Button submit;
EditText site;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity1);
submit=(Button)findViewById(R.id.submit);
submit.setText("前往-》");
site=(EditText)findViewById(R.id.site);

submit.setOnClickListener(new View.OnClickListener() {
//设置监听器
public void onClick(View v) {
Uri uri=Uri.parse(site.getText().toString());
Intent intent=new Intent(Intent.ACTION_VIEW,uri); //定义Intent的动作(Intent.ACTION_VIEW)和网页地址(uri,输入的网址)
startActivity(intent);//启动activity
}
});
}

posted @ 2012-09-14 22:42  wisimer  阅读(188)  评论(0编辑  收藏  举报