Chinaunix首页 | 论坛 | 博客
  • 博客访问: 520161
  • 博文数量: 257
  • 博客积分: 1666
  • 博客等级: 上尉
  • 技术积分: 1535
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-02 23:02
文章分类

全部博文(257)

文章存档

2013年(2)

2012年(255)

分类:

2012-08-13 13:26:10


点击(此处)折叠或打开

  1. 1. 注册MyReceiver广播
  2. framework/base/packages/SystemUI/AndroidManifest.xml
  3. + <receiver android:name=".MyReceiver" >
  4. + <intent-filter>
  5. + <action android:name="android.intent.action.SMITUSBMASS" />
  6. + </intent-filter>
  7. + </receiver>

  8. 2. 增加MyReceiver.java这个文件,接收广播执行UsbStorageActivity
  9. frameworks/base/packages/SystemUI/src/com/android/systemui/MyReceiver.java
  10. /*
  11.  * Copyright (C) 2011 The Android Open Source Project
  12.  *
  13.  * Licensed under the Apache License, Version 2.0 (the "License");
  14.  * you may not use this file except in compliance with the License.
  15.  * You may obtain a copy of the License at
  16.  *
  17.  *
  18.  *
  19.  * Unless required by applicable law or agreed to in writing, software
  20.  * distributed under the License is distributed on an "AS IS" BASIS,
  21.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22.  * See the License for the specific language governing permissions and
  23.  * limitations under the License.
  24.  */

  25. package com.android.systemui;

  26. import android.content.BroadcastReceiver;
  27. import android.content.ContentResolver;
  28. import android.content.Context;
  29. import android.content.Intent;
  30. import android.provider.Settings;
  31. import android.util.Slog;
  32. import android.content.ComponentName;

  33. /**
  34.  * Performs a number of miscellaneous, non-system-critical actions
  35.  * after the system has finished booting.
  36.  */
  37. public class MyReceiver extends BroadcastReceiver {
  38.     private static final String TAG = "SystemUIMyReceiver";

  39.     @Override
  40.     public void onReceive(final Context context, Intent intent) {
  41.         try {
  42.             Intent loadavg = new Intent();
  43.             ComponentName component = new ComponentName("com.android.systemui",
  44.                                 "com.android.systemui.usb.UsbStorageActivity");
  45.             if(component != null) {
  46.                 loadavg.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  47.                 loadavg.setComponent(component);
  48.                 context.startActivity(loadavg);
  49.             } else {
  50.                 Slog.e(TAG, "componenet is not existed");
  51.             }
  52.         } catch (Exception e) {
  53.             Slog.e(TAG, "Can't start startActivity", e);
  54.         }
  55.     }
  56. }

  57. 3. 增加按键F1, 发送广播
  58. framework/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
  59. + if ((keyCode == KeyEvent.KEYCODE_F1) && !down) {
  60. + //setDisplddayOutput();

  61. + Intent intent = new Intent();
  62. + intent.setAction("android.intent.action.SMITUSBMASS");//

  63. + mContext.sendBroadcast(intent);
  64. +
  65. + }

  66.          if ((keyCode == KeyEvent.KEYCODE_F3) && !down) {

  67. 4. 增加按键F11, 挂载和卸载UsbStorage到PC机.
  68. frameworks/base/packages/SystemUI/src/com/android/systemui/usb/UsbStorageActivity.java
  69. +import android.view.KeyEvent;
  70.     
  71.     // 增加SetTheUsbMass函数

  72.     private void SetTheUsbMass() {
  73.         Log.e(TAG, "+++++++++++++++++++++SetTheUsbMass");
  74.         if(!mStorageManager.isUsbMassStorageEnabled()) {
  75.             Log.e(TAG, "+++++++++++++++++++++SetUsbMassStorageEnabled");
  76.             checkStorageUsers();
  77.         } else {
  78.             Log.e(TAG, "22222+++++++++++++++++++++SetUsbMassStoragedisabled");
  79.             switchUsbMassStorage(false);
  80.         }
  81.     }

  82.     protected void onCreate(Bundle savedInstanceState) {
  83.         super.onCreate(savedInstanceState);
  84.         ......    
  85. +        SetTheUsbMass();
  86. +        finish();
  87.     }

  88.     // 增加onKeyDown函数

  89.     public boolean onKeyDown(int keyCode, KeyEvent event) {
  90.         if(keyCode==KeyEvent.KEYCODE_F11)
  91.         {
  92.             // Check for list of storage users and display dialog if needed.

  93.             if(!mStorageManager.isUsbMassStorageEnabled())
  94.                 checkStorageUsers();
  95.             else
  96.                 switchUsbMassStorage(false);
  97.         }
  98.         return super.onKeyDown(keyCode, event);
  99.     }

阅读(323) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~