我有一个数据库保存在我的应用程序资产文件夹中,并在应用程序首次打开时使用以下代码复制数据库.
inputStream = mContext.getAssets().open(Utils.getDatabaseName());
if(inputStream != null) {
int mFileLength = inputStream.available();
String filePath = mContext.getDatabasePath(Utils.getDatabaseName()).getAbsolutePath();
// Save the downloaded file
output = new FileOutputStream(filePath);
byte data[] = new byte[1024];
long total = 0;
int count;
while ((count = inputStream.read(data)) != -1) {
total += count;
if(mFileLength != -1) {
// Publish the progress
publishProgress((int) (total * 100 / mFileLength));
}
output.write(data, 0, count);
}
return true;
}
Run Code Online (Sandbox Code Playgroud)
上面的代码运行没有问题,但是当你尝试查询数据库时,你会得到一个SQLite:没有这样的表异常.
此问题仅发生在Android P中,所有早期版本的Android都能正常工作.
这是Android P的已知问题还是有些变化?
我YuvImage用来压缩android.hardware.Camerajpeg 的feed.从那时起,我一直skia onFlyCompress在logcat中看到消息,这完全污染了它.有没有办法禁用此消息?我知道我可以过滤logcat输出,但这意味着一直到处都做,这不是一个修复,而是一个解决方法.我根本不想要打印这些消息
我想从assets文件夹中复制SQLite数据库.这是我的DatabaseAdapter.java类
package com.example.dictionary;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DatabaseAdapter extends SQLiteOpenHelper {
static String DB_PATH = "/data/data/com.example.dictionary/databases/";
static String DB_NAME = "dict.db";
SQLiteDatabase db;
private final Context mContext;
public DatabaseAdapter(Context context) {
super(context, DB_NAME, null, 1);
this.mContext = context;
}
public void createDB(){
boolean dbExist = checkDB();
if (dbExist) {
} else {
this.getReadableDatabase();
try {
copyDB();
} catch (Exception e) {
throw new Error("Error copying DB");
}
} …Run Code Online (Sandbox Code Playgroud) 从Android框架的源代码中,有一个名为的文件config.xml,其中存储了Android内部使用的一些值。
还有一个值控制被视为缩放手势的手指之间的最小距离:
<!-- Minimum span needed to begin a touch scaling gesture.
If the span is equal to or greater than this size, a scaling gesture
will begin, where supported. (See android.view.ScaleGestureDetector)
This also takes into account the size of any active touch points.
Devices with screens that deviate too far from their assigned density
bucket should consider tuning this value in a device-specific overlay.
For best results, care should be taken such that this value remains
larger …Run Code Online (Sandbox Code Playgroud)