zoukankan      html  css  js  c++  java
  • 第一个应用:一键打电话

    AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"    //命名空间
        package="com.itheima.callhoney"
        android:versionCode="1"
        android:versionName="1.0" >
        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="17" />
        <uses-permission android:name="android.permission.CALL_PHONE"/>    //注意这里:添加了电话的权限
    
        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="com.itheima.callhoney.MainActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
    
    </manifest>

    res/layout/activity_main.xml

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".MainActivity" >
        
        <Button 
            android:onClick="callhoney"
            android:text="打电话"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            />
        
    </RelativeLayout>

    MainActivity.java

    package com.itheima.callhoney;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Bundle;
    import android.view.View;
    
    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
        }
    
        //这里的方法的 签名是 固定的 . 
        public void callhoney(View v){
            
            // 不同的组件之间 ,相互 调用的时候, 激活的时候, 一般采用的是 意图 --- intent
            // 意图 包含 你具体要  做 什么 
            // 动作:  做
            // 数据:  什么 
            // 例如:  泡 茶 , 泡网吧, 泡 妞, 泡 面
            
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_CALL);  //动作 , 打电话 
            intent.setData(Uri.parse("tel://5201314"));  // 数据, 给 谁打 电话
            
            //发送意图 出去, 告诉 系统我要打电话. 
            startActivity(intent);
            
        }
        
    }
  • 相关阅读:
    Leetcode 238. Product of Array Except Self
    Leetcode 103. Binary Tree Zigzag Level Order Traversal
    Leetcode 290. Word Pattern
    Leetcode 205. Isomorphic Strings
    Leetcode 107. Binary Tree Level Order Traversal II
    Leetcode 102. Binary Tree Level Order Traversal
    三目运算符
    简单判断案例— 分支结构的应用
    用switch判断月份的练习
    java基本打印练习《我行我素购物系统》
  • 原文地址:https://www.cnblogs.com/maogefff/p/7784965.html
Copyright © 2011-2022 走看看