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);
            
        }
        
    }
  • 相关阅读:
    强弱类型 静态语言 动态语言 || 脚本语言
    mysql版本升级问题处理
    word
    IntelliJ IDEA 插件
    dubbo
    spring源码构建
    zookeeper 本地多线程模拟分布式事务控制及配置中心
    一次性关闭所有的Activity
    可能以后用得到得东西
    Thread.sleep还是TimeUnit.SECONDS.sleep
  • 原文地址:https://www.cnblogs.com/maogefff/p/7784965.html
Copyright © 2011-2022 走看看