I want to read (only) records from data/data/com.android.providers.telephony/databases/mmssms.db (I know no official API, etc. but since it lacks an official API I have to do it). I thought I can do it like written开发者_开发问答 How to access an existing sqlite database in Android? in the last answer, just by
SQLiteDatabase db = SQLiteDatabase.openDatabase("data/data/com.android.providers.telephony/databases/mmssms.db ", null, 0);
but the system is not able to open that DB file. Next I thought I might have to create a full blown DB Helper class
package com.test.dbaccess;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DbAdapterMms
{
private final Context ctx;
private DatabaseHelper dbHelper;
public SQLiteDatabase db;
private static class DatabaseHelper extends SQLiteOpenHelper
{
private final Context ctx;
DatabaseHelper(Context context)
{
super(context, "data/data/com.android.providers.telephony/databases/mmssms.db", null, 1);
this.ctx = context;
}
@Override
public void onCreate(SQLiteDatabase db)
{
//do nothing, this should exist
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
//do nothing, reading only
}
}
public DbAdapterMms(Context context)
{
this.ctx = context;
}
public void open()
{
dbHelper = new DatabaseHelper(ctx);
db = dbHelper.getReadableDatabase();
}
public void close()
{
dbHelper.close();
}
}
It still doesn't work, this time I think it might be an issue in the call super(); since there the DBVersion has to be given. The version I don't know, I just want to read the existing db. Can't be rocket sience...
Any help? Thanks, A.
I think you cannot read the database of another app. As in Android every app has it's own storage location on the file system which cannot be accessed from other processes. The only exception is if it is defined in the manifest file that other applications are allowed to access the data. As you're trying to access the data of an application that you don't own, you cannot edit its manifest file to grant yourself access to the data.
The only way to read the database would be if you got a rooted phone. Then you can pull the database on you PC and push it back into the store of you app. But I think that's not what you're looking for.
You can use something like this to open the smsmms database
Cursor cSys = getContentResolver().query("content://mms-sms",null, null, null,null);
Using this cursor you can manipulate the database.
getting list of mms
精彩评论