您的位置:首页 > 编程语言

安卓必备五个常用代码片段整理

2015-12-10 09:58 387 查看
“`

拨打电话

public static void call(Context context, String phoneNumber) {

context.startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(“tel:” + phoneNumber)));

}

跳转至拨号界面

public static void callDial(Context context, String phoneNumber) {

context.startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(“tel:” + phoneNumber)));

}

发送短信

public static void sendSms(Context context, String phoneNumber,

String content) {

Uri uri = Uri.parse(“smsto:”

+ (TextUtils.isEmpty(phoneNumber) ? “” : phoneNumber));

Intent intent = new Intent(Intent.ACTION_SENDTO, uri);

intent.putExtra(“sms_body”, TextUtils.isEmpty(content) ? “” : content);

context.startActivity(intent);

}

唤醒屏幕并解锁

public static void wakeUpAndUnlock(Context context){

KeyguardManager km= (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);

KeyguardManager.KeyguardLock kl = km.newKeyguardLock(“unLock”);

//解锁

kl.disableKeyguard();

//获取电源管理器对象

PowerManager pm=(PowerManager) context.getSystemService(Context.POWER_SERVICE);

//获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是LogCat里用的Tag

PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK,”bright”);

//点亮屏幕

wl.acquire();

//释放

wl.release();

}

需要添加权限

来自:http://blog.csdn.net/zhaokaiqiang1992
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: