您的位置:首页 > 移动开发 > Android开发

Android--Intent常用(拨号,浏览器,联系人,Wi-Fi)

2013-02-21 22:42 357 查看
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>


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐