3.12

安卓调用url
• 所花时间:2
• 代码行数:214
• 博客容量:1
• 代码如下:

<?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=".actionUri"
    android:orientation="vertical">
    <Button
        android:id="@+id/bt_dial"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:height="80dp"
        android:text="拨号"/>
    <Button
        android:id="@+id/bt_sms"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:height="80dp"
        android:text="短信"/>
    <Button
        android:id="@+id/bt_calcu"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:height="80dp"
        android:text="计算器"/>


</LinearLayout>
package com.example.chapter05;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

public class actionUri extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_action_uri);
        findViewById(R.id.bt_dial).setOnClickListener(this);
        findViewById(R.id.bt_sms).setOnClickListener(this);
        findViewById(R.id.bt_calcu).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if(v.getId()==R.id.bt_dial){
            Intent intent=new Intent();
            intent.setAction(Intent.ACTION_DIAL);
            Uri uri=Uri.parse("tel:"+"1234544");
            intent.setData(uri);
            startActivity(intent);
        } else if (v.getId()==R.id.bt_sms) {
            Intent intent=new Intent();
            intent.setAction(Intent.ACTION_SENDTO);
            Uri uri=Uri.parse("smsto:"+"1234544");
            intent.setData(uri);
            startActivity(intent);
        } else if (v.getId()==R.id.bt_calcu) {
            Intent intent=new Intent();
            intent.setAction("android.intent.action.Ning");
            intent.addCategory(Intent.CATEGORY_DEFAULT);
            startActivity(intent);
        }
    }
}
posted @ 2024-03-12 20:10  aallofitisst  阅读(8)  评论(0)    收藏  举报