Android 调用打电话,发短信(彩信),发邮件,浏览器,分享,跳转系统的各个设置页面
系统应用调用
调用打电话,发短信功能可分为直接调用和间接调用,通过设置intent属性即可实现:
直接调用,不经过用户确认:
//电话 Intent intent = new Intent( Intent.ACTION_CALL, Uri.parse("tel:10086")); startActivity(intent);
//短信 String smsContent = "ye"; // note: SMS must be divided before being sent SmsManager sms = SmsManager.getDefault(); List<String> texts = sms.divideMessage(smsContent); for (String text : texts) { sms.sendTextMessage("10086", null, text, null, null); }
调用程序等待用户确认:
Intent intent = new Intent( Intent.ACTION_DIAL, Uri.parse("tel:10086")); startActivity(intent);
Uri uri = Uri.parse("smsto:10086"); Intent it = new Intent(Intent.ACTION_SENDTO, uri); it.putExtra("sms_body", "ye"); startActivity(it);
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission> <uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
//调web浏览器 Uri myBlogUri = Uri.parse("http://www.soqi.cc"); returnIt = new Intent(Intent.ACTION_VIEW, myBlogUri); //调用地图 Uri mapUri = Uri.parse("geo:38.899533,-77.036476"); returnIt = new Intent(Intent.ACTION_VIEW, mapUri); //调用发邮件 Uri emailUri = Uri.parse("mailto:xxxx@gmail.com"); returnIt = new Intent(Intent.ACTION_SENDTO, emailUri); //邮件详细 returnIt = new Intent(Intent.ACTION_SEND); String[] tos = { "xxxx@gmail.com" }; String[] ccs = { "xxxx@gmail.com" }; returnIt.putExtra(Intent.EXTRA_EMAIL, tos); returnIt.putExtra(Intent.EXTRA_CC, ccs); returnIt.putExtra(Intent.EXTRA_TEXT, "body"); returnIt.putExtra(Intent.EXTRA_SUBJECT, "subject"); returnIt.setType("message/rfc882"); Intent.createChooser(returnIt, "Choose Email Client"); //发彩信 Uri mmsUri = Uri.parse("content://media/external/images/media/23"); returnIt = new Intent(Intent.ACTION_SEND); returnIt.putExtra("sms_body", "yyyy"); returnIt.putExtra(Intent.EXTRA_STREAM, mmsUri); returnIt.setType("image/png");
分享功能调用
Intent intent=new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); //纯文本分享 /*图片分享 intent.setType("image/png"); //添加图片 File f = new File(Environment.getExternalStorageDirectory() +"/Pictures/haha.png"); Uri u = Uri.fromFile(f); intent.putExtra(Intent.EXTRA_STREAM, u); */ intent.putExtra(Intent.EXTRA_SUBJECT, "分享"); intent.putExtra(Intent.EXTRA_TEXT, "I would like to share ..."); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(Intent.createChooser(intent, getTitle()));
跳转系统设置各个页面
在android SDK文档中有这样一个类,android.provider.Settings类提供android系统各个页面的跳转常量:
使用实例例:startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS)),即可跳到android手机网络设置页面。
如果要launch Mobile Networks Setting页面按如下方法:
Intent intent=new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS);
ComponentName cName = new ComponentName(“com.android.phone”,”com.android.phone.Settings”);
intent.setComponent(cName);
startActivity(intent);
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName(“com.android.phone”, “com.android.phone.NetworkSetting”);
startActivity(intent);
具体列表如下:
String |
ACTION_ACCESSIBILITY_SETTINGS |
Activity Action: Show settings for accessibility modules. |
String |
ACTION_ADD_ACCOUNT |
Activity Action: Show add account screen for creating a new account. |
String |
ACTION_AIRPLANE_MODE_SETTINGS |
Activity Action: Show settings to allow entering/exiting airplane mode. |
String |
ACTION_APN_SETTINGS |
Activity Action: Show settings to allow configuration of APNs. |
String |
ACTION_APPLICATION_DETAILS_SETTINGS |
Activity Action: Show screen of details about a particular application. |
String |
ACTION_APPLICATION_DEVELOPMENT_SETTINGS |
Activity Action: Show settings to allow configuration of application development-related settings. |
String |
ACTION_APPLICATION_SETTINGS |
Activity Action: Show settings to allow configuration of application-related settings. |
String |
ACTION_BLUETOOTH_SETTINGS |
Activity Action: Show settings to allow configuration of Bluetooth. |
String |
ACTION_DATA_ROAMING_SETTINGS |
Activity Action: Show settings for selection of2G/3G. |
String |
ACTION_DATE_SETTINGS |
Activity Action: Show settings to allow configuration of date and time. |
String |
ACTION_DEVICE_INFO_SETTINGS |
Activity Action: Show general device information settings (serial number, software version, phone number, etc.). |
String |
ACTION_DISPLAY_SETTINGS |
Activity Action: Show settings to allow configuration of display. |
String |
ACTION_INPUT_METHOD_SETTINGS |
Activity Action: Show settings to configure input methods, in particular allowing the user to enable input methods. |
String |
ACTION_INPUT_METHOD_SUBTYPE_SETTINGS |
Activity Action: Show settings to enable/disable input method subtypes. |
String |
ACTION_INTERNAL_STORAGE_SETTINGS |
Activity Action: Show settings for internal storage. |
String |
ACTION_LOCALE_SETTINGS |
Activity Action: Show settings to allow configuration of locale. |
String |
ACTION_LOCATION_SOURCE_SETTINGS |
Activity Action: Show settings to allow configuration of current location sources. |
String |
ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS |
Activity Action: Show settings to manage all applications. |
String |
ACTION_MANAGE_APPLICATIONS_SETTINGS |
Activity Action: Show settings to manage installed applications. |
String |
ACTION_MEMORY_CARD_SETTINGS |
Activity Action: Show settings for memory card storage. |
String |
ACTION_NETWORK_OPERATOR_SETTINGS |
Activity Action: Show settings for selecting the network operator. |
String |
ACTION_PRIVACY_SETTINGS |
Activity Action: Show settings to allow configuration of privacy options. |
String |
ACTION_QUICK_LAUNCH_SETTINGS |
Activity Action: Show settings to allow configuration of quick launch shortcuts. |
String |
ACTION_SEARCH_SETTINGS |
Activity Action: Show settings for global search. |
String |
ACTION_SECURITY_SETTINGS |
Activity Action: Show settings to allow configuration of security and location privacy. |
String |
ACTION_SETTINGS |
Activity Action: Show system settings. |
String |
ACTION_SOUND_SETTINGS |
Activity Action: Show settings to allow configuration of sound and volume. |
String |
ACTION_SYNC_SETTINGS |
Activity Action: Show settings to allow configuration of sync settings. |
String |
ACTION_USER_DICTIONARY_SETTINGS |
Activity Action: Show settings to manage the user input dictionary. |
String |
ACTION_WIFI_IP_SETTINGS |
Activity Action: Show settings to allow configuration of a static IP address for Wi-Fi. |
String |
ACTION_WIFI_SETTINGS |
Activity Action: Show settings to allow configuration of Wi-Fi. |
String |
ACTION_WIRELESS_SETTINGS |
Activity Action: Show settings to allow configuration of wireless controls such as Wi-Fi, Bluetooth and Mobile networks. |
String |
AUTHORITY |
|
String |
EXTRA_AUTHORITIES |
Activity Extra: Limit available options in launched activity based on the given authority. |
String |
EXTRA_INPUT_METHOD_ID |
此外还有一种方式:
Intent intent = new Intent("/");
ComponentName cm = new ComponentName("com.android.settings","com.android.settings.WirelessSettings");
intent.setComponent(cm);
intent.setAction("android.intent.action.VIEW");
activity.startActivityForResult( intent , 0);
经过测试,使用下面字段可以在软件中直接打开相应的系统界面
com.android.settings.AccessibilitySettings 辅助功能设置
com.android.settings.ActivityPicker 选择活动
com.android.settings.ApnSettings APN设置
com.android.settings.ApplicationSettings 应用程序设置
com.android.settings.BandMode 设置GSM/UMTS波段
com.android.settings.BatteryInfo 电池信息
com.android.settings.DateTimeSettings 日期和坝上旅游网时间设置
com.android.settings.DateTimeSettingsSetupWizard 日期和时间设置
com.android.settings.DevelopmentSettings 应用程序设置=》开发设置
com.android.settings.DeviceAdminSettings 设备管理器
com.android.settings.DeviceInfoSettings 关于手机
com.android.settings.Display 显示——设置显示字体大小及预览
com.android.settings.DisplaySettings 显示设置
com.android.settings.DockSettings 底座设置
com.android.settings.IccLockSettings SIM卡锁定设置
com.android.settings.InstalledAppDetails 语言和键盘设置
com.android.settings.LanguageSettings 语言和键盘设置
com.android.settings.LocalePicker 选择手机语言
com.android.settings.LocalePickerInSetupWizard 选择手机语言
com.android.settings.ManageApplications 已下载(安装)软件列表
com.android.settings.MasterClear 恢复出厂设置
com.android.settings.MediaFormat 格式化手机闪存
com.android.settings.PhysicalKeyboardSettings 设置键盘
com.android.settings.PrivacySettings 隐私设置
com.android.settings.ProxySelector 代理设置
com.android.settings.RadioInfo 手机信息
com.android.settings.RunningServices 正在运行的程序(服务)
com.android.settings.SecuritySettings 位置和安全设置
com.android.settings.Settings 系统设置
com.android.settings.SettingsSafetyLegalActivity 安全信息
com.android.settings.SoundSettings 声音设置
com.android.settings.TestingSettings 测试——显示手机信息、电池信息、使用情况统计、Wifi information、服务信息
com.android.settings.TetherSettings 绑定与便携式热点
com.android.settings.TextToSpeechSettings 文字转语音设置
com.android.settings.UsageStats 使用情况统计
com.android.settings.UserDictionarySettings 用户词典
com.android.settings.VoiceInputOutputSettings 语音输入与输出设置
com.android.settings.WirelessSettings 无线和网络设置