Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6709465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:53:07+00:00 2026-05-26T07:53:07+00:00

void launchImageCapture(Activity context) { Uri imageFileUri = context.getContentResolver() .insert(Media.INTERNAL_CONTENT_URI, new ContentValues()); m_queue.add(imageFileUri); Intent i

  • 0
void launchImageCapture(Activity context) {
    Uri imageFileUri = context.getContentResolver()
        .insert(Media.INTERNAL_CONTENT_URI, new ContentValues());
    m_queue.add(imageFileUri);
    Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

    i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri); 
    context.startActivityForResult(i, ImportActivity.CAMERA_REQUEST); 
}

The above code, which has always worked, is now generating this exception for me at insert().

java.lang.UnsupportedOperationException: Writing to internal storage is not supported.
     at com.android.providers.media.MediaProvider.generateFileName(MediaProvider.java:2336)
     at com.android.providers.media.MediaProvider.ensureFile(MediaProvider.java:1851)
     at com.android.providers.media.MediaProvider.insertInternal(MediaProvider.java:2006)
     at com.android.providers.media.MediaProvider.insert(MediaProvider.java:1974)
     at android.content.ContentProvider$Transport.insert(ContentProvider.java:150)
     at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:140)
     at android.os.Binder.execTransact(Binder.java:287)
     at dalvik.system.NativeStart.run(Native Method)

It is not a space issue, and the only thing I changed was the package of an unrelated class all together. Also, I restarted my phone.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:53:07+00:00Added an answer on May 26, 2026 at 7:53 am

    Facing same problem here, I was happy to find this thread. Even though two things were bugging me in this workaround, this post had me looking in the right direction. I’d like to share my own workaround/solution.

    Let me begin by stating what I did not see myself living with.

    First, I did not want to leave the application private file as MODE_WORLD_WRITEABLE. This looks like non-sense to me, although I cannot figure exactly how another application could access this file unless knowing where to look for it with complete name and path. I’m not saying it is necessarily bad for your scenario, but it is still bugging me somehow. I would prefer to cover all my bases by having picture files really private to my app. In my business case, pictures are of no use outside of the application and by no means should they be deleteable via, say, the Android Gallery. My app will trigger cleanup at an appropriate time so as to not vampirize Droid device storage space.

    Second, openFileOutput() do not leave any option but to save the resulting file in the root of getFilesDir(). What if I need some directory structure to keep things in order? In addition, my application must handle more than one picture, so I would like to have the filename generated so I can refer to it later on.

    See, it is easy to capture a photo with the camera and save it to public image area (via MediaStore) on the Droid device. It is also easy to manipulate (query, update, delete) media from MediaStore. Interestingly, inserting camera picture to MediaStore genreates a filename which appears to be unique. It is also easy to create private File for an application with a directory structure. The crux of the “Capturea camera picture and save it to internal memory” problem is that you can’t do so directly because Android prevents ContentResolver to use Media.INTERNAL_CONTENT_URI, and because private app files are by definition not accessible via the (outside) Camera activity.

    Finally I adopted the following strategy:

    1. Start the Camera activity for result from my app with the Intent to capture image.
    2. When returning to my app, insert capture to the MediaStore.
    3. Query the MediaStore to obtain generated image file name.
    4. Create a truly internal file onto whatever path relative to private application data folder using Context.getDir().
    5. Use an OutputStream to write Bitmap data to this private file.
    6. Delete capture from MediaStore.
    7. (Optional) show an ImageView of the capture in my app.

    Here is the code starting the cam:

    public void onClick (View v)
    {
        ContentValues values = new ContentValues ();
    
        values.put (Media.IS_PRIVATE, 1);
        values.put (Media.TITLE, "Xenios Mobile Private Image");
        values.put (Media.DESCRIPTION, "Classification Picture taken via Xenios Mobile.");
    
        Uri picUri = getActivity ().getContentResolver ().insert (Media.EXTERNAL_CONTENT_URI, values);
    
        //Keep a reference in app for now, we might need it later.
        ((XeniosMob) getActivity ().getApplication ()).setCamPicUri (picUri);
    
        Intent takePicture = new Intent (MediaStore.ACTION_IMAGE_CAPTURE);
    
        //May or may not be populated depending on devices.
        takePicture.putExtra (MediaStore.EXTRA_OUTPUT, picUri);
    
        getActivity ().startActivityForResult (takePicture, R.id.action_camera_start);
    }
    

    And here is my activity getting cam result:

    @Override
    protected void onActivityResult (int requestCode, int resultCode, Intent data)
    {
        super.onActivityResult (requestCode, resultCode, data);
        if (requestCode == R.id.action_camera_start)
        {
            if (resultCode == RESULT_OK)
            {
                Bitmap pic = null;
                Uri picUri = null;
    
                //Some Droid devices (as mine: Acer 500 tablet) leave data Intent null.
                if (data == null) {
                    picUri = ((XeniosMob) getApplication ()).getCamPicUri ();
                } else
                {
                    Bundle extras = data.getExtras ();
                    picUri = (Uri) extras.get (MediaStore.EXTRA_OUTPUT);
                }
    
                try
                {
                    pic = Media.getBitmap (getContentResolver (), picUri);
                } catch (FileNotFoundException ex)
                {
                    Logger.getLogger (getClass ().getName ()).log (Level.SEVERE, null, ex);
                } catch (IOException ex)
                {
                    Logger.getLogger (getClass ().getName ()).log (Level.SEVERE, null, ex);
                }
    
                //Getting (creating it if necessary) a private directory named app_Pictures
                //Using MODE_PRIVATE seems to prefix the directory name provided with "app_".
                File dir = getDir (Environment.DIRECTORY_PICTURES, Context.MODE_PRIVATE);
    
                //Query the MediaStore to retrieve generated filename for the capture.
                Cursor query = getContentResolver ().query (
                            picUri,
                            new String [] {
                                Media.DISPLAY_NAME,
                                Media.TITLE
                            },
                            null, null, null
                        );
                boolean gotOne = query.moveToFirst ();
                File internalFile = null;
                if (gotOne)
                {
                    String dn = query.getString (query.getColumnIndexOrThrow (Media.DISPLAY_NAME));
                    String title = query.getString (query.getColumnIndexOrThrow (Media.TITLE));
                    query.close ();
    
                    //Generated name is a ".jpg" on my device (tablet Acer 500).
                    //I prefer to work with ".png".
                    internalFile = new File (dir, dn.subSequence (0, dn.lastIndexOf (".")).toString () + ".png");
                    internalFile.setReadable (true);
                    internalFile.setWritable (true);
                    internalFile.setExecutable (true);
                    try
                    {
                        internalFile.createNewFile ();
    
                        //Use an output stream to write picture data to internal file.
                        FileOutputStream fos = new FileOutputStream (internalFile);
                        BufferedOutputStream bos = new BufferedOutputStream (fos);
    
                        //Use lossless compression.
                        pic.compress (Bitmap.CompressFormat.PNG, 100, bos);
    
                        bos.flush ();
                        bos.close ();
                    } catch (FileNotFoundException ex)
                    {
                        Logger.getLogger (EvaluationActivity.class.getName()).log (Level.SEVERE, null, ex);
                    } catch (IOException ex)
                    {
                        Logger.getLogger (EvaluationActivity.class.getName()).log (Level.SEVERE, null, ex);
                    }
                }
    
                //Update picture Uri to that of internal file.
                ((XeniosMob) getApplication ()).setCamPicUri (Uri.fromFile (internalFile));
    
                //Don't keep capture in public storage space (no Android Gallery use)
                int delete = getContentResolver ().delete (picUri, null, null);
    
                //rather just keep Uri references here
                //visit.add (pic);
    
                //Show the picture in app!
                ViewGroup photoLayout = (ViewGroup) findViewById (R.id.layout_photo_area);
                ImageView iv = new ImageView (photoLayout.getContext ());
                iv.setImageBitmap (pic);
                photoLayout.addView (iv, 120, 120);
            }
            else if (resultCode == RESULT_CANCELED)
            {
                Toast toast = Toast.makeText (this, "Picture capture has been cancelled.", Toast.LENGTH_LONG);
                toast.show ();
            }
        }
    }
    

    Voila! Now we have a truly application private picture file, which name has been generated by the Droid device. And nothing is kept in the public storage area, thus preventing accidental picture manipulation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

- (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSelectFont(context, Arial, 24, kCGEncodingMacRoman); CGContextShowTextAtPoint(context, 80, 80,
void GenerateSurvey(string AnketId, System.Web.UI.WebControls.PlaceHolder plch) { var db = new Xrm.XrmDataContext(Microsoft.Xrm.Client.CrmConnection.Parse(Utils.getXrmConnectionString(_PortalBrandHelper.BrandProxy.BrandDedicatedCrmOrgName))); var AnketSoru =
void getThisAlert(String Title, Displayable txtagency2) { Alert error = new Alert(, Title, null, AlertType.INFO);
-(void)insertEvent:(stRs232Timer*)pEvent { BOOL bFound = NO; NSLog(@insertEvent); pEvent->uExpirationTime = pEvent->uPeriod-45; // Insert the item
-(void)add { Myview *optionV =[[Myview alloc] initWithFrame:CGRectMake(80,80, 590, 25)]; [interactiveView addSubview:optionV]; //interactiveView is UIView
void (int a[]) { a[5] = 3; // this is wrong? } Can I
void addNewNode (struct node *head, int n) { struct node* temp = (struct node*)
void some_func(int param = get_default_param_value());
void foo(void **Pointer); int main () { int *IntPtr; foo(&((void*)IntPtr)); } Why do I
void FileManager::CloseFile(File * const file) { for (int i = 0; i < MAX_OPEN_FILES;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.