Android开发环境搭建和SAP安装KEY计算程序

来源:互联网 发布:二选一数据选择器芯片 编辑:程序博客网 时间:2024/05/22 12:01

Android开发环境搭建和SAP安装KEY计算程序

成都﹒495435190

    很多项目都要求加入移动业务处理功能,所以上周三开始就准备在Android开发平台上试试手机上的软件开发。本文将介绍Android开发环境搭建的步骤和SAPSolution Key计算程序的手机版(我之前用DELPHI写有一个电脑版,这两个程序都可以在我的空间中下载)。

    一. Android开发环境搭建

         1. 下载JDK,我使用的版本是 jdk-6u21-windows-i586.exe。安装到 C:\jdk1.6.0_21 并设置环境变量:

              JAVA_HOME=C:\jdk1.6.0_21

              CLASSPATH=.;%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\bin;

         2. 下载Android的SDK,我下载的版本是 android-sdk_r12-windows.zip

         3. 下载Android的ADT,我下载的版本是 ADT-12.0.0.zip

         4. 下载eclipse,我下载的是3.50版的 Pulsar for Mobile Java Developers.zip

         5.  把SDK解压到D盘,并运行 D:\Android\android-sdk-windows\SDK Manager.exe下载开发需要的Android平台和第三方库。这个过程很长,我的平均下载500K,但仍然需要1个小时。android-sdk_r12-windows解压后只有54M,全部下载后共计2.84G。SDK下载好后,以后再次安装就是几分钟搞定的事情。设置环境变量:

              ANDROID=D:\Android\android-sdk-windows\tools;D:\Android\android-sdk-windows\platform-tools;

              PATH=%ANDROID%;%JAVA_HOME%\bin;   (在前面加入,原来的PATH变量要保留)

         6. 解压 Pulsar for Mobile Java Developers.zip 到 D:\Android\eclipse,运行D:\Android\eclipse\eclipse.exe,我把eclipse的workspace设置在D:\Android\workspace

         7. 用本地文件安装安装ADT:eclipse菜单 --> Help --> Install New Software

             

             创建手机模拟器:eclipse菜单 --> Window --> Android SDK and AVD Manager

            

             手机模拟的启动给的速度根据机器配置从几秒到几分钟不等,在我的虚拟机中需要1分钟左右

            

    二. SAP安装KEY计算程序

          1. 启动eclipse创建一个项目(如果Eclipse New菜单没有Android Project请按下面的方法操作一次即可)

              a) 打开Eclipse, New->Project->Android Project, 随便新建一个工程,然后关掉eclipse。

              b) 再次打开的Eclipse, New 菜单就有Android Project了。

          2. 总的说来Android的开发还算简洁,我这个程序只用到了简单的界面控件的值存取和按钮的相应事件处理,和borland公司的Delphi手法相同。

          3. 界面布局文件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="wrap_content"        android:layout_height="wrap_content"        android:textSize="18sp"        android:text="@string/usage"     />    <LinearLayout        android:orientation="horizontal"        android:layout_width="match_parent"        android:layout_height="wrap_content">        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"        android:textColor="#FFFFFF"            android:textSize="18sp"            android:text="@string/lbSID"         />        <EditText         android:id="@+id/edtSID"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:singleLine="true"            android:maxLength="3"            android:hint="DEV"        />    </LinearLayout>    <LinearLayout        android:orientation="horizontal"        android:layout_width="match_parent"        android:layout_height="wrap_content">        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:textSize="18sp"        android:textColor="#FFFFFF"            android:text="@string/lbNO"         />        <EditText         android:id="@+id/edtNO"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:maxLength="2"            android:inputType="numberDecimal"            android:singleLine="true"            android:hint="00"        />    </LinearLayout>    <LinearLayout        android:orientation="horizontal"        android:layout_width="match_parent"        android:layout_height="wrap_content">        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:textSize="18sp"        android:textColor="#FFFFFF"            android:text="@string/lbHostName"         />        <EditText         android:id="@+id/edtHostName"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:maxLength="25"            android:singleLine="true"            android:hint="hostname"        />    </LinearLayout>    <LinearLayout        android:orientation="horizontal"        android:layout_width="match_parent"        android:layout_height="wrap_content">    <Button    android:id="@+id/btnCal"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:textSize="16sp"        android:text="@string/btnOK"     />        <TextView    android:id="@+id/tvresult"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:textSize="18sp"        android:textColor="#FF0000"        android:text="@string/result"     />    </LinearLayout></LinearLayout>

          4. 字符串资源文件string.xml            

<?xml version="1.0" encoding="utf-8"?><resources>    <string name="app_name">SAP安装KEY</string>    <string name="usage">本程序用于获取SAP软件安装时要求输入的Solution Key。输入实例名、安装号和主机名后点击计算</string>    <string name="lbSID">实例名</string>    <string name="lbNO">安装号</string>    <string name="lbHostName">主机名</string>    <string name="btnOK">计算</string>    <string name="result"></string>    <string name="app_titile">SAP安装KEY计算程序</string></resources>

          5. JAVA主程序MainActivity.java              

package iivii.net;import android.app.Activity;import android.os.Bundle;import android.text.Html;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import android.widget.TextView;public class MainActivity extends Activity{/** Called when the activity is first created. */private Button btnCal = null;private EditText edtTmp = null;private TextView tvResult = null;private InstallationKey instKey = new InstallationKey();private String strSID = null;private String strNO = null;private String strHostName = null;@Overridepublic void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);// 点击按钮后计算安装KEYbtnCal = (Button) findViewById(R.id.btnCal);btnCal.setOnClickListener(ClickListener);}private OnClickListener ClickListener = new OnClickListener(){@Overridepublic void onClick(View v){// TODO Auto-generated method stubedtTmp = (EditText) findViewById(R.id.edtSID);strSID = edtTmp.getText().toString();edtTmp = (EditText) findViewById(R.id.edtNO);strNO = edtTmp.getText().toString();edtTmp = (EditText) findViewById(R.id.edtHostName);strHostName = edtTmp.getText().toString();instKey.setSID(strSID);instKey.setNO(strNO);instKey.setHostName(strHostName);tvResult = (TextView) findViewById(R.id.tvresult);if (strSID.trim().length() == 0){tvResult.setText("请输入实例名");return;}if (strSID.trim().length() < 3){tvResult.setText("实例名需输入3位字符");return;}if (strNO.trim().length() == 0){tvResult.setText("请输入安装号");return;}if (strNO.trim().length() <2 ){tvResult.setText("安装号需输入2位数字");return;}if (strHostName.trim().length() == 0){tvResult.setText("请输入主机名");return;}tvResult.setText(Html.fromHtml("<font color=white>"+instKey.CalInstallationKey()+"</font>"));}};}

          5. 程序运行效果(右边的适当做了美化)

               

原创粉丝点击