Intent的Data和Type和Flag属性-amdroid学习之旅(五十一)

来源:互联网 发布:网站漏洞检测软件 编辑:程序博客网 时间:2024/06/16 02:12

Data属性介绍

这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述

使用Data和Action属性启动系统Activity

这里写图片描述

代码示例

public class MainActivity extends Activity{    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);    }    public void btn(View view){        Intent intent = new Intent();        intent.setAction(Intent.ACTION_VIEW);        String data  = "http://www.baidu.com";        Uri dataUri = Uri.parse(data);        intent.setData(dataUri);        startActivity(intent);    }    public void edit(View view){        Intent intent = new Intent();        intent.setAction(Intent.ACTION_EDIT);        String data  = "content://com.android.contacts/contacts/1";        Uri dataUri = Uri.parse(data);        intent.setData(dataUri);        startActivity(intent);    }   public void call(View view){       Intent intent = new Intent();       intent.setAction(Intent.ACTION_DIAL);       String data  = "tel:18710849943";       Uri dataUri = Uri.parse(data);       intent.setData(dataUri);       startActivity(intent);   }}

布局代码

<?xml version="1.0" encoding="utf-8"?><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"    >  <Button      android:layout_width="fill_parent"      android:layout_height="wrap_content"      android:id="@+id/btn"      android:text="btn"/>    <Button        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:id="@+id/btnEdit"        android:text="edit"/>    <Button        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:id="@+id/call"        android:text="call"/></LinearLayout>

Flag属性

这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述

0 0