saveToGallery SQLiteDatabase:插入bucket_id

时间:2018-12-15 14:21:11

标签: android mpandroidchart

我无法保存图表。我从saveToGallery中获得了错误的定价,在logs中看到的是:

  

SQLiteDatabase:插入bucket_id = -2075821635 date_modified = 1544882049 is_hw_burst = 0 datetaken = 1 544882049000 bucket_display_name = DCIM parent = 8 format = 14337 storage_id = 65537 media_type = 1 mime_type = image / jpeg title = chart.jpg d escription = MPAndroidChart -库保存_data = / storage / emulated / 0 / DCIM / chart.jpg _size = 33015 date_add = 1544882049 _display_name = chart.jpg方向= 0。

我拥有清单中的所有权限,还授予了runtime权限。 根本原因是什么?

这是我在runtime上进行验证的方法

public static void verifyStoragePermissions(Activity activity) {
        // Check if we have write permission
        int permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE);

    if (permission != PackageManager.PERMISSION_GRANTED) {
        // We don't have permission so prompt the user
        ActivityCompat.requestPermissions(
                activity,
                PERMISSIONS_STORAGE,
                REQUEST_EXTERNAL_STORAGE
        );
    }
}

这用于保存图表:

case R.id.fab_save:
            boolean saved = lineChart.saveToGallery(file_name,100);
                Toast.makeText(getApplicationContext(),"File saved "+saved, Toast.LENGTH_LONG ).show();
            break;

1 个答案:

答案 0 :(得分:0)

问题出在file_name的唯一性上。例如,可以是:

`Long tsLong = System.currentTimeMillis()/1000;
                String ts = tsLong.toString();
            boolean saved = lineChart.saveToGallery(file_name+ts,100);`