안드로이드에서 우리는 일반적으로 SQLite를 사용하며, 인터넷 상에 예를 들어 this과 같이 많은 수의 예제가 있습니다. 나는 온라인으로 특히 사례의 대부분 싫어하지만, 하나의 기본은 기본적으로 다음 SQLite 데이터베이스는 응용 프로그램 실행하기 전에, 미리 준비하고, 저장 할 것이라는 가정으로
public class DataBaseHelper extends SQLiteOpenHelper {
private static String DB_PATH = "/data/data/com.your.application/databases/";
private static String DB_NAME = "android.db";
private SQLiteDatabase myDataBase;
private final Context myContext;
/**
* Constructor Takes and keeps a reference of the passed context in order to
* access to the application assets and resources.
*
* @param context
*/
public DataBaseHelper(Context context) {
super(context, DB_NAME, null, 1);
this.myContext = context;
}
/**
* Creates a empty database on the system and rewrites it with your own
* database.
*/
public void createDataBase() throws IOException {
boolean dbExist = checkDataBase();
if (dbExist) {
// do nothing - database already exist
Log.v("Database","Database Exists");
} else {
Log.v("Database","Data base needs creating");
// By calling this method and empty database will be created into
// the default system path
// of your application so we are gonna be able to overwrite that
// database with our database.
this.getReadableDatabase();
try {
Log.v("Database","CopyDataBase");
copyDataBase();
} catch (IOException e) {
throw new Error("Error Copying Database");
}
}
}
/**
* Check if the database already exist to avoid re-copying the file each
* time you open the application.
*
* @return true if it exists, false if it doesn't
*/
private boolean checkDataBase() {
SQLiteDatabase checkDB = null;
try {
String myPath = DB_PATH + DB_NAME;
checkDB = SQLiteDatabase.openDatabase(myPath, null,
SQLiteDatabase.OPEN_READWRITE);
} catch (SQLiteException e) {
// database does't exist yet.
}
if (checkDB != null) {
checkDB.close();
}
return checkDB != null ? true : false;
}
/**
* Copies your database from your local assets-folder to the just created
* empty database in the system folder, from where it can be accessed and
* handled. This is done by transfering bytestream.
*/
private void copyDataBase() throws IOException {
// Open your local db as the input stream
InputStream myInput = myContext.getAssets().open(DB_NAME);
// Path to the just created empty db
String outFileName = DB_PATH + DB_NAME;
// Open the empty db as the output stream
OutputStream myOutput = new FileOutputStream(outFileName);
// transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer)) > 0) {
myOutput.write(buffer, 0, length);
}
// Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
Log.v("Log","Database copied sucsessfully");
}
public void openDataBase() throws SQLException {
// Open the database
String myPath = DB_PATH + DB_NAME;
myDataBase = SQLiteDatabase.openDatabase(myPath, null,SQLiteDatabase.OPEN_READWRITE);
Log.v("Logger","Database Opened");
}
@Override
public synchronized void close() {
if (myDataBase != null)
myDataBase.close();
super.close();
}
@Override
public void onCreate(SQLiteDatabase db) {
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
public Cursor get() {
return myDataBase.query("AwayMessages", null, null, null, null, null,null);
}
public SQLiteDatabase returnDatabase() {
return myDataBase;
}
}
자산 당신은 GPS를 사용해야합니다 this question
을 확인하고, 그 다음 here
를하려고 카메라를 실행하고 응용 프로그램에 다시 사진을 찍어, GPS에 관해서는
폴더 내장 디지털 나침반의 +가속도계. –정보를 제공해 주셔서 감사합니다. -하지만 문제는 - 예를 들어 GPS를 만들면 GPS 버튼을 클릭하면 GPS가 현재 위치/지역에 위치하게됩니다. 어떻게하면 안드로이드에서 할 수 있습니까? 어떤 예를 들어 주시겠습니까? – theBorneo