//
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服务的没戏!!!!)// 给someone@domain
.com
发邮件Uri uri = Uri
.parse
(
"mailto:someone@domain.com"
)
;
Intent intent = new Intent(Intent
.ACTION
_SENDTO, uri)
;
startActivity(intent)
;
// 给someone@domain
.com
发邮件发送内容为“Hello”的邮件Intent intent = new Intent(Intent
.ACTION
_SEND)
;
intent
.putExtra
(Intent
.EXTRA
_EMAIL,
"someone@domain.com"
)
;
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 = {
"1@abc.com"
,
"2@abc.com"
}
; // 收件人
String[] ccs = {
"3@abc.com"
,
"4@abc.com"
}
; // 抄送
String[] bccs = {
"5@abc.com"
,
"6@abc.com"
}
; // 密送
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 = new Intent(Intent
.ACTION
_VIEW, uri)
;
startActivity(intent)
;
//
9.
打开摄像头拍照:// 打开拍照程序Intent intent = new Intent(MediaStore
.ACTION
_IMAGE_CAPTURE)
;
startActivityForResult(intent,
0
)
;
// 取出照片数据Bundle extras = intent
.getExtras
()
;
Bitmap bitmap = (Bitmap) extras
.get
(
"data"
)
;
//另一种://调用系统相机应用程序,并存储拍下来的照片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)
;
//
10.
获取并剪切图片// 获取并剪切图片Intent intent = new Intent(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
(new File(
"/mnt/sdcard/temp"
)))
; // 保存路径
intent
.putExtra
(
"outputFormat"
,
"JPEG"
)
;// 返回格式
startActivityForResult(intent,
0
)
;
// 剪切特定图片Intent intent = new Intent(
"com.android.camera.action.CROP"
)
;
intent
.setClassName
(
"com.android.camera"
,
"com.android.camera.CropImage"
)
;
intent
.setData
(Uri
.fromFile
(new File(
"/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 = new Intent(Intent
.ACTION
_VIEW, uri)
;
startActivity(intent)
;
//
12.
进入手机设置界面:// 进入无线网络设置界面(其它可以举一反三) Intent intent = new Intent(android
.provider
.Settings
.ACTION
_WIRELESS_SETTINGS)
;
startActivityForResult(intent,
0
)
;
//
13.
安装apk:Uri installUri = Uri
.fromParts
(
"package"
,
"xxx"
, null)
;
returnIt = new Intent(Intent
.ACTION
_PACKAGE_ADDED, installUri)
;
//
14.
卸载apk:Uri uri = Uri
.fromParts
(
"package"
, strPackageName, null)
;
Intent it = new Intent(Intent
.ACTION
_DELETE, uri)
;
startActivity(it)
;
//
15.
发送附件:Intent it = new Intent(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 = new Intent()
;
intent
.setAction
(Intent
.ACTION
_VIEW)
;
intent
.setData
(People
.CONTENT
_URI)
;
startActivity(intent)
;
//
17.
查看指定联系人: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)
;
系统给我们提供的常见的Activity
最新推荐文章于 2019-07-16 17:35:01 发布