-
《移动应用开发》试题
题目:
1.
请实现点击按钮拨打电话功能。
(
20
分)
2.
请实现点击按钮改变文本控
件颜色的功能。
(
30
分)
3.
请实现使用
soc
ket
通信的服务器端代码。
(
50<
/p>
分)
要求:逻辑结构完整,答案要点突
出,论述充分,每题答案字数不少于
400
字。答案不得完全照
抄书本
或其他资料,不得互相抄袭。
2016
年
12
月
(
专
科
)
中南大学网络教育课程考试
《移动应用开发
》答卷
本人承诺:本试卷确为本人独立完成,若有违反愿意接受处理。
签名
:
______________
学号:
____________________
专业:
__________________
学习中心:<
/p>
_________________
题号
成绩
答:
①
private Button btn2;
②
btn2=(Button)findViewById(2);//
p>
在
xml
中把
bu
tton2
改成
btn2
,为该按钮的
id
③
lickListener(new
OnClickListener(){});
④在
OnClick()
Intent in2 = new Intent();
ion(_CALL);//
指定意图动作
a((
指定电话号码
startActivity(in2);
⑤在
android
系统中,所有系统请求,必须要在
中注册
在
ent
上面
:
package
import
;
import
import ty;
import ialog;
import
import Interface;
import
import Inflater;
import
import
import kListener;
import
import xt;
public class MainActivity
extends Activity {
private Button btn;
移动应用开发
第
1
页
共
24
页
一
二
三
总分
评阅人签字
1.
/a191030148/article/details/9396099
2016
年
12
月<
/p>
(
专科
)
private Button btn2;
private EditText et;
private
EditText et2;
@Override
protected void onCreate(Bundle savedInstanceState)
{
te(savedInstanceState);
setContentView(ty_main);
et = (EditText)findViewById(xt1);
et2 =
(EditText)findViewById(xt2);
btn2 = (Button)findViewById(2);
btn = (Button)findViewById(1);
lickListener(new
OnClickListener(){
@Override
public void
onClick(View arg0) {
//
TODO Auto-generated method stub
Intent
in2 = new Intent();
ion(_CALL);
a((
startActivity(in2);
@Override
public void onClick(View arg0) {
// TODO Auto-generated
method stub
final String str =
t().toString().trim();
final String
str2 = t().toString().trim();
if ((str2))
{
}
else
{
}
n(
Intent in = new Intent(,);
startActivity(in);
}});
lickListener(new
OnClickListener(){
}});
移动应用开发
第
2
页
共
24
页
2016
年
12
月
(
专科
)
}
@Override
public boolean
onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action
bar if it is present.
getMenuInflater().inflate(, menu);
return true;
}
}
:
package=
android:versionCode=
android:versionName=
android:minSdkVersion=
android:targetSdkVersion=
android:allowBackup=
android:icon=
android:label=
android:theme=
android:name=
android:label=
android:name=
android:label=
移动应用开发
第
3
页
共
24
页
2016
年
12
月
(
专科
)
1.
/
①
Android
Layout
文件
Layout
p>
文件,用来呈现一个拨打电话的按钮。
1.
xml
version
=
encoding
=
>
2.
<
LinearLayout
xml
ns:android
=
androi
d
3.
and
roid:layout_width
=
4.
android:layout_
height
=
5.
android:orienta
tion
=
>
6.
7.
8.
<
Button
9.
android:id
=
10.
android:layout_
width
=
nt
11.
and
roid:layout_height
=
12.
p>
android:text
=
/>
13.
14.
LinearLayout
>
②
Activity
使用以下代码,
Android
拨打电话:
1.
Intent
callIntent
=
new
Intent
(
Intent
.
ACTION_CALL
);
2.
p>
callIntent
.
setData<
/p>
(
Uri
.
pa
rse
(
));
3.
startActivity
p>
(
call
Intent
< br>);
移动应用开发
第
4
页
共
24
页
2016
年
12
月
(
专科
)
文件:
当点击拨打电话按钮时,就会
拨打
这个号码。
1.
package
net
.
cublog
.
andr
oid
;
2.
3.
import
android
.
p>
app
.
Activity
;
4.
import
android
.
p>
content
.
Context
;
5.
import
android
.
p>
content
.
Intent
;
6.
import
android
.
p>
net
.
Uri
;
7.
import
android
.
p>
os
.
Bundle
;
8.
import
android
.
p>
telephony
.
PhoneStat
eListener
;
9.
import
android
.
p>
telephony
.
Telephony
Manager
;
10.
import
android
.
p>
util
.
Log
;
11.
import
android
.
p>
view
.
View
;
12.
import
android
.
p>
view
.
View
.
OnClickListener
;
13.
import
android
.
p>
widget
.
Button
;
14.
15.
public
class
MainActivity
extends
Activity
{
16.
private
Button
button
;
17.
18.
@
Override
19.
public
void
onCreate
(
Bundle
s
avedInstanceState
)
{
20.
21.
p>
super
.
onCreate
(
savedInstanceStat
e
);
22.
p>
setContentView
(
R
.
layout
.
m
ain
);
23.
24.
button
=
(
But
ton
)
findViewById
(
R
.
id<
/p>
.
buttonCall
);
25.
26.
// add button
listener
27.
p>
button
.
setOnClickLi
stener
(
new
OnClickListener
()
{
28.
29.
@
Override
移动应用开发
第
5
页
共
24
页
2016
年
12
月
(
专科
)
30.
public
void
onClick
(
View
arg0
)
{
31.
32.
Intent
callIntent
=
new
Intent
(
Intent
.
ACTION_CALL
);
33.
callIntent
.
setDa
ta
(
p>
Uri
.
parse
(
));
34.
startActivity
p>
(
ca
llIntent
< br>);
35.
36.
}
37.
38.
});
39.
40.
}
41.
42.
43.
}
③
Android Manifest
拨打电话,
Android
需要
CALL_PHONE
的权限。
在
中添加以下代码:
1.
<
us
es
-
permission
android
:
name
< br>=
/>
添加后:
1.
xml
version
=
encoding
=
>
2.
<
manifest
xmlns:a
ndroid
=
android
3.
pac
kage
=
4.
android:version
Code
=
5.
android:version
Name
=
>
6.
移动应用开发
第
6
页
共
24
页
2016
年
12
月
(
专科
)
7.
<
uses-sdk android:minSdkVers
ion
=
/>
8.
<
uses-permission
android:name
=
/>
9.
10.
<
application
11.
android:icon
=
her
12.
android:label
p>
=
>
13.
<
activity
14.
android:name
=
ity
15.
android:label
p>
=
pp_name
>
16.
<
intent-
filter
>
17.
<
action
android:n
ame
=
/>
18.
19.
<
category
android
:name
=
/>
20.
intent-
filter
>
21.
ac
tivity
>
22.
ap
plication
>
23.
24.
manifest
>
④
PhoneStateListener
例子
更新上面的
Activity
,模拟拨打电话的状态,当电话拨打结束后,返回原始
Activity
,实际
上只是重启了这个
activity
。
1.
package
net
.
cublog
.
andr
oid
;
2.
3.
import
android
.
p>
app
.
Activity
;
4.
import
android
.
p>
content
.
Context
;
移动应用开发
第
7
页
共
24
页
2016
年
12
月
(
专科
)
5.
import
android
.
p>
content
.
Intent
;
6.
import
android
.
p>
net
.
Uri
;
7.
import
android
.
p>
os
.
Bundle
;
8.
import
android
.
p>
telephony
.
PhoneStat
eListener
;
9.
import
android
.
p>
telephony
.
Telephony
Manager
;
10.
import
android
.
p>
util
.
Log
;
11.
import
android
.
p>
view
.
View
;
12.
import
android
.
p>
view
.
View
.
OnClickListener
;
13.
import
android
.
p>
widget
.
Button
;
14.
15.
public
class
MainActivity
extends
Activity
{
16.
private
Button
button
;
17.
18.
@
Override
19.
public
void
onCreate
(
Bundle
s
avedInstanceState
)
{
20.
21.
p>
super
.
onCreate
(
savedInstanceStat
e
);
22.
p>
setContentView
(
R
.
layout
.
m
ain
);
23.
24.
button
=
(
But
ton
)
findViewById
(
R
.
id<
/p>
.
buttonCall
);
25.
26.
// add
PhoneStateListener
27.
PhoneCallListener
phoneListener
=
new
PhoneCallListener
();
28.
TelephonyManager
telephonyManager
=
(
Tel
ephonyManager
)
this
29.
.
get
SystemService
(
Contex
< br>t
.
TELEPHONY_SERVICE
);
30.
p>
telephonyManager
.
li
sten
(
phoneLis
tene
r
,
PhoneStateListener
< br>.
LISTEN_CALL_STATE
);
31.
32.
移动应用开发
第
8
页
共
24
页
2016
年
12
月
(
专科
)
33.
// add button
listener
34.
p>
button
.
setOnClickLi
stener
(
new
OnClickListener
()
{
35.
36.
@
Override
37.
public
void
onClick
(
View
arg0
)
{
38.
39.
Intent
callIntent
=
new
Intent
(
Intent
.
ACTION_CALL
);
40.
callIntent
.
setDa
ta
(
p>
Uri
.
parse
(
));
41.
startActivity
p>
(
ca
llIntent
< br>);
42.
43.
}
44.
45.
});
46.
47.
}
48.
49.
//monitor phone
call activities
50.
private
class
PhoneCallListener
extends
PhoneStateListener
{
51.
52.
private
boolean
isPhoneCalling
=
false
;
53.
54.
String
LOG_TAG
=
;
55.
56.
@
Override
57.
public
void
onCallStateC
hanged
(
int
state
,
String
incomingNumber
)
{
58.
移动应用开发
第
9
页
共
24
页
2016
年
12
月
(
专科
)
59.
if
<
/p>
(
TelephonyManager
.
CALL_STATE_RINGING
==
state
)
{
60.
// phone ringing
61.
Log
.
i
(
LOG_TAG
< br>,
+
incomingNumber
);
62.
}
63.
64.
if
<
/p>
(
TelephonyManager
.
CALL_STATE_OFFHOOK
==
state
)
{
65.
// active
66.
Log
.
i
(
LOG_TAG
< br>,
);
67.
68.
isPhoneCalling
=
true
;
69.
}
70.
71.
if
<
/p>
(
TelephonyManager
.
CALL_STATE_IDLE
==
state
)
{
72.
//
run
when
class
initial and phone call
ended,
73.
// need detect
flag from
CALL_STATE_OFFHOOK
74.
Log
.
i
(
LOG_TAG
< br>,
);
75.
76.
if
<
/p>
(
isPhoneCalling
)
p>
{
77.
78.
Log
.
i
(
LO
G_
TAG
,
);
79.
80.
//
restart app
移动应用开发
第
10
页
共
24
页
2016
年
12
月
(
专科
)
81.
Intent i
=
getBaseContext
(
).
getPackageManager
()
82.
.
p>
getLaunchIntentForPackage
(
83.
get
BaseContext
().
getPackageName
());
84.
i
.
p>
addFla
gs
(
Intent
.
FLAG_ACTIVITY_CLEAR_
TOP
);
85.
startAct
ivity
(
i
);
86.
87.
isPhoneC
alling
=
false
;
88.
}
89.
90.
}
91.
}
92.
}
93.
}
由于
PhoneStateListener
< br>需要
READ_PHONE_STATE
权限,需要在<
/p>
中添
加以下代码:
1.
<
uses-permission
android:name
=
/>
添加后
如下:
1.
xml
version
=
encoding
=
>
2.
<
manifest
xmlns:a
ndroid
=
android
3.
pac
kage
=
4.
android:version
Code
=
5.
android:version
Name
=
>
移动应用开发
第
11
页
共
24
页
-
-
-
-
-
-
-
-
-
上一篇:shipping order 的作用
下一篇:web答辩问题