標籤:
關於連絡人的一些URI:
管理連絡人的Uri:
ContactsContract.Contacts.CONTENT_URI
管理連絡人的電話的Uri:
ContactsContract.CommonDataKinds.Phone.CONTENT_URI
管理連絡人的Email的Uri:
ContactsContract.CommonDataKinds.Email.CONTENT_URI
(註:Contacts有兩個表,分別是rawContact和Data,
rawContact記錄了使用者的id和name,
其中id欄名稱為:ContactsContract.Contacts._ID, name名稱欄為ContactContract.Contacts.DISPLAY_NAME,
電話資訊表的外鍵id為ContactsContract.CommonDataKinds.Phone.CONTACT_ID,
電話號碼欄名稱為:ContactsContract.CommonDataKinds.Phone.NUMBER.
data表中Email地址欄名稱為:
ContactsContract.CommonDataKinds.Email.DATA
其外鍵欄為:ContactsContract.CommonDataKinds.Email.CONTACT_ID)
關於多媒體的一些URI:
儲存在sd卡上的音頻檔案:
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
儲存在手機內部儲存空間上的音頻檔案:
MediaStore.Audio.Media.INTERNAL_CONTENT_URI
SD卡上的圖片檔案內容:
MediaStore.Audio.Images.EXTERNAL_CONTENT_URI
手機內部儲存空間上的圖片:
MediaStore.Audio.Images.INTERNAL_CONTENT_URI
SD卡上的視頻:
MediaStore.Audio.Video.EXTERNAL_CONTENT_URI
手機內部儲存空間上的視頻:
MediaStore.Audio.Video.INTERNAL_CONTENT_URI
(註:圖片的顯示名欄:Media.DISPLAY_NAME,
圖片的詳細描述列為:Media.DESCRIPTION
圖片的儲存位置:Media.DATA
簡訊URI:
Content://sms
發送箱中的簡訊URI:
Content://sms/outbox
收信箱中的簡訊URI:
Content://sms/sent
草稿中的簡訊URI:
Content://sms/draft
常用代碼:
// 查詢通訊錄中連絡人?
Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
// 擷取手機號
Cursor phone = cursor.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +"="+ ContactId, null, null);
// 複雜點:
Cursor phone = cursor.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +"="+ ContactId +" AND "+ ContactsContract.CommonDataKinds.Phone.TYPE +"="+ ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE, null, null);
ContactsContract.CommonDataKinds.Phone.TYPE 表示連絡人電話的類型,
主要對應如下:
TYPE_MOBILE : 手機號碼
TYPE_HOME : 住家電話
TYPE_WORK : 公司電話
開啟一個網頁,類別是Intent.ACTION_VIEW
| |
Uri uri = Uri.parse("http://www.baidu.com/");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
開啟地圖並定位到一個點
| |
Uri uri = Uri.parse("geo:52.76,-79.0342");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
開啟撥號介面,類型是Intent.ACTION_DIAL
| |
Uri uri = Uri.parse("tel:10086");
Intent intent = new Intent(Intent.ACTION_DIAL, uri);
|
直接撥打到電話,與之不同的是,這個直接撥打到電話,而不是開啟撥號介面
|
Uri uri = Uri.parse("tel:10086");
Intent intent = new Intent(Intent.ACTION_CALL, uri);
|
卸載一個應用,Intent的類別是Intent.ACTION_DELETE
| |
Uri uri = Uri.fromParts("package", "xxx", null);
Intent intent = new Intent(Intent.ACTION_DELETE, uri);
|
安裝應用程式,Intent的類別是Intent.ACTION_PACKAGE_ADDED
|
Uri uri = Uri.fromParts("package", "xxx", null);
Intent intent = new Intent(Intent.ACTION_PACKAGE_ADDED, uri);
|
播放音頻檔案
| |
Uri uri = Uri.parse("file:///sdcard/download/everything.mp3");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setType("audio/mp3");
|
開啟發郵件介面
| |
Uri uri= Uri.parse("mailto:[email protected]Android-study.com");
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
|
發郵件,不同是將郵件發送出去
| |
Intent intent = new Intent(Intent.ACTION_SEND);
String[] tos = { "[email protected]" };
String[] ccs = { "[email protected]" };
intent.putExtra(Intent.EXTRA_EMAIL, tos);
intent.putExtra(Intent.EXTRA_CC, ccs);
intent.putExtra(Intent.EXTRA_TEXT, "I come from http://www.android-study.com");
intent.putExtra(Intent.EXTRA_SUBJECT, "http://www.android-study.com");intent.setType("message/rfc882");
Intent.createChooser(intent, "Choose Email Client");
|
//發送帶附件的郵件
| |
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
intent.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mysong.mp3");
intent.setType("audio/mp3");
startActivity(Intent.createChooser(intent, "Choose Email Client"));
|
發簡訊
| |
Uri uri= Uri.parse("tel:10086");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.putExtra("sms_body", "I come from http://www.android-study.com");
intent.setType("vnd.Android-dir/mms-sms");
|
直接發簡訊
| |
Uri uri= Uri.parse("smsto://100861");
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.putExtra("sms_body", "3g android http://www.android-study.com");
|
發多媒體訊息
| |
Uri uri= Uri.parse("content://media/external/images/media/23");
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra("sms_body", "3g android http://www.android-study.com");
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType("image/png");
|
# Market 相關
|
1 //尋找某個應用
Uri uri = Uri.parse("market://search?q=pname:pkg_name");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
//where pkg_name is the full package path for an application
2 //顯示某個應用的相關資訊
Uri uri = Uri.parse("market://details?id=app_id");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
//where app_id is the application ID, find the ID
//by clicking on your application on Market home
//page, and notice the ID from the address bar
|
路徑規劃
| |
Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
//where startLat, startLng, endLat, endLng are a long with 6 decimals like: 50.123456
|
安裝指定apk
| |
public void setupAPK(String apkname){
String fileName = Environment.getExternalStorageDirectory() + "/" + apkname;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(fileName)),"application/vnd.android.package-archive");
mService.startActivity(intent);
}
|
進入連絡人頁面
|
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(People.CONTENT_URI);
startActivity(intent);
|
查看指定連絡人
| |
Uri personUri = ContentUris.withAppendedId(People.CONTENT_URI, info.id);// info.id連絡人ID
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(personUri);
startActivity(intent);
|
調用相簿
| |
public static final String MIME_TYPE_IMAGE_JPEG = "image/*";
public static final int ACTIVITY_GET_IMAGE = 0;
Intent getImage = new Intent(Intent.ACTION_GET_CONTENT);
getImage.addCategory(Intent.CATEGORY_OPENABLE);
getImage.setType(MIME_TYPE_IMAGE_JPEG);
startActivityForResult(getImage, ACTIVITY_GET_IMAGE);
|
調用系統相機應用程式,並儲存拍下來的照片
| |
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
time = Calendar.getInstance().getTimeInMillis();
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment
.getExternalStorageDirectory().getAbsolutePath()+"/tucue", time + ".jpg")));
startActivityForResult(intent, ACTIVITY_GET_CAMERA_IMAGE);
|
<uses-permission android:name="android.permission.READ_CONTACTS"/>
android 常用URI