第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在沒有root的情況下訪問Android應(yīng)用程序上的數(shù)據(jù)庫

如何在沒有root的情況下訪問Android應(yīng)用程序上的數(shù)據(jù)庫

湖上湖 2023-06-04 15:20:53
我正在開發(fā)一個包含 100 個元素的數(shù)據(jù)庫的小型應(yīng)用程序。我導(dǎo)入了數(shù)據(jù)庫,但只有一個模擬器(我擁有的 3 個女巫)運行正常。我發(fā)現(xiàn)它運行沒有問題,因為“Songs.db”數(shù)據(jù)庫存在于 data/data/myapppackage/databases/ 文件夾中,如果不對設(shè)備進(jìn)行 root,我將無法訪問。我通過互聯(lián)網(wǎng)搜索解決此問題的不同方法和解決方案,但沒有任何效果。我是 android 編程的新手,對于這種問題,沒有任何教程。public class DatabaseHelper extends SQLiteOpenHelper {    public static final String DATABASE_NAME = "Songs.db";    public static final String TABLE_NAME = "songs_table";    public static final String COL_1 = "ID";    public static final String COL_2 = "TITLE";    public DatabaseHelper (Context context) {        super( context, DATABASE_NAME, null, 1 );        SQLiteDatabase db = this.getWritableDatabase();    }    public Cursor getData(int id) {        SQLiteDatabase db = this.getReadableDatabase();        Cursor res =  db.rawQuery( "select TITLE from songs_table where ID="+id+"", null );        return res;    }}和 PlayerTurn 類myDb = new DatabaseHelper( this );Cursor rs = db.getData( b );rs.moveToFirst();tit = rs.getString( rs.getColumnIndex( db.COL_2 ) );我大多數(shù)時候收到的錯誤消息是android.database.sqlite.SQLiteException: no such table: songs_table (code 1): 誰能幫幫我?我花了將近 15 個小時...
查看完整描述

1 回答

?
拉莫斯之舞

TA貢獻(xiàn)1820條經(jīng)驗 獲得超10個贊

您可以將數(shù)據(jù)庫復(fù)制到 SD 卡中,您可以隨時從 SD 卡訪問數(shù)據(jù)庫


試試這個代碼:


 try {

    File sd = Environment.getExternalStorageDirectory();

    File data = Environment.getDataDirectory();

    if (sd.canWrite()) {

        String currentDBPath = "data/"+sPackageName+"/databases/"+sDBName;

        String backupDBPath = "/.appname-external-data-cache/"+sDBName; //"{database name}";

        File dir = new File(sd,backupDBPath.replace(sDBName,""));

        if(dir.mkdir()) {


        }

        File currentDB = new File(data, currentDBPath);

        File backupDB = new File(sd, backupDBPath);

        if (currentDB.exists()) {

            FileChannel src = new FileInputStream(currentDB).getChannel();

            FileChannel dst = new FileOutputStream(backupDB).getChannel();

            dst.transferFrom(src, 0, src.size());

            src.close();

            dst.close();

        }

    } 


   } catch (Exception e) {

}


查看完整回答
反對 回復(fù) 2023-06-04
  • 1 回答
  • 0 關(guān)注
  • 214 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號