Android的SQLite数据库与DATABSE的具体位置可能吗? [英] android SQLite database with databse on specific location possible?

查看:200
本文介绍了Android的SQLite数据库与DATABSE的具体位置可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作需要数据库中的APP,我已经创建了数据库,它接受查询时,创建数据库,我能够做的所有操作。
以下是其中工程数据库:

I am working on an APP which require database, I have created database and it accepts the query, creates the database, and I am able to do all operations. following is the database which works:

    import java.util.ArrayList;
    import java.util.List;

    import android.content.ContentValues;
    import android.content.Context;
    import android.database.Cursor;
    import android.database.sqlite.SQLiteDatabase;
    import android.database.sqlite.SQLiteOpenHelper;

    public class DatabaseHandler extends SQLiteOpenHelper {

// All Static variables
// Database Version
private static final int DATABASE_VERSION = 1;

// Database Name
private static final String DATABASE_NAME = "sandeep.db";

// Table name
private static final String TABLE_C = "table_data";

// Table Columns names
private static final String KEY_ID = "id";
private static final String KEY_NAME = "name";
private static final String KEY_PH_NO = "phone_number";

public DatabaseHandler(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

// Creating Tables
@Override
public void onCreate(SQLiteDatabase db) {
    String CREATE_TABLE = "CREATE TABLE " + TABLE_C + "("
            + KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT,"
            + KEY_PH_NO + " TEXT" + ")";
    db.execSQL(CREATE_TABLE);
 }
}

数据库中获取的默认位置/数据/ dataapp_name创建/但我不能访问因无根的电话​​。

The database gets created in default location /data/dataapp_name/ but I cannot access it due to unrooted phone.

我的问题:结果
1.如何在SD卡或手机内存是可公开访问的创建sandeep.db?
2.我可以创建一个WhatsApp的像文件夹,并有我的数据库驻留在?

my Problem:
1. how to create sandeep.db on sdcard or on phone memory which is publicly accessible? 2. Can I create a Whatsapp like folder and have my database reside in that?

推荐答案

使用这种方法命名为 SQLiteDatabase.openOrCreateDatabase(字符串路径,SQLiteDatabase.CursorFactory工厂)
 它可以让你在SD卡创建数据库。

Use this method named SQLiteDatabase.openOrCreateDatabase(String path, SQLiteDatabase.CursorFactory factory). It will allow you to create database on sdcard.

您需要添加以下在AndroidManifest.xml中的权限,

You need to add following permission in your AndroidManifest.xml ,

android.permission.WRITE_EXTERNAL_STORAGE

这篇关于Android的SQLite数据库与DATABSE的具体位置可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆