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属性
时间: 2024-10-08 11:19:43