デバイスの温度ライブ グラフを作成しています。しかし、グラフの温度は常に 0 です (私は BATTERY_STATS 権限を持っています)。
private final Handler mHandler = new Handler();
private Runnable mTimer1;
private Runnable mTimer2;
private LineGraphSeries<DataPoint> mSeries1;
private LineGraphSeries<DataPoint> mSeries2;
private double graph2LastXValue = 5d;
private int temp;
これが私のBroadcastReceiverです:
private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context arg0, Intent intent) {
try {
temp = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1);
} catch (Exception e) {
//...
}
}
};
これが私のOnCreateViewです
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v =inflater.inflate(R.layout.tab_2,container,false);
getActivity().registerReceiver(this.mBatInfoReceiver,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
GraphView graph2 = (GraphView) v.findViewById(R.id.graph2);
mSeries2 = new LineGraphSeries<DataPoint>();
graph2.addSeries(mSeries2);
graph2.getViewport().setXAxisBoundsManual(true);
graph2.getViewport().setMinX(0);
graph2.getViewport().setMaxX(40);
return v;
}
これが私の...Graphコード(?)です(よくわかりません:D)
@Override
public void onResume() {
super.onResume();
mTimer2 = new Runnable() {
@Override
public void run() {
graph2LastXValue += 1d;
mSeries2.appendData(new DataPoint(graph2LastXValue, temp/10f), true, 40);
mHandler.postDelayed(this, 200);
}
};
mHandler.postDelayed(mTimer2, 1000);
}
@Override
public void onPause() {
//...
}
}
私は初心者なので、助けてください!jjoe64 の GraphView を使用しています。