1. 程式人生 > 其它 >每日日報 20210121

每日日報 20210121

今天學習了activity 元件的相關知識的瞭解

//1.撥打電話
// 給移動客服10086撥打電話
Uri uri = Uri.parse("tel:10086");
Intent intent = new Intent(Intent.ACTION_DIAL, uri);
startActivity(intent);

//2.傳送簡訊
// 給10086傳送內容為“Hello”的簡訊
Uri uri = Uri.parse("smsto:10086");
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.putExtra("sms_body", "Hello");
startActivity(intent);

//3.傳送彩信(相當於傳送帶附件的簡訊)
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra("sms_body", "Hello");
Uri uri = Uri.parse("content://media/external/images/media/23");
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType("image/png");
startActivity(intent);

//4.開啟瀏覽器:
// 開啟Google主頁
Uri uri = Uri.parse("http://www.baidu.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

//5.傳送電子郵件:(閹割了Google服務的沒戲!!!!)
// 給[email protected]發郵件
Uri uri = Uri.parse("mailto:[email protected]");
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
startActivity(intent);
// 給[email protected]發郵件傳送內容為“Hello”的郵件
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, "[email protected]");
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intent.putExtra(Intent.EXTRA_TEXT, "Hello");
intent.setType("text/plain");
startActivity(intent);
// 給多人發郵件
Intent intent=new Intent(Intent.ACTION_SEND);
String[] tos = {"[email protected]", "[email protected]"}; // 收件人
String[] ccs = {"[email protected]", "[email protected]"}; // 抄送
String[] bccs = {"[email protected]", "[email protected]"}; // 密送
intent.putExtra(Intent.EXTRA_EMAIL, tos);
intent.putExtra(Intent.EXTRA_CC, ccs);
intent.putExtra(Intent.EXTRA_BCC, bccs);
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intent.putExtra(Intent.EXTRA_TEXT, "Hello");
intent.setType("message/rfc822");
startActivity(intent);

//6.顯示地圖:
// 開啟Google地圖中國北京位置(北緯39.9,東經116.3)
Uri uri = Uri.parse("geo:39.9,116.3");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

//7.路徑規劃
// 路徑規劃:從北京某地(北緯39.9,東經116.3)到上海某地(北緯31.2,東經121.4)
Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=39.9 116.3&daddr=31.2 121.4");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

//8.多媒體播放:
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("file:///sdcard/foo.mp3");
intent.setDataAndType(uri, "audio/mp3");
startActivity(intent);

//獲取SD卡下所有音訊檔案,然後播放第一首=-=
Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");
Intent intent = newIntent
(Intent.ACTION_VIEW, uri); startActivity(intent);//9.開啟攝像頭拍照:// 開啟拍照程式Intent intent =newIntent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent,0);// 取出照片資料Bundle extras = intent.getExtras();Bitmap bitmap =(Bitmap) extras.get("data");//另一種://呼叫系統相機應用程式,並存儲拍下來的照片Intent intent =newIntent(MediaStore
.ACTION_IMAGE_CAPTURE); time =Calendar.getInstance().getTimeInMillis(); intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(newFile(Environment.getExternalStorageDirectory().getAbsolutePath()+"/tucue", time +".jpg"))); startActivityForResult(intent, ACTIVITY_GET_CAMERA_IMAGE);//10.獲取並剪下圖片// 獲取並剪下圖片Intent
intent =newIntent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); intent.putExtra("crop","true");// 開啟剪下 intent.putExtra("aspectX",1);// 剪下的寬高比為1:2 intent.putExtra("aspectY",2); intent.putExtra("outputX",20);// 儲存圖片的寬和高 intent.putExtra("outputY",40); intent.putExtra("output",Uri.fromFile(newFile("/mnt/sdcard/temp")));// 儲存路徑 intent.putExtra("outputFormat","JPEG");// 返回格式 startActivityForResult(intent,0);// 剪下特定圖片Intent intent =newIntent("com.android.camera.action.CROP"); intent.setClassName("com.android.camera","com.android.camera.CropImage"); intent.setData(Uri.fromFile(newFile("/mnt/sdcard/temp"))); intent.putExtra("outputX",1);// 剪下的寬高比為1:2 intent.putExtra("outputY",2); intent.putExtra("aspectX",20);// 儲存圖片的寬和高 intent.putExtra("aspectY",40); intent.putExtra("scale",true); intent.putExtra("noFaceDetection",true); intent.putExtra("output",Uri.parse("file:///mnt/sdcard/temp")); startActivityForResult(intent,0);//11.開啟Google Market // 開啟Google Market直接進入該程式的詳細頁面Uri uri =Uri.parse("market://details?id="+"com.demo.app");Intent intent =newIntent(Intent.ACTION_VIEW, uri); startActivity(intent);//12.進入手機設定介面:// 進入無線網路設定介面(其它可以舉一反三) Intent intent =newIntent(android.provider.Settings.ACTION_WIRELESS_SETTINGS); startActivityForResult(intent,0);//13.安裝apk:Uri installUri =Uri.fromParts("package","xxx",null); returnIt =newIntent(Intent.ACTION_PACKAGE_ADDED, installUri);//14.解除安裝apk:Uri uri =Uri.fromParts("package", strPackageName,null);Intent it =newIntent(Intent.ACTION_DELETE, uri); startActivity(it);//15.傳送附件:Intent it =newIntent(Intent.ACTION_SEND); it.putExtra(Intent.EXTRA_SUBJECT,"The email subject text"); it.putExtra(Intent.EXTRA_STREAM,"file:///sdcard/eoe.mp3"); sendIntent.setType("audio/mp3"); startActivity(Intent.createChooser(it,"Choose Email Client"));//16.進入聯絡人頁面:Intent intent =newIntent(); intent.setAction(Intent.ACTION_VIEW); intent.setData(People.CONTENT_URI); startActivity(intent);//17.檢視指定聯絡人:Uri personUri =ContentUris.withAppendedId(People.CONTENT_URI, info.id);//info.id聯絡人IDIntent intent =newIntent(); intent.setAction(Intent.ACTION_VIEW); intent.setData(personUri); startActivity(intent);