原文地址 http://blog.csdn.net/qq_25806863/article/details/70145785
突然看到之前的一篇筆記,就補充一下發上來。Intent是什麼就先不說了。列表可以看一下目錄。
所有用法均在小米max手機上親測,android6.0。有些權限在6.0上要動態獲取。
以後如果用到新功能了再補充,沒用過的先不寫了。
打電話
使用ACTION_CALL需要android.permission.CALL_PHONE
權限
Intent intent=new Intent();
intent.setAction(Intent.ACTION_VIEW);
//intent.setAction(Intent.ACTION_CALL);
//intent.setAction(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:12212212212"));
startActivity(intent);
發短信
- 1
Intent intent= new Intent();
intent.setData(Uri.parse("smsto:10086"));
intent.setAction(Intent.ACTION_SENDTO);
intent.putExtra("sms_body", "填信息內容");
startActivity(intent);
- 2
Intent intent= new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setType("vnd.android-dir/mms-sms");
intent.putExtra("sms_body", "填信息內容");
startActivity(intent);
發郵件
- 彈出選擇器
Intent intent=new Intent();
intent.setAction(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, "郵件內容 2333");
intent.putExtra(Intent.EXTRA_SUBJECT, "郵件主題");
intent.setType("message/rfc822");
startActivity(Intent.createChooser(intent, "選擇客戶端發送"));
- 直接啓動郵件客戶端
Intent intent=new Intent();
intent.setData(Uri.parse("mailto:"));
intent.setAction(Intent.ACTION_SENDTO);
//收件人
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, "郵件內容 2333");
intent.putExtra(Intent.EXTRA_SUBJECT, "郵件主題");
//intent.setType("message/rfc822");
startActivity(intent);
啓動相機
- 單純啓動相機
Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
startActivity(intent);
- 以錄像模式啓動相機
Intent intent = new Intent(MediaStore.INTENT_ACTION_VIDEO_CAMERA);
startActivity(intent);
- 獲取拍照返回的縮略圖 需要
android.permission.CAMERA
權限
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent,0);
然後在
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Bitmap bitmap = data.getParcelableExtra("data");
}
回到桌面,HOME
Intent intent = new Intent();
intent.setAction("android.intent.action.MAIN");
intent.addCategory("android.intent.category.HOME");
startActivity(intent);
從聯繫人選擇電話號碼
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(intent,0);
然後再
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Uri uri = data.getData();
String[] names = new String[]{ContactsContract.CommonDataKinds.Phone.NUMBER};
Cursor cursor = getContentResolver().query(uri, names,null, null, null);
int index = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
String number = cursor.getString(index);
Log.i(TAG, "onActivityResult: "+number);
}
插入新的聯繫人,跳到新建聯繫人頁面並自動填好信息。
Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
intent.putExtra(ContactsContract.Intents.Insert.NAME, "aaa");
intent.putExtra(ContactsContract.Intents.Insert.EMAIL, "wandjnfdjkn");
intent.putExtra(ContactsContract.Intents.Insert.PHONE, "100200100");
startActivity(intent);
安裝apk文件
String fileName = Environment.getExternalStorageDirectory() + "/a.apk" ;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive");
startActivity(intent);
啓動QQ,並打開指定的聊天窗口
String url = "mqqwpa://im/chat?chat_type=wpa&uin=1492571688";
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
打開手機上的地圖軟件,如百度地圖。傳入的座標如果在範圍內會直接點位到所傳的座標
Uri uri = Uri.parse("geo:40.2268400000,88.1141060000");
Intent intent = new Intent(Intent.ACTION_VIEW,uri);
startActivity(intent);
打開系統各各個設置頁面
如WiFi
Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS);
startActivity(intent);
其他如
ACTION_SETTINGS
ACTION_WIRELESS_SETTINGS
ACTION_AIRPLANE_MODE_SETTINGS
ACTION_WIFI_SETTINGS
ACTION_APN_SETTINGS
ACTION_BLUETOOTH_SETTINGS
ACTION_DATE_SETTINGS
ACTION_LOCALE_SETTINGS
ACTION_INPUT_METHOD_SETTINGS
ACTION_DISPLAY_SETTINGS
ACTION_SECURITY_SETTINGS
ACTION_LOCATION_SOURCE_SETTINGS
ACTION_INTERNAL_STORAGE_SETTINGS
ACTION_MEMORY_CARD_SETTINGS
用瀏覽器打開網頁
Uri webpage = Uri.parse("http://www.baidu.com");
Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
startActivity(intent);
打開錄音機
Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
startActivity(intent);