Note that there are some explanatory texts on larger screens.

plurals
  1. PONot able to read the saved image from SQLite database
    text
    copied!<p>I have included 'share via' option in my android app. Very first time when I add a photo by share via option its added to my table and viewed successfully. But next time when I add it shows 'image saved' but couldn't see using show function(Previously added photos showed correctly). I don't know what causes the problem whether error is in sharing code or database viewing code. I have attached the code snippets.</p> <p>Share.java</p> <pre><code> String myPath = DB_PATH + DATABASE_NAME; //*receive image from 'share via' option // Get the intent that started this activity Intent intent = getIntent(); Uri data = intent.getData(); // Figure out what to do based on the intent type if (intent.getType().indexOf("image/") != -1) { // Handle intents with image data ... try { Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); mBitmap =MediaStore.Images.Media.getBitmap(this.getContentResolver(),imageUri); // bimatp factory BitmapFactory.Options options = new BitmapFactory.Options(); // downsizing image as it throws OutOfMemory Exception for larger // images options.inSampleSize = 2; ByteArrayOutputStream bos=new ByteArrayOutputStream(); mBitmap.compress(Bitmap.CompressFormat.PNG, 100, bos); img =bos.toByteArray(); if(img!=null){ //open database in read and write mode checkDB = SQLiteDatabase.openDatabase(myPath, null,SQLiteDatabase.OPEN_READWRITE); if(checkDB!=null){ ContentValues contentValues = new ContentValues(); contentValues.put("myid", strEmailId); contentValues.put("image", img); database.insert("Images", null,contentValues); displayToast("Image saved"); }else displayToast("check is null"); }else displayToast("img is null"); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } </code></pre> <p>ShowPhotos.java</p> <pre><code>//adapter for gallery view ImageAdapter images = new ImageAdapter(this); final GridView gridView = (GridView) findViewById(R.id.gridview); //get the large image view int i=0; Cursor cursor = null; try { System.out.println("===================addImageToGallery==========================="); db = SQLiteDatabase.openDatabase(myPath, null,SQLiteDatabase.OPEN_READONLY); cursor = db.rawQuery("SELECT _id, image FROM images WHERE myid='"+id+"'", null); if (cursor != null ) { strImageID = new String[cursor.getCount()]; strImagePath = new String[cursor.getCount()]; if (cursor.moveToFirst()) { do{ strImageID[i] = cursor.getString(cursor.getColumnIndex("_id")); byte[] data = cursor.getBlob(cursor.getColumnIndex("image")); //Bitmap thumbnail = BitmapFactory.decodeByteArray(data, 0, data.length); //images.AddImage(thumbnail); images.AddImage(ShrinkBitmap(data, getWindowManager().getDefaultDisplay().getWidth(), getWindowManager().getDefaultDisplay().getHeight())); gridView.setAdapter(images); i++; }while(cursor.moveToNext()); } } } catch (Exception e){ System.out.println("addImageToGallery() : "+e.toString()); }finally{ if(cursor != null)cursor.close(); } </code></pre> <p>Please help me to find out the bug..</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload