Copy sqlite database from apk package to device folder Android example
Put your sglite database to Android Eclipse project folder named Assets.
On device will copy database file to application folder as this example:
On device will copy database file to application folder as this example:
public void createDatabase(Context myContext) throws IOException {
String sPackName = myContext.getPackageName();
InputStream assetsDB = myContext.getAssets().open("myDatabase");
OutputStream dbOut = new FileOutputStream("/data/data/"+sPackName+"/database");
byte[] buffer = new byte[1024];
int length;
while ((length = assetsDB.read(buffer))>0){
dbOut.write(buffer, 0, length);
}
dbOut.flush();
dbOut.close();
assetsDB.close();
}
396LW NO topic_id
AD
Další témata ....(Topics)
1.) Try reopen the Emulaor and restart Eclipse.
OR
2.) Try to delete AVD from Eclipse menu Window - AVD manager.
OR
3.) Insert into manifest.xml this source code.
OR
2.) Try to delete AVD from Eclipse menu Window - AVD manager.
OR
3.) Insert into manifest.xml this source code.
<manifest xmlns:android="//schemas.android.com/apk/res/android"
package="com.myweb.mypackage"
android:installLocation="preferExternal"
Video tutorial
How to add or remove widgets home screen Android 4.
How to add or remove widgets home screen Android 4.
Calendar dateOfYourBirth = new GregorianCalendar(1998, Calendar.SEPTEMBER, 17); Calendar today = Calendar.getInstance(); Android example.
public class HoriziontalScrollActivity extends Activity {
TextView txtV;
Context cntx;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txtV = (TextView)findViewById(R.id.idLabel);
cntx = this;
StringBuilder strBuild = new StringBuilder();
// enter your date of birth
Calendar dateOfYourBirth = new GregorianCalendar(1998, Calendar.SEPTEMBER, 17);
Calendar today = Calendar.getInstance();
int yourAge = today.get(Calendar.YEAR) - dateOfYourBirth.get(Calendar.YEAR);
dateOfYourBirth.add(Calendar.YEAR, yourAge);
if (today.before(dateOfYourBirth)) {
yourAge--;
}
strBuild.append("You are " + yourAge + " old!");
txtV.setText(strBuild);
}
}
Eclipse update ADT 17 Android Emulator error: E/AndroidRuntime(370): java.lang.NoClassDefFoundError: com.google.ads.AdView
Solution:
-right click on the project in project tree and select Project properties
-select Java Build Path
-select TAB Order and Export
-check GoogleAdMobAdsSdk-4.0.4.jar (or your version SDK)
-press OK
-clean project by menu Project -> Clean
-rebuild project (Project - Build Automatically)
How add GoogleAdMobAdsSdk....jar to project:
-right click on the project in project tree and select Project properties
-select Java Build Path
-select TAB Libraries
-press the button Add External JARs...
-select your version GoogleAdMobAdsSdkXXX.jar what you can using
-OK
-OK
-clean project
-rebuild project
Solution:
-right click on the project in project tree and select Project properties
-select Java Build Path
-select TAB Order and Export
-check GoogleAdMobAdsSdk-4.0.4.jar (or your version SDK)
-press OK
-clean project by menu Project -> Clean
-rebuild project (Project - Build Automatically)
How add GoogleAdMobAdsSdk....jar to project:
-right click on the project in project tree and select Project properties
-select Java Build Path
-select TAB Libraries
-press the button Add External JARs...
-select your version GoogleAdMobAdsSdkXXX.jar what you can using
-OK
-OK
-clean project
-rebuild project
Old code with HashMap
Lint warning:
Use new SparseArray(...) instead for better performance
Issue: Looks for opportunities to replace HashMaps with the more efficient SparseArray
Id: UseSparseArrays
New code with SparseArray
SparseArray methods:
//developer.android.com/reference/android/util/SparseArray.html
Map<Integer, Bitmap> _bitmapCache = new HashMap<Integer, Bitmap>();
private void fillBitmapCache() {
_bitmapCache.put(R.drawable.icon, BitmapFactory.decodeResource(getResources(), R.drawable.icon));
_bitmapCache.put(R.drawable.abstrakt, BitmapFactory.decodeResource(getResources(), R.drawable.abstrakt));
_bitmapCache.put(R.drawable.wallpaper, BitmapFactory.decodeResource(getResources(), R.drawable.wallpaper));
_bitmapCache.put(R.drawable.scissors, BitmapFactory.decodeResource(getResources(),
}
Bitmap bm = _bitmapCache.get(R.drawable.icon);
Lint warning:
Use new SparseArray
Issue: Looks for opportunities to replace HashMaps with the more efficient SparseArray
Id: UseSparseArrays
New code with SparseArray
SparseArray<Bitmap> _bitmapCache = new SparseArray<Bitmap>();
private void fillBitmapCache() {
_bitmapCache.put(R.drawable.icon, BitmapFactory.decodeResource(getResources(), R.drawable.icon));
_bitmapCache.put(R.drawable.abstrakt, BitmapFactory.decodeResource(getResources(), R.drawable.abstrakt));
_bitmapCache.put(R.drawable.wallpaper, BitmapFactory.decodeResource(getResources(), R.drawable.wallpaper));
_bitmapCache.put(R.drawable.scissors, BitmapFactory.decodeResource(getResources(),
}
Bitmap bm = _bitmapCache.get(R.drawable.icon);
SparseArray methods:
//developer.android.com/reference/android/util/SparseArray.html
Editace: 2011-09-15 08:37:18
Počet článků v kategorii: 396
Url:copy-sqlite-database-from-apk-to-device-folder-android-example