Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

Copy sqlite database from apk package to device folder Android example


AD MOB

Put your sglite database to Android Eclipse project folder named Assets.
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();
}



397LW NO topic_id




AD

Další témata ....(Topics)


255

Not request focus EditText if startup Android | not-request-focus-edittext-if-startup-android


Not request focus EditText if startup Android - hide keyboard if startup.

Remove: from EditText

Create a LinearLayout and set the:
attributes android:focusable="true" android:focusableInTouchMode="true"


   <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:focusable="true" 
        android:focusableInTouchMode="true"
        android:orientation="vertical" >
</LinearLayout>
90

Map TreeMap get values to array Java Android example | map-treemap-get-values-to-array-java-android-example



import java.util.Map;
import java.util.TreeMap;

public class MainClass {
	public static void main(String[] arg) {

		// english;germany dictionary
		String[] arrayOfString = { "one;eine", "two;zwei", "two sets of;zwei"
				, "three;drei", "four;vier" };

		Map<String, String> map = new TreeMap<String, String>();

		for (String s : arrayOfString) {
			String[] array = s.split(";");
			String sKey = "", sValue = "";
			if (array.length > 1) {
				sKey = array[0];
				sValue = array[1];
				map.put(sKey, sValue);
			}
		}
    Object[] objectArrayOfValues = map.values().toArray();
	for (int i = 0; i < objectArrayOfValues.length; i++) {
		System.out.println(objectArrayOfValues[i]);
	}
		 
		
	}// end main

}
/*
vier
eine
drei
zwei
zwei
 */
150

drawBitmap, clipPath, UNION, DIFFERENCE, INTERSECT, REPLACE, XOR Android example | drawbitmap-clippath-union-difference-intersect-replace-xor-android-example



public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new SampleView(this));
	}

	private static class SampleView extends View {

		// CONSTRUCTOR
		public SampleView(Context context) {
			super(context);
			setFocusable(true);

		}

		@Override
		protected void onDraw(Canvas canvas) {
			Paint paint = new Paint();

			canvas.drawColor(Color.YELLOW);

			 Bitmap b = Bitmap.createBitmap(200, 200,
			 Bitmap.Config.ARGB_8888);

			// you need to insert a image flower_blue into res/drawable folder

			paint.setFilterBitmap(true);
			Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
					R.drawable.flower_blue);
			canvas.drawBitmap(bitmapOrg, 10, 10, paint);
			int width, height;

		    Canvas c = new Canvas(b);
		    paint.setAlpha(255); //0x80
		    c.translate(0, 30);
		    c.drawBitmap(bitmapOrg, new Matrix(), paint);
		    paint.setColor(Color.BLUE);
        Path mPath = new Path();
		    mPath.addCircle(50, 50, 50, Path.Direction.CCW);
            //c.clipPath(mPath, Region.Op.UNION);
            //c.clipPath(mPath, Region.Op.DIFFERENCE);
            c.clipPath(mPath, Region.Op.INTERSECT);
            //c.clipPath(mPath, Region.Op.REPLACE);
            //c.clipPath(mPath, Region.Op.XOR);
           paint.setColor(Color.GREEN);
           paint.setAntiAlias(true);
           c.drawCircle(30, 20, 30, paint);

		    int h = bitmapOrg.getHeight();
			//canvas.drawBitmap(bitmapOrg, 10, 10, paint);
			canvas.drawBitmap(b, 0, 10 + h + 10, paint);

		}

	}
}



bitmap xor android


regions
152

Copy save Bitmap Image Pictures Android example | save-bitmap-image-android-example


Copy file to another

        File path = Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_PICTURES);
        File file = new File(path, "MyPicture.jpg");
           // the Pictures directory exists? 
            path.mkdirs();
            InputStream is = getResources().openRawResource(R.drawable.flower_blue);
            OutputStream os = new FileOutputStream(file);
            byte[] data = new byte[is.available()];
            is.read(data);
            os.write(data);
            is.close();
            os.close();


Copy and compress file

Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
					R.drawable.flower_blue);

try {
	 FileOutputStream out = new FileOutputStream("new_bitmap.jpg");
		bitmapOrg.compress(Bitmap.CompressFormat.JPEG, 90, out);
} catch (Exception e) {
	e.printStackTrace();
	Log.e("saveBitmap", e.getMessage());
} 
159

Array copy to Array Java Android example | array-copy-to-array-java-android-example



    String[] source = {"Hello","world","by","Android"};
    
    String[] destination = new String[source.length];
   
    System.arraycopy(source, 0, destination, 0, source.length);



Editace: 2011-09-15 08:37:18
Počet článků v kategorii: 397
Url:copy-sqlite-database-from-apk-to-device-folder-android-example

AD
11 Share
Share
Tweet