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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

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

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

湖上湖 2023-06-04 15:20:53
我正在開發(fā)一個(gè)包含 100 個(gè)元素的數(shù)據(jù)庫(kù)的小型應(yīng)用程序。我導(dǎo)入了數(shù)據(jù)庫(kù),但只有一個(gè)模擬器(我擁有的 3 個(gè)女巫)運(yùn)行正常。我發(fā)現(xiàn)它運(yùn)行沒有問題,因?yàn)椤癝ongs.db”數(shù)據(jù)庫(kù)存在于 data/data/myapppackage/databases/ 文件夾中,如果不對(duì)設(shè)備進(jìn)行 root,我將無(wú)法訪問。我通過互聯(lián)網(wǎng)搜索解決此問題的不同方法和解決方案,但沒有任何效果。我是 android 編程的新手,對(duì)于這種問題,沒有任何教程。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ù)時(shí)候收到的錯(cuò)誤消息是android.database.sqlite.SQLiteException: no such table: songs_table (code 1): 誰(shuí)能幫幫我?我花了將近 15 個(gè)小時(shí)...
查看完整描述

1 回答

?
拉莫斯之舞

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

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


試試這個(gè)代碼:


 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) {

}


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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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