源码简介
类似于360样的手机助手
源码截图
源码片段:
- public class FlashWidgetService extends Service {
- private ApwReciver apReciver;// appwidget广播
- Camera mCamera;
- Camera.Parameters parameters;
- private boolean blag = false; // 控制变量,用于更新闪光灯状态
- @Override
- public IBinder onBind(Intent arg0) {
- return null;
- }
- @SuppressLint("NewApi")
- @Override
- public void onCreate() {
- // 广播接收器
- apReciver = new ApwReciver();
- // 得到Camera对象
- mCamera = Camera.open(0);
- parameters = mCamera.getParameters();
- super.onCreate();
- }
- @Override
- public void onStart(Intent intent, int startId) {
- // 注册appwidget的广播
- IntentFilter intentFilter = new IntentFilter();
- intentFilter.addAction(FlashWidgetProvider.OPEN_ACTION);//
- intentFilter.addAction(FlashWidgetProvider.ISOPEN_ACTION);
- intentFilter.addAction(FlashWidgetProvider.ISCLOSE_ACTION);
- registerReceiver(apReciver, intentFilter);
- super.onStart(intent, startId);
- }
- @Override
- public void onDestroy() {
- if (mCamera != null) {
- mCamera.release();
- }
- }
- public class ApwReciver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- if (intent.getAction().equals(FlashWidgetProvider.OPEN_ACTION)) {
- if (blag == false) {// 未打开
- // 开启闪光灯
- parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
- mCamera.setParameters(parameters);
- // 发送一条广播,在AppWidget里面接受,改变手电筒的图片
- sendBroadcast(new Intent(FlashWidgetProvider.ISOPEN_ACTION));
- blag = true;
- } else if (blag == true) {// 已打开
- // 关闭闪光灯
- parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
- mCamera.setParameters(parameters);
- sendBroadcast(new Intent(FlashWidgetProvider.ISCLOSE_ACTION));
- blag = false;
- }
- }
- }
- }
- }