Android作业之组建通讯与后台服务 1

实验内容

1. Intent组件的使用,界面设计如图1和图2所示,完成如下功能:

  1. 点击“拨打电话”按钮启动Android系统自带的拨号应用程序界面;
  2. 点击“发送信息”按钮启动Android系统自带的发短信应用程序界面;
  3. 点击“打开网页”按钮启动Android系统自带的浏览器应用程序界面;
  4. 点击“返回系统桌面”按钮返回Android系统桌面界面;
  5. 点击“查看通讯录第一条联系人” 按钮启动第一条联系人相关信息界面图2

MainActivity.java

package com.example.text1;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    Button btn1,btn2,btn3,btn4,btn5;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn1=(Button)findViewById(R.id.call);
        btn1.setOnClickListener(new mclick1());
        btn2=(Button)findViewById(R.id.message);
        btn2.setOnClickListener(new mclick2());
        btn3=(Button)findViewById(R.id.baidu);
        btn3.setOnClickListener(new mclick3());
        btn4=(Button)findViewById(R.id.info);
        btn4.setOnClickListener(new mclick4());
        btn5=(Button)findViewById(R.id.back);
        btn5.setOnClickListener(new mclick5());
    }
    class mclick1 implements View.OnClickListener{
        @Override
        public void onClick(View v) {
            Uri uri=Uri.parse("tel:10086");
            Intent it=new Intent(Intent.ACTION_DIAL,uri);
            startActivity(it);
        }
    }
    class mclick2 implements View.OnClickListener{
        @Override
        public void onClick(View v) {
            Uri uri=Uri.parse("smsto:10010");
            Intent it=new Intent(Intent.ACTION_SENDTO,uri);
            it.putExtra("sms_body","TheSMS text");
            startActivity(it);
        }
    }
    class mclick3 implements View.OnClickListener{
        @Override
        public void onClick(View v) {
            Uri uri=Uri.parse("http://www.baidu.com");
            Intent it=new Intent();
            it.setAction(Intent.ACTION_VIEW);
            it.setData(uri);
            startActivity(it);
        }
    }
    class mclick4 implements View.OnClickListener{
        @Override
        public void onClick(View v) {
//            Uri uri=Uri.parse("content://contacts/people/1");
            Intent it=new Intent();
            it.setAction(Intent.ACTION_VIEW);
            it.setData(Uri.parse("content://contacts/people/1"));
            startActivity(it);
        }
    }
    class mclick5 implements View.OnClickListener{
        @Override
        public void onClick(View v) {
            Intent it=new Intent();
            it.setAction(Intent.ACTION_MAIN);
            it.addCategory(Intent.CATEGORY_HOME);
            startActivity(it);
        }
    }
}

activity.main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical">

    <Button
        android:id="@+id/call"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/call"
        />
    <Button
        android:id="@+id/message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/message"
        />
    <Button
        android:id="@+id/baidu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/baidu"
        />
    <Button
        android:id="@+id/back"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/back"
        />
    <Button
        android:id="@+id/info"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/info"
        />

</LinearLayout>

strings.xml

<resources>
    <string name="app_name">text1</string>
    <string name="call">拨打电话</string>
    <string name="message">发送消息</string>
    <string name="baidu">打开网页</string>
    <string name="back">返回系统桌面</string>
    <string name="info">查看通讯录第一条联系人</string>
</resources>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值