从零开始,学习android开发

简单的说,一个Android的应用,比如一个Activity,主要包含4个文件,即3个xml,一个Java,三个xml分别是main.xml(主界面文件),strings.xml(值文件)和一个AndroidManifest.xml(功能清单文件)。一个Java文件就是我们的主程序文件。
现在要编写的第一个android项目,是获取手机信息的一个Activity。
下面是4个文件的内容:
main.xml
<?xml version="1.0" encoding="utf-8"?>
<linearLayout xmlns:android="http://schemas.android.com/ask/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="@+id/text01"
android:layout_width="fill_parent"
andriod:layout_height="fill_parent"/>
</linearLayout>

stinrs.xml的内容
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, Code01_01!</string>
<string name="app_name">Code01_01</string>
</resources>

AndroidManifest.xml的内容
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Code01_01"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Code01_01"
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>
最后一个是Java主程序文件,是以你的Project的名字命名的Java程序文件。

package com.Code01_01(注,项目名必须是Code01_01)
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.telephonyManager;
import android.widget.TextView;
pubilc class Code01_01 extends Activity{
TextView textview01=null;

public void onCreate(Bundle saveInstanceState){
super.onCreate(saveInstanceState);
setContentView(R.Layout.main);
textview01=(TextView)this.findViewById(R.id.text01);
fetch_status();

Syste.out.pringln("----------------onCreate");
}
public void getPhoneNumber(){
TelephonyManager tm=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String imei=tm.getDeviceId();
String tel=tm.getLine1Number();
textview01.setText("手机串号"+imei+"\n"+"手机号"+tel+"\n");
}
public void fetch_status(){
TelephonyManager tm=(TelephonyManager) this
.getSystemService(Context.TELEPHONY_SERVICE);
String str="";
str+="移动设备身份码DeviceId(IMEI)="+tm.getDeviceID()+"\n";
str += "设备软件版本DeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion()+ "\n";
str += "手机号Line1Number = " + tm.getLine1Number() + "\n";
str += "国际长途区号NetworkCountryIso = " + tm.getNetworkCountryIso() + "\n";
str += "网络运营商NetworkOperator = " + tm.getNetworkOperator() + "\n";
str += "运营商名称NetworkOperatorName = " + tm.getNetworkOperatorName() + "\n";
str += "网络连接类型NetworkType = " + tm.getNetworkType() + "\n";
str += "手机类型PhoneType = " + tm.getPhoneType() + "\n";
str += "获取ISO国家码SimCountryIso = " + tm.getSimCountryIso() + "\n";
str += "运营商网络码SimOperator = " + tm.getSimOperator() + "\n";
str += "运营商名称SimOperatorName = " + tm.getSimOperatorName() + "\n";
str += "SIM卡的序列号SimSerialNumber = " + tm.getSimSerialNumber() + "\n";
str += "SIM卡状态SimState = " + tm.getSimState() + "\n";
str += "唯一的用户IDSubscriberId(IMSI) = " + tm.getSubscriberId() + "\n";
str += "获取语音邮件号码VoiceMailNumber = " + tm.getVoiceMailNumber() + "\n";
textView01.setText(str);
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值