《《移动应用开发》试题及答案.doc》由会员分享,可在线阅读,更多相关《《移动应用开发》试题及答案.doc(24页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、-作者xxxx-日期xxxx移动应用开发试题及答案【精品文档】移动应用开发试题题目:1.请实现点击按钮拨打电话功能。(20分)2.请实现点击按钮改变文本控件颜色的功能。(30分)3.请实现使用socket通信的服务器端代码。(50分)要求:逻辑结构完整,答案要点突出,论述充分,每题答案字数不少于400字。答案不得完全照抄书本或其他资料,不得互相抄袭。【精品文档】中南大学网络教育课程考试移动应用开发答卷本人承诺:本试卷确为本人独立完成,若有违反愿意接受处理。签名:_学号:_专业:_学习中心:_题号一二三总分评阅人签字成绩1.答: private Button btn2;btn2=(Button)
2、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); 在application上面MainActivity.java:package com.example.qq;i
3、mport .Uri;import android.os.Bundle;import android.app.Activity;import android.app.AlertDialog;import android.app.Dialog;import android.content.DialogInterface;import android.content.Intent;import android.view.LayoutInflater;import android.view.Menu;import android.view.View;import android.view.View.
4、OnClickListener;import android.widget.Button;import android.widget.EditText;public class MainActivity extends Activity private Button btn;private Button btn2; private EditText et; private EditText et2; Override protected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); se
5、tContentView(R.layout.activity_main); et = (EditText)findViewById(R.id.editText1); et2 = (EditText)findViewById(R.id.editText2); btn2 = (Button)findViewById(R.id.btn2); btn = (Button)findViewById(R.id.button1); btn.setOnClickListener(new OnClickListener()Overridepublic void onClick(View arg0) / TODO
6、 Auto-generated method stub final String str = et.getText().toString().trim(); final String str2 = et2.getText().toString().trim();if (str.equals(str2)Intent in = new Intent(MainActivity.this,SecActivity.class);startActivity(in);elseSystem.out.println(!);); btn2.setOnClickListener(new OnClickListene
7、r()Overridepublic void onClick(View arg0) / TODO Auto-generated method stubIntent in2 = new Intent();in2.setAction(Intent.ACTION_CALL);startActivity(in2);); Override public boolean onCreateOptionsMenu(Menu menu) / Inflate the menu; this adds items to the action bar if it is present. getMenuInflater(
8、).inflate(R.menu.main, menu); return true; androidmainfest.xml: 1.Android Layout文件Layout文件,用来呈现一个拨打电话的按钮。1. 2. 6.7. 8. 13.14. Activity使用以下代码,Android拨打电话:1. Intent callIntent = new Intent(Intent.ACTION_CALL);2. callIntent.setData(Uri.parse();3. startActivity(callIntent);文件:MainActivity.java 当点击拨打电话按钮
9、时,就会拨打1. package net.cublog.android;2.3. import android.app.Activity;4. import android.content.Context;5. import android.content.Intent;6. import .Uri;7. import android.os.Bundle;8. import android.telephony.PhoneStateListener;9. import android.telephony.TelephonyManager;10. import android.util.Log;1
10、1. import android.view.View;12. import android.view.View.OnClickListener;13. import android.widget.Button;14.15. public class MainActivity extends Activity 16. private Button button;17. 18. Override19. public void onCreate(Bundle savedInstanceState) 20. 21. super.onCreate(savedInstanceState);22. set
11、ContentView(R.layout.main);23. 24. button = (Button) findViewById(R.id.buttonCall);25. 26. / add button listener27. button.setOnClickListener(new OnClickListener() 28. 29. Override30. public void onClick(View arg0) 31. 32. Intent callIntent = new Intent(Intent.ACTION_CALL);33. callIntent.setData(Uri
12、.parse();34. startActivity(callIntent);35. 36. 37. 38. );39. 40. 41. 42. 43. Android Manifest拨打电话,Android需要CALL_PHONE的权限。在AndroidManifest.xml中添加以下代码:1. 添加后:1. 2. 6.7. 8. 9.10. 13. 16. 17. 18.19. 20. 21. 22. 23.24. PhoneStateListener 例子更新上面的Activity,模拟拨打电话的状态,当电话拨打结束后,返回原始Activity,实际上只是重启了这个activity。
13、1. package net.cublog.android;2.3. import android.app.Activity;4. import android.content.Context;5. import android.content.Intent;6. import .Uri;7. import android.os.Bundle;8. import android.telephony.PhoneStateListener;9. import android.telephony.TelephonyManager;10. import android.util.Log;11. imp
14、ort android.view.View;12. import android.view.View.OnClickListener;13. import android.widget.Button;14.15. public class MainActivity extends Activity 16. private Button button;17. 18. Override19. public void onCreate(Bundle savedInstanceState) 20. 21. super.onCreate(savedInstanceState);22. setConten
15、tView(R.layout.main);23. 24. button = (Button) findViewById(R.id.buttonCall);25. 26. / add PhoneStateListener27. PhoneCallListener phoneListener = new PhoneCallListener();28. TelephonyManager telephonyManager = (TelephonyManager) this29. .getSystemService(Context.TELEPHONY_SERVICE);30. telephonyMana
16、ger.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);31. 32. 33. / add button listener34. button.setOnClickListener(new OnClickListener() 35. 36. Override37. public void onClick(View arg0) 38. 39. Intent callIntent = new Intent(Intent.ACTION_CALL);40. callIntent.setData(Uri.parse();41. sta
17、rtActivity(callIntent);42. 43. 44. 45. );46. 47. 48. 49. /monitor phone call activities50. private class PhoneCallListener extends PhoneStateListener 51. 52. private boolean isPhoneCalling = false;53. 54. String LOG_TAG = LOGGING 123;55. 56. Override57. public void onCallStateChanged(int state, Stri
18、ng incomingNumber) 58. 59. if (TelephonyManager.CALL_STATE_RINGING = state) 60. / phone ringing61. Log.i(LOG_TAG, RINGING, number: + incomingNumber);62. 63. 64. if (TelephonyManager.CALL_STATE_OFFHOOK = state) 65. / active66. Log.i(LOG_TAG, OFFHOOK);67. 68. isPhoneCalling = true;69. 70. 71. if (Tele
19、phonyManager.CALL_STATE_IDLE = state) 72. / run when class initial and phone call ended, 73. / need detect flag from CALL_STATE_OFFHOOK74. Log.i(LOG_TAG, IDLE);75. 76. if (isPhoneCalling) 77. 78. Log.i(LOG_TAG, restart app);79. 80. / restart app81. Intent i = getBaseContext().getPackageManager()82.
20、.getLaunchIntentForPackage(83. getBaseContext().getPackageName();84. i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);85. startActivity(i);86. 87. isPhoneCalling = false;88. 89. 90. 91. 92. 93. 由于PhoneStateListener需要READ_PHONE_STATE权限,需要在AndroidManifest.xml中添加以下代码:1. 添加后AndroidManifest.xml如下:1. 2. 6.7. 8.
21、 9. 10.11. 14. 17. 18. 19.20. 21. 22. 23. 24.25. 1.答:import android.app.Activity;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;p
22、ublic class MainActivity extends Activity private Button mCallButton;Overrideprotected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mCallButton = (Button) findViewById(R.id.btn_call);mCallButton.setOnClickListener(new OnClickListe
23、ner() Overridepublic void onClick(View v) / TODO Auto-generated method stub/打给联通客服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;/public void clickHandler(View source)/TextView tv = (TextView) findViewById(R.id.show);/tv.setText(你好!现在时间: + new java.util.Date();/activity_main.xml: AndroidManifest.xml: /ac
限制150内