黑马程序员_android笔记1

---------------------- android培训java培训、期待与您交流! ----------------------



         第一天

1、安装:

所需开发环境:

JDK 5 或 JDK 6 (仅有JRE不够Eclipse 3.5 (galileo)

下载用于在Eclipse 开发android应用的ADT 插件 

下载地址:http://dl.google.com/android/ADT-0.9.7.zip

安装 Eclipse 插件 (ADT)

启动 Eclipse,选择 Help > Install New Software,在出现的对话框里,点击Add按钮,在对话框的name一栏输入“ADT”, 然后点击Archive...,浏览和选择已经下载的ADT插件压缩文件。 

点击 OK.。返回可用软件的视图,你会看到这个插件,然后选择Developer Tools (会选中下面的“Android Developer Tools”和 “Android Editors),点击 Next,最后重启 Eclipse

下载安装Android SDK

Android SDK包含了开发Android应用所依赖的jar文件、运行环境及相关工具。  

下载地址: http://dl.google.com/android/android-sdk_r06-windows.zip

下载完SDK后,把.zip文件解压到你电脑上合适位置。启动 Eclipse,选择window->preferences,在打开的视图左边点击android,在右边的SDK Location中选择Android SDK所在位置。

然后建立模拟器:window中得Android sdk and AVD Manager中新建

2、卸掉:

删除Eclipse 安装目录下features文件夹下的

com.android.ide.eclipse.adt_0.9.5.v200911191123-20404.jar

com.android.ide.eclipse.ddms_0.9.5.v200911191123-20404.jar

还有plugins文件夹下的

com.android.ide.eclipse.adt_0.9.5.v200911191123-20404.jarcom.android.ide.eclipse.ddms_0.9.5.v200911191123-20404.jar

然后重启Eclipse

3、打开Android模拟器时,出现无信号,拔打电话或发短信时,提示“尚未注册网络”错误信息的解决方案如下。

  场景一:你的电脑没有连接上互联网,同时也没有在局域网。

  解决办法:右键点击网上邻居,选择"属性",在网络连接窗口中右键点击"本地连接",选择"属性",设置TCP/IP属性如下:

     IP地址:192.168.1.100

     子网掩码:255.255.255.0

     默认网关:192.168.1.100

     首选DNS服务器:192.168.1.100

  场景二:你的电脑没有连接上互联网,但在局域网。

  解决办法:右键点击网上邻居,选择"属性",在网络连接窗口中右键点击"本地连接",选择"属性",设置TCP/IP属性如下:

     IP地址:设置成你所在局域网的IP,如:192.168.1.100 

     子网掩码:设置成你所在局域网的掩码,如:255.255.255.0

     默认网关:设置成你所在局域网的网关,一般网关的IP格式为:*.*.*.1,如:192.168.1.1

     首选DNS服务器:设置成你所在局域网的路由器IP,一般路由器的IP格式为:*.*.*.1,如:192.168.1.1

  最后一种解决方案是:让你的电脑连接上互联网。

                                     第一个android应用hello

Hello.java应用资源清单解释:

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

     

 package="liuxu.myfirstandroid"

    

  android:versionCode="1"

 

     android:versionName="1.0">

 

   <application android:icon="@drawable/icon" 

android:label="@string/app_name">

      

  <activity android:name=".Hello"

        

          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>

    <uses-sdk android:minSdkVersion="8" />

</manifest>

当用户单击应用图标时,系统会将点击封装成一个IntendIntend包含动作名称和类别,将此意图发给意图处理器,然后意图处理器 会按照Intend寻找相应的组件显示。

意图会找到Hello.java类,对这个类进行实例化。

实例化完成后调用onCreate方法,这个方法只会执行一次。然后执行setContentView方法用于显示一个界面。

package liuxu.myfirstandroid;

import android.app.Activity;

import android.os.Bundle;

public class Hello extends Activity {

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

    }

}

main.xml布局文件:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation="vertical"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    >

<TextView  

    android:layout_width="fill_parent" 

    android:layout_height="wrap_content" 

    android:text="@string/hello"

    />

</LinearLayout>

                           电话拨号器

效果图:    

             

界面显示文字引用设置:

NewFile.xml(位于values目录,相当于strings.xml的作用)

<?xml version="1.0" encoding="UTF-8"?>

<resources>

    <string name="input">请输入电话号码:</string>

    <string name="dialog">拨打</string>

</resources>

Activity布局设置:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation="vertical"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    >

<TextView  

    android:layout_width="fill_parent" 

    android:layout_height="wrap_content" 

    android:text="@string/input"

    />

 <EditText   

    android:layout_width="fill_parent" 

    android:layout_height="100px" 

    android:id="@+id/content"

   />

 <Button    

    android:layout_width="wrap_content" 

    android:layout_height="wrap_content" 

    android:text="@string/dialog"

    android:id="@+id/button"

    />

</LinearLayout>

电话拨号组件清单描述(这个组件有很多activity,每个activity又有几个意图过滤器,这里只列出拨打电话的activity的意图过滤器)

 …………

<activity android:name="OutgoingCallBroadcaster"

                android:permission="android.permission.CALL_PHONE"

                android:theme="@android:style/Theme.NoDisplay"

                android:configChanges="orientation|keyboardHidden">

            <!-- CALL action intent filters, for the various ways

                 of initiating an outgoing call. -->

            <intent-filter>  <!--拨打电话是需要匹配的意图过滤器-->

                <action android:name="android.intent.action.CALL" />

                <category android:name="android.intent.category.DEFAULT" />

                <data android:scheme="tel" />

            </intent-filter>

…………

</activity>

…………

PhoneActivity.class:

public class PhoneActivity extends Activity {

EditText phoneText;

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        phoneText=(EditText) findViewById (R.id.phone);

        Button button=(Button)findViewById(R.id.button);

        button.setOnClickListener(new ButtonListener());

    }

    private class ButtonListener implements OnClickListener{

          @Override

        public void onClick(View v) {

        

         String phoneNo = phoneText.getText().toString();

         Intent intent=new Intent("android.intent.action.CALL" ,Uri.parse("tel:"+phoneText.getText()));

         startActivity(intent);

        }

    }    

}

从上可知打电话权限的使用:在Manifest文件中申明权限:

<uses-permission android:name="android.permission.CALL_PHONE" />

在程序中:Button but=(Button) findViewById(R.id.button);

          but.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {

    EditText et=(EditText) findViewById(R.id.phoneText);

 Intent intent=new Intent(Intent.ACTION_CALL,Uri.parse("tel:"

                     +et.getText().toString()));

    Phone.this.startActivity(intent);

}

});


短信发送器

java代码事件处理:

button.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {

     EditText phoneNoText=(EditText) findViewById(R.id.phoneNoText);

     EditText contentText=(EditText) findViewById(R.id.contentText);

     String phoneNo=phoneNoText.getText().toString();

     String content=contentText.getText().toString();

     SmsManager manager1=SmsManager.getDefault();

     List<String> cons=manager1.divideMessage(content);

 for(String con:cons){

manager1.sendTextMessage(phoneNo, null , con, nullnull); 

 }

}

});

功能清单文件权限声明:

<uses-permission android:name="android.permission.SEND_SMS" />




---------------------- android培训java培训、期待与您交流! ----------------------

详细请查看:http://edu.csdn.net/heima

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值