突然看到之前的一篇笔记,就补充一下发上来。Intent是什么就先不说了。列表可以看一下目录。

所有用法均在小米max手机上亲测,android6.0。有些权限在6.0上要动态获取。

以后如果用到新功能了再补充,没用过的先不写了。

打电话

使用ACTION_CALL需要android.permission.CALL_PHONE权限

1
2
3
4
5
6
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

    1
    2
    3
    4
    5
    Intent intent= new Intent();
    intent.setData(Uri.parse("smsto:10086"));
    intent.setAction(Intent.ACTION_SENDTO);
    intent.putExtra("sms_body", "填信息内容");
    startActivity(intent);
  • 2

    1
    2
    3
    4
    5
    Intent intent= new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setType("vnd.android-dir/mms-sms");
    intent.putExtra("sms_body", "填信息内容");
    startActivity(intent);

发邮件

  • 弹出选择器

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    Intent intent=new Intent();
    intent.setAction(Intent.ACTION_SEND);
    //收件人
    String[] tos={"wangyisll@163.com"};
    //抄送人
    String[] ccs={"1212121@qq.com"};
    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, "选择客户端发送"));
  • 直接启动邮件客户端

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    Intent intent=new Intent();
    intent.setData(Uri.parse("mailto:"));
    intent.setAction(Intent.ACTION_SENDTO);
    //收件人
    String[] tos={"wangyisll@163.com"};
    //抄送人
    String[] ccs={"1212121@qq.com"};
    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);

启动相机

  • 单纯启动相机

    1
    2
    Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
    startActivity(intent);
  • 以录像模式启动相机

    1
    2
    Intent intent = new Intent(MediaStore.INTENT_ACTION_VIDEO_CAMERA);
    startActivity(intent);
  • 获取拍照返回的缩略图 需要android.permission.CAMERA权限

    1
    2
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(intent,0);

    然后在

    1
    2
    3
    4
    5
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Bitmap bitmap = data.getParcelableExtra("data");
    }

回到桌面,HOME

1
2
3
4
Intent intent = new Intent();
intent.setAction("android.intent.action.MAIN");
intent.addCategory("android.intent.category.HOME");
startActivity(intent);

从联系人选择电话号码

1
2
3
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(intent,0);

然后再

1
2
3
4
5
6
7
8
9
10
@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);
}

插入新的联系人,跳到新建联系人页面并自动填好信息。

1
2
3
4
5
6
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文件

1
2
3
4
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,并打开指定的聊天窗口

1
2
String url = "mqqwpa://im/chat?chat_type=wpa&uin=1492571688";
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));

打开手机上的地图软件,如百度地图。传入的坐标如果在范围内会直接点位到所传的坐标

1
2
3
Uri uri = Uri.parse("geo:40.2268400000,88.1141060000");
Intent intent = new Intent(Intent.ACTION_VIEW,uri);
startActivity(intent);

打开系统各各个设置页面

如WiFi

1
2
Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS);
startActivity(intent);

其他如

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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

用浏览器打开网页

1
2
3
Uri webpage = Uri.parse("http://www.baidu.com");
Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
startActivity(intent);

打开录音机

1
2
Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
startActivity(intent);