使用Action,Data属性启动系统Activity
生活随笔
收集整理的這篇文章主要介紹了
使用Action,Data属性启动系统Activity
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
幾個Action屬性和Data屬性的特殊組合:
ACTION_VIEW content://com.android.contacts/contacts/1:顯示標識為1的聯系人的信息
ACTION_EDIT content://com.android.contacts/contacts/1:編輯標識為1的聯系人的信息
ACTION_DIAL content://com.android.contacts/contacts/1:顯示向標識為1的聯系人撥號的界面
ACTION_VIEW tel:123:顯示向指定號碼123撥號的界面
ACTION_DIAL tel:123:顯示向指定號碼123撥號的界面
ACTION_VIEW content://contacts/people/:顯示所有聯系人列表的信息,通過這種組合可以方便地查看系統聯系人
MainActivity.java
package com.hust.actiondataonsystemactivity;import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Button brower=(Button) findViewById(R.id.button1);Button edit=(Button) findViewById(R.id.button2);Button call=(Button) findViewById(R.id.button3);//瀏覽網頁brower.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View v) {// TODO Auto-generated method stubIntent intent =new Intent();intent.setAction(Intent.ACTION_VIEW);intent.setData(Uri.parse("http://www.baidu.com"));startActivity(intent);}});//編輯聯系人頁面edit.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View v) {// TODO Auto-generated method stubIntent intent =new Intent();intent.setAction(Intent.ACTION_EDIT);intent.setData(Uri.parse("content://com.android.contacts/contacts/2"));startActivity(intent);}});//撥號頁面call.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View v) {// TODO Auto-generated method stubIntent intent =new Intent();intent.setAction(Intent.ACTION_DIAL);intent.setData(Uri.parse("tel:02780108225"));startActivity(intent);}});}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}@Overridepublic boolean onOptionsItemSelected(MenuItem item) {// Handle action bar item clicks here. The action bar will// automatically handle clicks on the Home/Up button, so long// as you specify a parent activity in AndroidManifest.xml.int id = item.getItemId();if (id == R.id.action_settings) {return true;}return super.onOptionsItemSelected(item);} }
總結
以上是生活随笔為你收集整理的使用Action,Data属性启动系统Activity的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用指定的Action,Category
- 下一篇: Android数据存储的三种方式-Sha