《移动应用开发》试题及答案_第1页
《移动应用开发》试题及答案_第2页
《移动应用开发》试题及答案_第3页
《移动应用开发》试题及答案_第4页
《移动应用开发》试题及答案_第5页
已阅读5页,还剩16页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、【精品文档】如有侵权,请联系网站删除,仅供学习与交流移动应用开发试题及答案.精品文档.移动应用开发试题题目:1.请实现点击按钮拨打电话功能。(20分)2.请实现点击按钮改变文本控件颜色的功能。(30分)3.请实现使用socket通信的服务器端代码。(50分)要求:逻辑结构完整,答案要点突出,论述充分,每题答案字数不少于400字。答案不得完全照抄书本或其他资料,不得互相抄袭。中南大学网络教育课程考试移动应用开发答卷本人承诺:本试卷确为本人独立完成,若有违反愿意接受处理。签名:_学号:_专业:_学习中心:_题号一二三总分评阅人签字成绩1. 答: private Button btn2;btn2=(

2、Button)findViewById(R.id.btn2);/在xml中把button2改成btn2,为该按钮的idbtn2.setOnClickListener(new OnClickListener();在OnClick() Intent in2 = new Intent(); in2.setAction(Intent.ACTION_CALL);/指定意图动作 in2.setData(Uri.parse("tel:1836380000");/指定电话号码 startActivity(in2);在android系统中,所有系统请求,必须要在androidmainfest

3、.xml中注册 在<application上面<uses-permission android:name="android.permission.CALL_PHONE"/>MainActivity.java:package com.example.qq;import .Uri;import android.os.Bundle;import android.app.Activity;import android.app.AlertDialog;import android.app.Dialog;import android.content.DialogInt

4、erface;import android.content.Intent;import android.view.LayoutInflater;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;public class MainActivity extends Activity private Button btn;private Button

5、btn2; private EditText et; private EditText et2; Override protected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); et = (EditText)findViewById(R.id.editText1); et2 = (EditText)findViewById(R.id.editText2); btn2 = (Button)findViewB

6、yId(R.id.btn2); btn = (Button)findViewById(R.id.button1); btn.setOnClickListener(new OnClickListener()Overridepublic void onClick(View arg0) / TODO Auto-generated method stub final String str = et.getText().toString().trim(); final String str2 = et2.getText().toString().trim();if (str.equals(str2)In

7、tent in = new Intent(MainActivity.this,SecActivity.class);startActivity(in);elseSystem.out.println("!"); btn2.setOnClickListener(new OnClickListener()Overridepublic void onClick(View arg0) / TODO Auto-generated method stubIntent in2 = new Intent();in2.setAction(Intent.ACTION_CALL);in2.setD

8、ata(Uri.parse("telquot;);startActivity(in2);Override public boolean onCreateOptionsMenu(Menu menu) / Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true;androidmainfest.xml:<?xml version="1.0"

9、encoding="utf-8"?><manifest xmlns:android=" package="com.example.qq" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="17" android:targetSdkVersion="17" /> <uses-permission android:n

10、ame="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.example.qq.MainActivity&qu

11、ot; android:label="string/app_name" > <intent-filter> <action android:name="ent.action.MAIN" /> <category android:name="ent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="com.exam

12、ple.qq.SecActivity" android:label="string/title_activity_sec" > </activity> </application></manifest>1. Android Layout文件Layout文件,用来呈现一个拨打电话的按钮。1. <?xml version="1.0" encoding="utf-8"?>2. <LinearLayout xmlns:android="3.   

13、;  android:layout_width="fill_parent"4.     android:layout_height="fill_parent"5.     android:orientation="vertical" >6.    <Button7.         android:id="

14、+id/buttonCall"8.         android:layout_width="wrap_content"9.         android:layout_height="wrap_content"10.         android:text="call/p>

15、" />11. </LinearLayout>Activity使用以下代码,Android拨打电话:1. Intent callIntent = new Intent(Intent.ACTION_CALL);2.                 callIntent.setData(Uri.parse("telquot;);3.    

16、0;            startActivity(callIntent);文件:MainActivity.java 当点击拨打电话按钮时,就会拨个号码。1. package net.cublog.android;2. import android.app.Activity;3. import android.content.Context;4. import android.content.Intent;5. import .Uri;6. im

17、port android.os.Bundle;7. import android.telephony.PhoneStateListener;8. import android.telephony.TelephonyManager;9. import android.util.Log;10. import android.view.View;11. import android.view.View.OnClickListener;12. import android.widget.Button;13. public class MainActivity extends Activity 14.

18、    private Button button;15.     Override16.     public void onCreate(Bundle savedInstanceState) 17.         super.onCreate(savedInstanceState);18.         set

19、ContentView(R.layout.main);19.         button = (Button) findViewById(R.id.buttonCall);20.         / add button listener21.         button.setOnClickListener(new OnClickListener()

20、22.             Override23.             public void onClick(View arg0) 24.                 Intent ca

21、llIntent = new Intent(Intent.ACTION_CALL);25.                 callIntent.setData(Uri.parse("telquot;);26.                 

22、startActivity(callIntent);Android Manifest拨打电话,Android需要CALL_PHONE的权限。在AndroidManifest.xml中添加以下代码:1. <uses-permission android:name="android.permission.CALL_PHONE" />添加后:1. <?xml version="1.0" encoding="utf-8"?>2. <manifest xmlns:android="3.  

23、60;  package="net.cublog.android"4.     android:versionCode="1"5.     android:versionName="1.0" >6.     <uses-sdk android:minSdkVersion="7" />7.     <uses-per

24、mission android:name="android.permission.CALL_PHONE" />8.     <application9.         android:icon="drawable/ic_launcher"10.         android:label="string/app_name"

25、>11.         <activity12.             android:name=".MainActivity"13.             android:label="string/app_name"

26、>14.             <intent-filter>15.                 <action android:name="ent.action.MAIN" />16.     

27、60;           <category android:name="ent.category.LAUNCHER" />17.             </intent-filter>18.         </

28、activity>19.     </application>20. </manifest>PhoneStateListener 例子更新上面的Activity,模拟拨打电话的状态,当电话拨打结束后,返回原始Activity,实际上只是重启了这个activity。1. package net.cublog.android;2. import android.app.Activity;3. import android.content.Context;4. import android.content.Intent;5. im

29、port .Uri;6. import android.os.Bundle;7. import android.telephony.PhoneStateListener;8. import android.telephony.TelephonyManager;9. import android.util.Log;10. import android.view.View;11. import android.view.View.OnClickListener;12. import android.widget.Button;13. public class MainActivity extend

30、s Activity 14.     private Button button;15.     Override16.     public void onCreate(Bundle savedInstanceState) 17.         super.onCreate(savedInstanceState);18.       

31、  setContentView(R.layout.main);19.         button = (Button) findViewById(R.id.buttonCall);20.         / add PhoneStateListener21.         PhoneCallListener phoneListene

32、r = new PhoneCallListener();22.         TelephonyManager telephonyManager = (TelephonyManager) this23.             .getSystemService(Context.TELEPHONY_SERVICE);24.       

33、  telephonyManager.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);25.         / add button listener26.         button.setOnClickListener(new OnClickListener() 27.       

34、;      Override28.             public void onClick(View arg0) 29.                 Intent callIntent = new Intent(Intent.ACTION_CAL

35、L);30.                 callIntent.setData(Uri.parse("telquot;);31.                 startActivity(callIntent);32.  

36、60;  /monitor phone call activities33.     private class PhoneCallListener extends PhoneStateListener 34.         private boolean isPhoneCalling = false;35.         String LOG_TAG = "LO

37、GGING 123"36.         Override37.         public void onCallStateChanged(int state, String incomingNumber) 38.             if (TelephonyManager.CALL_STATE_

38、RINGING = state) 39.                 / phone ringing40.                 Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);41. &

39、#160;           if (TelephonyManager.CALL_STATE_OFFHOOK = state) 42.                 / active43.            &#

40、160;    Log.i(LOG_TAG, "OFFHOOK");44.                 isPhoneCalling = true;45.             if (TelephonyManager.CALL_STATE_IDLE =

41、 state) 46.                 / run when class initial and phone call ended, 47.                 / need detect flag from CALL_STATE_OFFHOOK48.

42、                 Log.i(LOG_TAG, "IDLE");49.                 if (isPhoneCalling) 50.        

43、0;            Log.i(LOG_TAG, "restart app");51.                     / restart app52.        

44、60;            Intent i = getBaseContext().getPackageManager()53.                         .getLaunchIntentForPackage(54.

45、                             getBaseContext().getPackageName();55.                

46、60;    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);56.                     startActivity(i);57.               &

47、#160;     isPhoneCalling = false;由于PhoneStateListener需要READ_PHONE_STATE权限,需要在AndroidManifest.xml中添加以下代码:1. <uses-permission android:name="android.permission.READ_PHONE_STATE" />添加后AndroidManifest.xml如下:1. <?xml version="1.0" encoding="utf-8&

48、quot;?>2. <manifest xmlns:android="3.     package="net.cublog.android"4.     android:versionCode="1"5.     android:versionName="1.0" >6.     <uses-sdk android:minSdkVersion=

49、"7" />7.     <uses-permission android:name="android.permission.CALL_PHONE" />8.     <uses-permission android:name="android.permission.READ_PHONE_STATE" />9.     <application10.   

50、60;     android:icon="drawable/ic_launcher"11.         android:label="string/app_name" >12.         <activity13.          &#

51、160;  android:name=".MainActivity"14.             android:label="string/app_name" >15.             <intent-filter>16.     

52、;            <action android:name="ent.action.MAIN" />17.                 <category android:name="ent.category.LAU

53、NCHER" />18.             </intent-filter>19.         </activity>20.     </application>21. </manifest>1. 答:MainActivity.javaimport android.app.Activi

54、ty;import android.content.Intent;import .Uri;import android.os.Bundle;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.TextView;public class MainActivity extends Activity private Button mCallButton;Overridep

55、rotected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mCallButton = (Button) findViewById(R.id.btn_call);mCallButton.setOnClickListener(new OnClickListener() Overridepublic void onClick(View v) / TODO Auto-generated method stub/打给

56、联通客服10010Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:10010");startActivity(intent);/Override/public boolean onCreateOptionsMenu(Menu menu) / Inflate the menu; this adds items to the action bar if it is present./getMenuInflater().inflate(R.menu.main, menu);/return true;/pub

57、lic void clickHandler(View source)/TextView tv = (TextView) findViewById(R.id.show);/tv.setText("你好!现在时间:" + new java.util.Date();activity_main.xml: <RelativeLayout xmlns:android=" xmlns:tools=" android:layout_width="match_parent" android:layout_height="match_pa

58、rent" 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=".MainActivi

59、ty" > <TextView android:id="+id/show" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:text="string/hello_world" /> <

60、;Button android:id="+id/btn_click" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="id/show" android:text="点击我" android:onClick="clickHandler"/> <Button android:id="+id/btn_call"

61、 android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="id/btn_click" android:text="拨打电话"/></RelativeLayout>AndroidManifest.xml: <?xml version="1.0" encoding="utf-8"?><manifest xmlns

62、:android=" package="com.xiami.caipiao" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" /><uses-permission android:name="android.permission.CALL_PHONE"/&g

63、t; <application android:allowBackup="true" android:icon="drawable/ic_launcher" android:label="string/app_name" android:theme="style/AppTheme" > <activity android:name="com.xiami.caipiao.MainActivity" android:label="string/app_name"

64、 > <intent-filter> <action android:name="ent.action.MAIN" /> <category android:name="ent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>2.答:打开表单模板:%FR_HOME%WebReportWEB-INFreportletsde

65、moanalyticsmulti_reportall.frm。选中总体概况按钮,在右侧的属性表中添加点击事件。具体的js代码如下:if(window.oldtd != null) window.oldtd.removeAttr("style"); var td; if($(e.target).is("button") td=$(e.target).parent().parent(); else td=$(e.target).find("button").parent().parent(); td.css("backgroun

66、d-image":"url()","background-color":"rgb(170, 223, 248)"); window.oldtd=td; 3. 答:服务器端  author  version1.002008/8/2  .ServerSocket;  .Socket;  importjava.io.IOException;  importjava.io.BufferedReader;  importjava.io.InputStreamRead

67、er;  importjava.io.PrintWriter;  publicclassServerSocketTest  privateServerSocketss;  privateSocketsocket;  privateBufferedReaderin;  privatePrintWriterout;  publicServerSocketTest()  try  ss=newServerSocket(10000);/建立服务器,监听.  System.out.println(&quo

68、t;Serverislisteningat10000.");  while(true)  socket=ss.accept();  /获取客户端IP地址  StringremoteIP=socket.getInetAddress().getHostAddress();  /获取客户端连接端口  StringremotePort=":"+socket.getLocalPort();  System.out.println("Aclinetcomein!IP:"+remoteIP

69、+remotePort);  /读取客户端输入  in=newBufferedReader(newInputStreamReader(socket.getInputStream();  Stringline=in.readLine();  System.out.println("Clientsendis:"+line);  /将服务器端信息发往客户端  out=newPrintWriter(socket.getOutputStream(),true);  out.println("YourMes

70、sageReceived!");  out.close();  in.close();  socket.close();  catch(IOExceptionex)  System.out.println(ex.getCause();  publicstaticvoidmain(Stringargs)  newServerSocketTest();  3.答:开发环境为eclipse,首先,新建两个普通的Java工程,一个命名为server_1,作为服务端;另一个命名为client_1,作为客户端。完成的

71、功能就是在客户端的控制台输入内容后,客户端将内容发送至服务端,在服务端的控制台可以看到输入的内容,当输入的内容为shutdown时,服务端和客户端都关闭通信,通信结束。服务端代码:package server_1;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.io.PrintWriter;import .ServerSocket;import .Socket;public class server_1 public static void

72、 main(String args) throws IOException /将异常全部抛出 ServerSocket server = new ServerSocket(10000); /用serversocket来启动服务器,并指定端口号 System.out.println("服务器启动。"); Socket socket = server.accept(); /获取客户端的socket信息 BufferedReader in = null; in = new BufferedReader(new InputStreamReader(socket.getInputStream(); /启动缓冲区 while (true) String msg = in.readLine(); / 将客户端发送来的信息存储在msg中 System.out.println(msg); if (msg.equals("shutdown") /客户端如果发

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论