3

I currently have an Android application that has an intent-filter to receive images from the Gallery. It is important that the images are received in the same order that the user selected them in. This seems to be the default behavior on most devices, however on some devices (so far I've seen this on Motorola's running Android 4.x) the order seems undefined. Does anyone know a way to declare in the intent that the images should be received in order? Or a way once the images are recieved to determine the selected order?

Here is relevant code from the manifest

 <activity
       android:label="@string/app_name"
       android:name=".activities.ImportImagesActivity" > 
       <intent-filter>   
           <action android:name="android.intent.action.SEND" />
           <category android:name="android.intent.category.DEFAULT" /> 
           <data android:mimeType="image/*" />
       </intent-filter>
       <intent-filter>   
           <action android:name="android.intent.action.SEND_MULTIPLE" />
           <category android:name="android.intent.category.DEFAULT" /> 
           <data android:mimeType="image/*" />
       </intent-filter>
   </activity>

And from ImportImagesActivity

private List<Uri> parseIncomingData() {
    List<Uri> uriList = null;

    Intent intent = this.getIntent();
    if(intent != null) {
        String action = intent.getAction();
        //Single Image
        if (action.equalsIgnoreCase("android.intent.action.SEND")) {
            //removed for brevity
            }
        }
        //Multiple Images
        else if (action.equalsIgnoreCase("android.intent.action.SEND_MULTIPLE")) {
            uriList  = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        }
    }

    //more code - at this point images have been recieved

    return uriList;
}

EDIT

To give a little context, let me explain the general flow of the app. The user opens the Gallery and selects images. They choose to 'Share' them with my app. My application receives a list of Uri's which are then displayed using an internal gallery backed by a custom Adapter class. The images display correctly based on the Uri list, the issue is the order of the List<Uri> is sometimes incorrect. It is important to my users that the images appear in the same order they select them in.

Clarification When I use the term Gallery I am referring to the built in Android app Gallery. When I use the term 'Share' I am referring to the the Share button within the Gallery app. This allows the user to select from a list of services such as Facebook, Email, and in this case my app.

For Example imagine a Gallery with 3 images, displayed in an arbitrary order: A, B, and C. The user selects first C then A then B and chooses to share them with my app. On most phones my list will be correctly ordered {C, A, B}, on offending phones this order seems random.

I cannot use the creation timestamp because the creation time is generally irrelevant to the selection order. Adding custom meta data doesn't help either because I don't know the correct initial order.

Mike
  • 2,399
  • 1
  • 20
  • 26

2 Answers2

1

My observation is that Android gallery displays images in accordance to their recency.

For the devices where you're unable to determine the order, you can import the images from the gallery and check their creation time. Here's a way to do that. Or you could use a metadata extractor app, many jars can be found.

Now, you could just arrange the images in the order of recency and you should be done.

[EDIT]

I have a question. You said they may be selected in any order, so are they "uploading" it onto a server by "sharing"?

If so, then one way is to check which image was uploaded or if you want the order of selection, you could do this. Edit the metadata of the images, there's bound to be a useless tag, select one and edit it on touch. So, if I select image A it changes to 1 and then I select image B it becomes 2. But if I unselect image A now then image B should become 1. So, you could use nodes here. This is the first in first out (FIFO) method. Upon un-selection, A is thrown out of the list and B replaces it.

Is this what you wanted?

EDIT Sorry, I don't think you can do this without creating your own gallery. Why don't you just import the android gallery into a grid view in your app?

Community
  • 1
  • 1
Karthik Balakrishnan
  • 4,353
  • 6
  • 37
  • 69
  • Just to make sure I understand you correctly, by order of recency, you mean by creation time? This doesn't work in my situation. My users may select the images from the Gallery in ANY order and when they are shared with my app they should be shown in that same order. – Mike Jan 14 '13 at 13:17
  • Please see my updated question, I added some context and clarification to help you better understand the issue. The 'sharing' is not done in my app, but in the Gallery app, so I have no control while the user is selecting images. The user then decides to 'Share' them with my app which results in me receiving a list of Uris..but at this point they are out of order. – Mike Jan 17 '13 at 14:25
  • The more I look into this I'm beginning to agree with you, I don't think it's possible. I'm going to mark you for the accepted answer but if anyone can come up with a solution I'm happy to change this. – Mike Jan 21 '13 at 13:33
1

Yeah, I just faced the same problem right now. I am also using Fedor's lazy loading concept.I am not sure how far this will be helpful and whether this is the right approach. But still it solved the problem for me.

I had to do a little modification in the getView(),

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    System.gc();

    ImageView view;

    if(convertView == null) {

        view = new ImageView(context);

        view.setScaleType(ImageView.ScaleType.FIT_CENTER);
        view.setLayoutParams(new GridView.LayoutParams(screenWidth/4, screenHeight/4));
        view.setAdjustViewBounds(false);
        view.setPadding(2, 2, 2, 2);



        System.gc();

    }else {
        view = (ImageView) convertView;
    }
      if(view!=null)
        {
               imageLoader.DisplayImage(urlList.get(position), view);
               notifyDataSetChanged();  //Calling this helped to solve the problem. 
        }

    System.gc();

    return view;
}
GOLDEE
  • 2,318
  • 3
  • 25
  • 49
  • Thanks for the suggestion. I'm already calling notifyDataSetChanged(). The images are displaying correctly the issue is my backing data source (the uri list) is out of order. Just out of curiosity, what is the Fedor lazy loading concept? – Mike Jan 17 '13 at 14:43
  • Lazy loading, also known as dynamic function loading , is a mode that allows a developer to specify what components of a program should not be loaded into storage by default when a program is started. Ordinarily, the system loader automatically loads the initial program and all of its dependent components at the same time. In lazy loading, dependents are only loaded as they are specifically requested. Lazy loading can be used to improve the performance of a program if most of the dependent components are never actually used. – GOLDEE Jan 18 '13 at 03:49