@Override public void onReceive(final Context context, final Intent intent) { String action = intent.getAction(); if (Intent.ACTION_BATTERY_CHANGED.equals(action) || Intent.ACTION_BATTERY_LOW.equals(action) || Intent.ACTION_BATTERY_OKAY.equals(action)) { // バッテリーが変化した時 mHostBatteryManager.setBatteryRequest(intent); List<Event> events = EventManager.INSTANCE.getEventList( mServiceId, HostBatteryProfile.PROFILE_NAME, null, HostBatteryProfile.ATTRIBUTE_ON_BATTERY_CHANGE); for (int i = 0; i < events.size(); i++) { Event event = events.get(i); Intent mIntent = EventManager.createEventMessage(event); HostBatteryProfile.setAttribute( mIntent, HostBatteryProfile.ATTRIBUTE_ON_BATTERY_CHANGE); Bundle battery = new Bundle(); double level = ((double) (mHostBatteryManager.getBatteryLevel())) / ((double) getBatteryScale()); HostBatteryProfile.setLevel(battery, level); HostBatteryProfile.setBattery(mIntent, battery); sendEvent(mIntent, event.getAccessToken()); } } }
@Override public void onReceive(final Context context, final Intent intent) { String action = intent.getAction(); if (Intent.ACTION_POWER_CONNECTED.equals(action) || Intent.ACTION_POWER_DISCONNECTED.equals(action)) { // バッテリーが充電された時 mHostBatteryManager.setBatteryRequest(intent); List<Event> events = EventManager.INSTANCE.getEventList( mServiceId, HostBatteryProfile.PROFILE_NAME, null, HostBatteryProfile.ATTRIBUTE_ON_CHARGING_CHANGE); for (int i = 0; i < events.size(); i++) { Event event = events.get(i); Intent mIntent = EventManager.createEventMessage(event); HostBatteryProfile.setAttribute( mIntent, HostBatteryProfile.ATTRIBUTE_ON_CHARGING_CHANGE); Bundle charging = new Bundle(); if (Intent.ACTION_POWER_CONNECTED.equals(action)) { HostBatteryProfile.setCharging(charging, true); } else { HostBatteryProfile.setCharging(charging, false); } HostBatteryProfile.setBattery(mIntent, charging); sendEvent(mIntent, event.getAccessToken()); } } }
@Override public void onCreate() { super.onCreate(); // Get application class instance. mApp = (HostDeviceApplication) this.getApplication(); // EventManagerの初期化 EventManager.INSTANCE.setController(new MemoryCacheController()); // ファイル管理クラスの作成 mFileMgr = new FileManager(this); mFileDataManager = new FileDataManager(mFileMgr); // add supported profiles addProfile(new HostConnectProfile(BluetoothAdapter.getDefaultAdapter())); addProfile(new HostNotificationProfile()); addProfile(new HostDeviceOrientationProfile()); addProfile(new HostBatteryProfile()); addProfile(new HostMediaStreamingRecordingProfile()); addProfile(new HostPhoneProfile()); addProfile(new HostSettingsProfile()); addProfile(new HostMediaPlayerProfile()); addProfile(new HostFileProfile(mFileMgr)); addProfile(new HostFileDescriptorProfile(mFileDataManager)); addProfile(new HostVibrationProfile()); addProfile(new HostProximityProfile()); addProfile(new HostCanvasProfile()); addProfile(new HostTouchProfile()); addProfile(new HostKeyEventProfile()); // バッテリー関連の処理と値の保持 mHostBatteryManager = new HostBatteryManager(); mHostBatteryManager.getBatteryInfo(this.getContext()); mIfBatteryCharge = new IntentFilter(); mIfBatteryCharge.addAction(Intent.ACTION_BATTERY_CHANGED); mIfBatteryCharge.addAction(Intent.ACTION_BATTERY_LOW); mIfBatteryCharge.addAction(Intent.ACTION_BATTERY_OKAY); mIfBatteryConnect = new IntentFilter(); mIfBatteryConnect.addAction(Intent.ACTION_POWER_CONNECTED); mIfBatteryConnect.addAction(Intent.ACTION_POWER_DISCONNECTED); // オーバーレイ mCameraOverlay = new CameraOverlay(this); mCameraOverlay.setFileManager(mFileMgr); // MediaPlayer (Video) IntentFilter. mIfMediaPlayerVideo = new IntentFilter(); mIfMediaPlayerVideo.addAction(VideoConst.SEND_VIDEOPLAYER_TO_HOSTDP); }
/** * Battery Profile<br> * バッテリーレベルを取得. * * @return バッテリーレベル */ public int getBatteryScale() { mHostBatteryManager.getBatteryInfo(this.getContext()); return mHostBatteryManager.getBatteryScale(); }