有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Android按顺序从Gallery接收图像

我目前有一个安卓应用程序,它有一个意向过滤器,可以从画廊接收图像。重要的是,图像的接收顺序与用户选择图像的顺序相同。这似乎是大多数设备的默认行为,但在一些设备上(到目前为止,我在摩托罗拉运行的安卓4.x上看到过这种情况),顺序似乎没有定义。有人知道一种方法来声明图像应该按顺序接收吗?还是一种在收到图像后确定所选顺序的方法

以下是清单中的相关代码

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

来自重要的活动

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

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

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

    return uriList;
}

编辑

让我来解释一下应用程序的一般流程。 用户打开图库并选择图像。他们选择与我的应用程序“共享”它们。我的应用程序接收一个Uri列表,然后使用一个由自定义适配器类支持的内部库来显示。图像根据Uri列表正确显示,问题在于列表的顺序<;Uri>;有时是不正确的。对我的用户来说,图片的显示顺序与他们选择的顺序相同,这一点很重要

澄清 当我使用术语Gallery时,我指的是内置的Android应用程序库。 当我使用“共享”这个词时,我指的是Gallery应用程序中的“共享”按钮。这允许用户从Facebook、电子邮件以及我的应用程序等服务列表中进行选择

比如 想象一下,一个画廊有3张图片,按任意顺序显示:a、B和C。用户先选择C,然后选择a,然后选择B,并选择与我的应用程序共享它们。在大多数手机上,我的列表将正确排序{C,A,B},在有问题的手机上,这个顺序似乎是随机的

我不能使用创建时间戳,因为创建时间通常与选择顺序无关。添加自定义元数据也没有帮助,因为我不知道正确的初始顺序


共 (1) 个答案

  1. # 1 楼答案

    是的,我现在也面临同样的问题。我还使用了Fedor的延迟加载概念。我不确定这会有多大帮助,也不确定这是否是正确的方法。但它还是解决了我的问题

    我必须在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;
    }