fragment中怎么读取数据库的数据?

数据库是在service中创建的,数据也就相应的存储到数据库中了,现在想在我的fragment所在的界面进行数据的读取,不知道用什么样的方法,求大神指点~非常感谢!

 service中的创建数据库的代码:
 private void broadcastUpdate(final String action,final BluetoothGattCharacteristic characteristic){
     final Intent intent = new Intent(action);
     if(UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())){
        int flag = characteristic.getProperties();
        int format = -1;
        if((flag & 0x01)!= 0){
            format = BluetoothGattCharacteristic.FORMAT_UINT16;
            Log.d(TAG,"Heart Rate format UINT16.");
        }else{
            format = BluetoothGattCharacteristic.FORMAT_UINT8;
            Log.d(TAG,"Heart Rate format UINT8.");
        }
        heartRate = characteristic.getIntValue(format,1);
        Log.d(TAG,String.format("Received Heart Rate : %d",heartRate));
        intent.putExtra(EXTRA_DATA,String.valueOf(heartRate));
        saveDatabase();
     }
     ...
     sendBroadcast(intent);
 }
 private void saveDatabase(){
    dbHelper = new SaveDatabaseHelper(this,"data.db",null,1);
    dbHelper.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put("rate",heartRate);
    dbHelper.insert(values);
}

现在想在fragment中进行数据库的读取数据的操作,但是不太会,请教大神,在线等~

1个回答

d broadcastUpdate(final String action,final BluetoothGattCharacteristic characteristic){
final Intent intent = new Intent(action);
if(UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())){
int flag = characteristic.getProperties();
int format = -1;
if((flag & 0x01)!= 0){
format = BluetoothGattCharacteristic.FORMAT_UINT16;
Log.d(TAG,"Heart Rate format UINT16.");
}else{
format = BluetoothGattCharacteristic.FORMAT_UINT8;
Log.d(TAG,"Heart Rate format UINT8.");
}

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐