編輯:關於android開發
package com.city.list.db; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import com.city.list.main.R; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.os.Environment; /** * 將raw中得數據庫文件寫入到data數據庫中 * @author sy * */ public class DBManager { private final int BUFFER_SIZE = 400000; private static final String PACKAGE_NAME = "com.city.list.main"; public static final String DB_NAME = "china_city_name.db"; public static final String DB_PATH = "/data" + Environment.getDataDirectory().getAbsolutePath() + "/" + PACKAGE_NAME ; // 存放路徑 private Context mContext; private SQLiteDatabase database; public DBManager(Context context) { this.mContext = context; } /** * 被調用方法 */ public void openDateBase() { this.database = this.openDateBase(DB_PATH + "/" + DB_NAME); } /** * 打開數據庫 * * @param dbFile * @return SQLiteDatabase * @author sy */ private SQLiteDatabase openDateBase(String dbFile) { File file = new File(dbFile); if (!file.exists()) { // 打開raw中得數據庫文件,獲得stream流 InputStream stream = this.mContext.getResources().openRawResource(R.raw.china_city_name); try { // 將獲取到的stream 流寫入道data中 FileOutputStream outputStream = new FileOutputStream(dbFile); byte[] buffer = new byte[BUFFER_SIZE]; int count = 0; while ((count = stream.read(buffer)) > 0) { outputStream.write(buffer, 0, count); } outputStream.close(); stream.close(); SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbFile, null); return db; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } return database; } public void closeDatabase() { if (database != null && database.isOpen()) { this.database.close(); } } }
Android新手入門2016(12)--基於Layout文件的AlertDialog 上一章學習了AlertDialog,後來發現還有基於Layout文件的AlertD
百度地圖簡單的使用,百度地圖簡單使用最近寫了百度地圖的Demo,所以總結下遇到的問題; 1.使用百度地圖,先看下官方的例子。要再清單文件中配置KEY,如果用到定位要注冊s
Android基礎入門教程——10.14 Android GPS初涉 1.定位相關的一些API 1)LocationManager 官方A
Android Binder機制介紹,androidbinder機制做過Android開發的同學可能有些體會,入門初期,工作內容主要是實現各式各樣的UI界面,以及實現應用