2009-06-04 5 views
1

JSR 256を使用して電源コードのプラグをコンセントから抜くときは、どうすれば検出できますか? JSRのスペックを簡単に見からJSR 256バッテリイベント

答えて

1

(あなたがして、仕様自体の付録D、最新のJavaMEのSDK、ソニーエリクソンの開発者向けウェブサイト、グーグルで始まる、コード例を探すこともできます)

いつものように、私は、JSRの多様な実装では、断片化が心配になりますが、ここでは私の最初のアイデアです:

import javax.microedition.sensor.*; 

SensorInfo[] powerSensorInfoArray = SensorManager.findSensors("power","ambient"); 

//let's assume there is one SensorInfo in the array. 

//open a connection to the sensor. 

SensorConnection connection = (SensorConnection)Connector.open(powerSensorInfoArray[0].getUrl(), Connector.READ); 

// add a DataListener to the connection 

connection.setDataListener(new MyDataListener(), 1); 

// implement the data listener 

public class MyDataListener implements DataListener { 

public void dataReceived(SensorConnection aSensor, Data[] aDataArray, boolean isDataLost) { 

//let's assume there is only one channel for the sensor and no data was lost. 

// figure out what kind of data the channel provides. 

int dataType = aDataArray[0].getChannelInfo().getDataType(); 

//now, I suggest you switch on dataType and print the value on the screen 

// experimentation on the JSR256 implementation you're targetting seems to be 

// the only way to figure out out power data is formatted and what values mean. 

//only one of the following 3 lines will work: 

double[] valueArray = aDataArray[0].getDoubleValues(); 
int[] valueArray = aDataArray[0].getIntValues(); 
Object[] valueArray = aDataArray[0].getObjectValues(); 

// let's assume one value in the valueArray 

String valueToPrint = "" + valueArray[0]; 

// see what happens with that and you plug or unplug the power supply cable. 

} 

} 

あなたのMIDletの権限にjavax.microedition.io.Connector.sensorを追加する必要があります。

------- EDITソニー・エリクソンサティオ携帯電話上のJSR-256の実装(S60第5版)から------

ドキュメント:

センサーがあり、バッテリーの充電以下の特性:

  • 数量:battery_charge

  • コンテキストタイプ:デバイス

  • URL:センサー:battery_charge; contextType =デバイス;モデル=ソニーエリクソン

  • チャンネル:(インデックス:名前、範囲、単位)

  • 0:battery_charge、0-100、パーセント

  • 1:charger_state、0-1、ブール

+0

ありがとう、男! 本当に大きな助けになった! 私はそれを試して、2あなたに戻ってきます。 – Attilah

1

あなたはprojecのアプリケーション記述子のAPIのアクセス許可]タブにjavax.microedition.io.Connector.sensorを追加しますtプロパティ。