android studio 打电话 发短信 进网页 活动间传值

package com.dingcheng365.yzgk89.h01;

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;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity
{
    // 变量 *********************************************************************
    private TextView tvMsg = null;
    private Button btnOpenA01 = null;
    private Button btnCall = null;
    private EditText etTel = null;
    private Button btnSms = null;
    private EditText etSms = null;
    private Button btnUrl = null;
    private EditText etUrl = null;

    // 函数 *********************************************************************
    public void OpenA01_clik(View v){
        // 获取数据
        String strTel = "";
        String strSms = "";

        strTel = etTel.getText().toString();
        strSms = etSms.getText().toString();

        // 将数据赋值给intent
        Intent intent = new Intent(MainActivity.this,A01Activity.class);
        intent.putExtra("Tel",strTel);
        intent.putExtra("Sms",strSms);

        // 启动Activity
        startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 初始化对象
        tvMsg = (TextView) findViewById(R.id.tvMainMsg);
        btnOpenA01 = (Button)findViewById(R.id.btnMainOpenA01);
        btnCall = (Button)findViewById(R.id.btnMainCall);
        etTel = (EditText)findViewById(R.id.etMainTel);
        btnSms = (Button)findViewById(R.id.btnMainSms);
        etSms = (EditText)findViewById(R.id.etMainSms);
        btnUrl = (Button)findViewById(R.id.btnMainUrl);
        etUrl = (EditText)findViewById(R.id.etMainUrl);

        // 打电话按钮单击事件
        btnCall.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                // 获取电话号码
                String strTel = "";

                strTel = etTel.getText().toString();

                // 调用打电话的App
                Uri uri = Uri.parse("tel:"+strTel);
                Intent intent = new Intent(Intent.ACTION_DIAL, uri);
                startActivity(intent);

            }
        });

        // 发送短信按钮单击事件
        btnSms.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                // 获取电话号码
                String strTel = "";
                strTel = etTel.getText().toString();

                // 获取发送短信内容
                String strSms = "";
                strSms = etSms.getText().toString();

                // 启动Android手机发送短信App中的Activity
                Uri uri = Uri.parse("smsto:" + strTel);
                Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
                intent.putExtra("sms_body", strSms);
                startActivity(intent);
            }
        });

        // 打开网页按钮单击事件
        btnUrl.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                // 获取网址
                String strUrl = "";
                strUrl = etUrl.getText().toString();

                // 启动打开网页的App
                Uri uri = Uri.parse(strUrl);
                Intent intent  = new Intent(Intent.ACTION_VIEW, uri);
                startActivity(intent);
            }
        });


    }





}

接受值

 super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_a01);

        // 初始化对象
        btnBack = (Button)findViewById(R.id.btnA01Back);
        tvMsg = (TextView)findViewById(R.id.tvA01Msg);

        // 获取Intent
        Intent intent = null;
        intent = getIntent();

        // 获取具体的数据
        String strTel = "";
        String strSms = "";

        strTel = intent.getStringExtra("Tel");
        strSms = intent.getStringExtra("Sms");

        // 数据的回显
        tvMsg.setText("Tel:" + strTel + " Sms:" + strSms);

        // 定义back按钮的单击事件
        btnBack.setOnClickListener(new View.OnClickListener()
        {
            // 单击事件所对应的函数
            @Override
            public void onClick(View v)
            {
                finish();
            }
        });

 

上一篇:Android-6


下一篇:VS 2019开发APP(一)界面和代码