Android常用功能实例 如IMEI号
2010-07-15 20:14:00 来源:WEB开发网Java代码
TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
String imei = tm.getDeviceId();
String tel = tm.getLine1Number();
TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
String imei = tm.getDeviceId();
String tel = tm.getLine1Number();
看来,android的确加速了j2me的消亡。
Android 振动器
总感觉手机上的振动器没有多大用处(当然静音模式下的振铃很有用),但还是顺带着说一下吧,只有两行代码:
1、获取振动服务的实例
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
2、设置振动时长,单位当然也是ms
vibrator.vibrate(1000);
如果你觉得这样过去单调的话,可以设个节奏:
vibrator.vibrate(new long[]{10, 100, 20, 200}, -1);
两个参数,习惯告诉我第一个是节奏,第二个是重复次数,可事实并没有这么简单,我翻译不好,大家还是看原文吧:
Java代码
public void vibrate (long[] pattern, int repeat)
pattern: an array of longs of times to turn the vibrator on or off.
repeat: the index into pattern at which to repeat, or -1 if you don't want to repeat.
public void vibrate (long[] pattern, int repeat)
pattern: an array of longs of times to turn the vibrator on or off.
repeat: the index into pattern at which to repeat, or -1 if you don't want to repeat.
google喜欢弄些技巧,我却觉得这里有点弄巧成拙了。
Android 闹钟
最近看了一下Android的闹钟管理类(AlarmManager),真不错误,强大又简单,代码如下:
1、建立一个AlarmReceiver继承入BroadcastReceiver,并在AndroidManifest.xml声明
Java代码
public static class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "闹钟提示:时间到!", Toast.LENGTH_LONG).show();
更多精彩
赞助商链接