Android--Intent常用(拨号,浏览器,联系人,Wi-Fi)
16lz
2021-01-23
package com.mrzhu.intenttest;import android.app.Activity;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.view.View;public class IntentTestActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } //拨号代码,需要在AndroidManifest.xml文件中加入 拨打电话权限 //<uses-permission android:name="android.permission.CALL_PHONE"/> public void callIntent(View v){ Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:12345678")); startActivity(callIntent); } //将电话号码传入拨号程序的代码 public void dialIntent(View v){ Intent dialIntent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:12345678")); startActivity(dialIntent); } //调用拨号程序的代码 public void touchDialerIntent(View v){ Intent touchDialerIntent = new Intent("com.android.phone.action.TOUCH_DIALER"); startActivity(touchDialerIntent); } //调用系统浏览器浏览网页的代码 public void webIntent(View v){ Intent webIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://nkiaguy.blogjava.net")); startActivity(webIntent); } //调用系统程序查看联系人的代码 public void contaclistIntent(View v){ Intent contacListIntent = new Intent("com.android.contacts.action.LIST_CONTACTS"); startActivity(contacListIntent); } //显示系统设置界面的代码 public void settingsIntent(View v){ Intent settingsIntent = new Intent("android.settings.SETTINGS"); startActivity(settingsIntent); } //显示Wi-Fi设置界面的代码 public void wifiSettingsIntent(View v){ Intent wifiSettingsIntent = new Intent("android.settings.WIFI_SETTINGS"); startActivity(wifiSettingsIntent); }}
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="callIntent" android:text="@string/btn_callIntent" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="dialIntent" android:text="@string/btn_dialIntent" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="touchDialerIntent" android:text="@string/btn_touchDialerIntent" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="webIntent" android:text="@string/btn_webIntent" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="contaclistIntent" android:text="@string/btn_contacListIntent" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="settingsIntent" android:text="@string/btn_settingsIntent" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="wifiSettingsIntent" android:text="@string/btn_wifiSettingsIntent" /></LinearLayout>
<?xml version="1.0" encoding="utf-8"?><resources> <string name="hello">Hello World, IntentTestActivity!</string> <string name="app_name">IntentTest</string> <string name="btn_callIntent">callIntent</string> <string name="btn_dialIntent">diaIntent</string> <string name="btn_touchDialerIntent">touchDialerIntent</string> <string name="btn_webIntent">webIntent</string> <string name="btn_contacListIntent">contacListIntent</string> <string name="btn_settingsIntent">settingsIntent</string> <string name="btn_wifiSettingsIntent">wifiSettingsIntent</string></resources>
更多相关文章
- Android Widget程序源码
- Android程序设置成横屏方法
- android4.2上获取应用程序大小的变更点
- Android 7.1 触摸事件代码跟踪
- Android 博客园客户端 (一) 基本界面
- Android 用户反馈界面的实现
- android 开发中将十六进制 颜色代码 转换为int类型数值 方法 :
- android双击返回键退出程序
- TextView --- 内容设置成上下滑动 和 代码设置字体颜色