Wednesday, October 2, 2013

[android-developers] Copy Image from Users Gallery to folder on SDCard

Let me start off by saying I am new to programming.  I am trying to create a Private Gallery and I have searched the web and gotten bits and pieces together to create this app

I have the basic gallery down and it displays the images that I have in my private folder in a grid and I can pick an image to enlarge it with pinch to zoom in and out and all those good things.

I also my application showing in the Share Menu...

<activity android:name="com.company.privategallery.SendToPrivateGallery" 
   android:exported="false">
   <intent-filter>
       <action android:name="android.intent.action.SEND" />
       <category android:name="android.intent.category.DEFAULT" />
       <data android:mimeType="image/*" />
   </intent-filter>
</activity>


What I want to do now is...  When the users starts their normal gallery and selects an image (or video) and then selects the SHARE Option, they Pick my App.  I want it to Copy the file to my Private Location "/DCIM/privgal/.nomedia/" and then delete the file from their Normal Gallery.

I am using an HTC ONE at the moment for all my testing and when I select my App from the Share menu, the gallery crashes and wants to send the report to HTC.  I do not see any errors in my LogCat, its as if it never actually calls my App so I can't see what's wrong.

I know this code below is a mess and I know it's not functional as is, but as I said before I am new to this and gathered these bits and pieces together and was hoping to get it working with the errors that the log cat would give me. Unfortunately it's not reporting any errors, so I am stuck.

Could someone PLEASE look at this and either point me in a direction to a working example or... I really hate to say it, fix my code?

Any help is appreciated!!!

-Steve


package com.company.privategallery;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import android.app.Activity;
import android.net.Uri;
import android.os.Environment;
import android.content.Intent;
import android.graphics.Bitmap;

public class SendToPrivateGallery extends Activity {
private static final int REQUEST_SHARE = 39714;

private File png = null;
        private static String ExternalStorageDirectoryPath = Environment.getExternalStorageDirectory().getAbsolutePath();
        private static String targetPath = ExternalStorageDirectoryPath + "/DCIM/privgal/.nomedia/";
        private static String privategallery = new String(ExternalStorageDirectoryPath + targetPath);;
    

private void startSendIntent() {
   png = new File(new File(Environment.getExternalStorageDirectory(), "Pictures"), getString(R.string.app_name));

   FileOutputStream out = null;
   try {
       out = new FileOutputStream(png);
       Bitmap bitmap = null;
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
       out.flush();
   } catch (Exception e) {
       e.printStackTrace();
   } finally {
       try {
           if (out != null) out.close();
       }
        catch (IOException ignore) {}
       }
       final Intent copyIntent = new Intent(android.content.Intent.ACTION_SEND);
        copyIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(png));
        copyIntent.setType("image/png");
       startActivityForResult(Intent.createChooser(copyIntent, getString(R.string.app_name)), REQUEST_SHARE);
   }

    private void deleteLatest() {
        // TODO Auto-generated method stub
        File f = new File(Environment.getExternalStorageDirectory() + "/DCIM/Camera" );

        //Log.i("Log", "file name in delete folder :  "+f.toString());
        File [] files = f.listFiles();

        //Log.i("Log", "List of files is: " +files.toString());
        Arrays.sort( files, new Comparator<Object>()
                {
            public int compare(Object o1, Object o2) {

                if (((File)o1).lastModified() > ((File)o2).lastModified()) {
                    //         Log.i("Log", "Going -1");
                    return -1;
                } else if (((File)o1).lastModified() < ((File)o2).lastModified()) {
                    //     Log.i("Log", "Going +1");
                    return 1;
                } else {
                    //     Log.i("Log", "Going 0");
                    return 0;
                }
            }

                });

        //Log.i("Log", "Count of the FILES AFTER DELETING ::"+files[0].length());
        files[0].delete();

    }    
}

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate