2011-11-26 5 views
0

저는 안드로이드 앱에 새로운 편입니다. 예를 들어 GPS와 카메라 API를 사용하여 별표를 만들어야합니다.휴대 전화에 데이터를 저장 하시겠습니까?

어떻게 모든 데이터베이스를 저장할 수 있습니까? 전화에 저장하면 너무 작을 것입니다. 미안하지만 바보처럼 들릴지 모르지만 저는 모바일 개발에 관해서 새로운 것입니다.

아이디어가 있으십니까? 그리고 카메라 API의 용어 -이 정보를 어디에서 찾을 수 있습니까? 예를 들어, 스타 x가 y와 같이 하늘 위로 특정 스타를 향해 카메라를 향하게합니다. 우리는 GPS 좌표와 카메라 API를 사용해야 만한다는 것을 알고 있습니까? 우리가 정확한 정보를 얻을 수 있도록 이것들을 결정하십시오.

아무에게도 도움이 될 수 있습니까? 아니면 이것에 대한 정보를 얻을 수 있습니까?

많은 감사, theBorneo

+0

을 확인하고, 그 다음 here

를하려고 카메라를 실행하고 응용 프로그램에 다시 사진을 찍어, GPS에 관해서는

폴더 내장 디지털 나침반의 +가속도계. –

+0

정보를 제공해 주셔서 감사합니다. -하지만 문제는 - 예를 들어 GPS를 만들면 GPS 버튼을 클릭하면 GPS가 현재 위치/지역에 위치하게됩니다. 어떻게하면 안드로이드에서 할 수 있습니까? 어떤 예를 들어 주시겠습니까? – theBorneo

답변

2

Data Storage에 아주 좋은 가이드가있다. 나는 당신이 찾고있는 대답을 찾을 수 있다고 생각합니다.

0

안드로이드에서 우리는 일반적으로 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

+0

아이디어를 주셔서 감사합니다. 누구에게 필요한 기술이 무엇인지 말해 주시겠습니까? 예를 들어 SQLite와 데이터베이스 저장소를 분리하고 GPS API 및 Camera API (아마도)를 배우고 Java에서 프로그램을 구현하는 별을 식별하는 모바일 앱을 개발하고 싶습니다. 내가 알고 있어야 할 다른 기술이나 기술? 아무도 나에게 몇 가지 아이디어를 주실 수 있습니까 - 무엇을 시작해야합니까? – theBorneo

+0

내가 정말로 생각할 수있는 유일한 다른 점은 이미지 비교를 통해 별자리를 식별하는 방법을 알아내는 것이 좋습니다. – Samuel

+0

Samuel에게 감사 드려요. 그러나 어떻게 데이터베이스를 안드로이드와 연결시킬 수 있습니까? 데이터베이스에 대한 테이블을 만들어야한다는 것을 알고 있지만 어떻게 시작 해야할지 모르겠습니다. 나 좀 도와 줄 수있어? – theBorneo

관련 문제