2012-03-08 3 views
1

이미지 및 확인란과 연관된 기본보기와 이메일 보내기 버튼이 있습니다. 체크 박스를 클릭하고 이메일 보내기 버튼을 선택하면 선택한 이미지가 첨부되어야하는 이메일 페이지로 리디렉션되어야합니다. 여기 내 코드가있다. choiceMode = "선다형 문제를"을 참조하십시오 당신의 XML & 목록 안드로이드에이 속성첨부 파일이 여러 개 있지만 선택한 이미지 만 있습니다.

public class GridcheckboxActivity extends Activity { 
    GridView mygrid; 
    String[] imagepaths; 
    Uri[] myUris; 
    boolean[] ticking; 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     mygrid=(GridView)findViewById(R.id.gridView1); 
     String folderpath=Environment.getExternalStorageDirectory().getAbsolutePath()+"/New Folder/"; 
     File myfile=new File(folderpath); 
     File[] imageslist=myfile.listFiles(new FilenameFilter() { 

      @Override 
      public boolean accept(File dir, String filename) { 
       // TODO Auto-generated method stub 
       return (filename.toLowerCase().endsWith("jpg")||filename.toLowerCase().endsWith("png")||filename.toLowerCase().endsWith("jpeg")); 
      } 
     }); 
     int imgCount=imageslist.length; 
     imagepaths=new String[imgCount]; 
     for(int i=0;i<imgCount;i++){ 
      imagepaths[i]=imageslist[i].getAbsolutePath(); 
      System.out.println("my image's paths are::::::::"+imagepaths[i]); 
     } 
     this.ticking=new boolean[imgCount]; 
     ImageAdapter imgad=new ImageAdapter(); 
     mygrid.setAdapter(imgad); 
     Button select=(Button)findViewById(R.id.button1); 
     select.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       final int len = ticking.length; 
       int cnt = 0; 
       String selectImages = ""; 
       ArrayList<String> myarray=new ArrayList<String>(); 

       for (int i =0; i<len; i++) 
       { 
        if (ticking[i]){ 
        cnt++; 
        selectImages = selectImages + imagepaths[i] + "|"; 
        myarray.add(imagepaths[i]); 
        } 
       } 
       Log.d("myarray","myarray size==="+myarray.size()); 
       if (cnt == 0){ 
        Toast.makeText(getApplicationContext(),"Please select at least one image",Toast.LENGTH_LONG).show(); 
          } 
       else { 
         Toast.makeText(getApplicationContext(), "You've selected Total " + cnt + " image(s).",Toast.LENGTH_LONG).show(); 
         Log.d("SelectedImages", selectImages); 

       try{ 
         Intent emailintent=new Intent(android.content.Intent.ACTION_SEND_MULTIPLE); 
         emailintent.setType("application/octet-stream"); 

         String[] addressvalue=new String[]{"[email protected]"}; 
         emailintent.putExtra(android.content.Intent.EXTRA_EMAIL, addressvalue); 
         emailintent.putExtra(android.content.Intent.EXTRA_SUBJECT, "subjectvalue"); 
         String bccvalue[]={"bcc address"}; 
         emailintent.putExtra(android.content.Intent.EXTRA_BCC, bccvalue); 
         String ccvalue[]={"cc address"}; 
         emailintent.putExtra(android.content.Intent.EXTRA_CC,ccvalue); 
         ArrayList<Uri> newone=new ArrayList<Uri>(); 
         for(int j=0;j<myarray.size();j++){ 
         Uri u=Uri.parse("file:/"+myarray.get(j)); 
         Log.d("uris", "myuris are:::::::"+u); 
         newone.add(u); 
         } 
         System.out.println("my uri array has values------->"+newone); 
         emailintent.putExtra(android.content.Intent.EXTRA_STREAM, newone); 

         GridcheckboxActivity.this.startActivity(Intent.createChooser(emailintent, "sending email using:")); 
        }catch(Exception e){ 
         e.printStackTrace(); 
         Log.d("error", "cannot start activity"); 
        } 
       } 
      } 
     }); 
    } 

답변

0

내가 많이 노력하고

public class GridcheckboxActivity extends Activity { 
    GridView mygrid; 
    String[] imagepaths; 
    Uri[] myUris; 
    boolean[] ticking; 
    ArrayList<String> myarray=new ArrayList<String>(); 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     mygrid=(GridView)findViewById(R.id.gridView1); 
     String folderpath=Environment.getExternalStorageDirectory().getAbsolutePath()+"/New Folder/"; 
     File myfile=new File(folderpath); 
     File[] imageslist=myfile.listFiles(new FilenameFilter() { 

      @Override 
      public boolean accept(File dir, String filename) { 
       // TODO Auto-generated method stub 
       return (filename.toLowerCase().endsWith("jpg")||filename.toLowerCase().endsWith("png")||filename.toLowerCase().endsWith("jpeg")); 
      } 
     }); 
     int imgCount=imageslist.length; 
     imagepaths=new String[imgCount]; 
     for(int i=0;i<imgCount;i++){ 
      imagepaths[i]=imageslist[i].getAbsolutePath(); 
      System.out.println("my image's paths are::::::::"+imagepaths[i]); 
     } 
     this.ticking=new boolean[imgCount]; 
     ImageAdapter imgad=new ImageAdapter(); 
     mygrid.setAdapter(imgad); 
     Button select=(Button)findViewById(R.id.button1); 
     select.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       final int len = ticking.length; 
       int cnt = 0; 
       String selectImages = ""; 


       for (int i =0; i<len; i++) 
       { 
        if (ticking[i]){ 
        cnt++; 
        selectImages = selectImages + imagepaths[i] + "|"; 
        myarray.add(imagepaths[i]); 
        } 
       } 
       Log.d("myarray","myarray size==="+myarray.size()); 
       if (cnt == 0){ 
        Toast.makeText(getApplicationContext(),"Please select at least one image",Toast.LENGTH_LONG).show(); 
          } 
       else { 
         Toast.makeText(getApplicationContext(), "You've selected Total " + cnt + " image(s).",Toast.LENGTH_LONG).show(); 
         Log.d("SelectedImages", selectImages); 

       try{ 
         Intent emailintent=new Intent(android.content.Intent.ACTION_SEND_MULTIPLE); 
         emailintent.setType("application/octet-stream"); 
         String[] addressvalue=new String[]{"[email protected]"}; 
         emailintent.putExtra(android.content.Intent.EXTRA_EMAIL, addressvalue); 
         emailintent.putExtra(android.content.Intent.EXTRA_SUBJECT, "subjectvalue"); 
         String bccvalue[]={"bcc address"}; 
         emailintent.putExtra(android.content.Intent.EXTRA_BCC, bccvalue); 
         String ccvalue[]={"cc address"}; 
         emailintent.putExtra(android.content.Intent.EXTRA_CC,ccvalue); 
         ArrayList<Uri> axn=getUriListForImages(); 
         emailintent.putExtra(android.content.Intent.EXTRA_STREAM, axn); 

         GridcheckboxActivity.this.startActivity(Intent.createChooser(emailintent, "sending email using:")); 
        } 
       catch(Exception e){ 
         e.printStackTrace(); 
         Log.d("error", "cannot start activity"); 
        } 
       } 
      } 



     }); 
    } 
private ArrayList<Uri> getUriListForImages() throws Exception { 
    ArrayList<Uri> myList = new ArrayList<Uri>(); 
    String imageDirectoryPath = Environment.getExternalStorageDirectory().getAbsolutePath()+ "/New Folder/"; 
    if(myarray.size() != 0) { 
     for(int i=0; i<myarray.size(); i++) 
     { 
      try 
      { 
       ContentValues values = new ContentValues(7); 
       values.put(Images.Media.TITLE, myarray.get(i)); 
       values.put(Images.Media.DISPLAY_NAME, myarray.get(i)); 
       values.put(Images.Media.DATE_TAKEN, new Date().getTime()); 
       values.put(Images.Media.MIME_TYPE, "image/jpeg"); 
       values.put(Images.ImageColumns.BUCKET_ID, imageDirectoryPath.hashCode()); 
       values.put(Images.ImageColumns.BUCKET_DISPLAY_NAME, myarray.get(i)); 
       values.put("_data", myarray.get(i)); 
       ContentResolver contentResolver = getApplicationContext().getContentResolver(); 
       Uri uri = contentResolver.insert(Images.Media.EXTERNAL_CONTENT_URI, values); 
       myList.add(uri); 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
     } 
    } 
    return myList; 
} 

    public class ImageAdapter extends BaseAdapter{ 
     private LayoutInflater mInflater; 
     //Context mycontext; 
     public ImageAdapter() { 
      // TODO Auto-generated constructor stub 

      mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     } 

     @Override 
     public int getCount() { 
      // TODO Auto-generated method stub 
      return imagepaths.length; 
     } 

     @Override 
     public Object getItem(int position) { 
      // TODO Auto-generated method stub 
      return imagepaths[position]; 
     } 

     @Override 
     public long getItemId(int position) { 
      // TODO Auto-generated method stub 
      return position; 
     } 

     @Override 
     public View getView(int position, View conview, ViewGroup arg2) { 
      // TODO Auto-generated method stub 
      viewholder myholder; 
      if(conview== null){ 
       myholder=new viewholder(); 
       conview=mInflater.inflate(R.layout.inflatexml,null); 
       myholder.img=(ImageView) conview.findViewById(R.id.imageView1); 
       myholder.cbox=(CheckBox) conview.findViewById(R.id.checkBox1); 
       conview.setTag(myholder); 

      }else{ 
       myholder=(viewholder) conview.getTag(); 
      } 
      myholder.img.setId(position); 
      myholder.cbox.setId(position); 

      myholder.cbox.setOnClickListener(new OnClickListener() { 

       @Override 
       public void onClick(View v) { 
        // TODO Auto-generated method stub 
        CheckBox cb=(CheckBox)v; 
        int id=cb.getId(); 
        if(ticking[id]){ 
         cb.setChecked(false); 
         ticking[id]=false; 
        }else{ 
         cb.setChecked(true); 
         ticking[id]=true; 
        } 
       } 
      }); 
      myholder.img.setOnClickListener(new OnClickListener() { 

       @Override 
       public void onClick(View v) { 
        // TODO Auto-generated method stub 
        int id=v.getId(); 
        Intent intent = new Intent(); 
        intent.setAction(Intent.ACTION_VIEW); 
        intent.setDataAndType(Uri.parse("file:/"+imagepaths[id]), "image/*");    
        startActivity(intent); 


       } 
      }); 

      Bitmap bm=BitmapFactory.decodeFile(""+imagepaths[position]); 
      Bitmap bm1=Bitmap.createScaledBitmap(bm, 140, 200, true); 
      myholder.img.setImageBitmap(bm1); 
      myholder.cbox.setChecked(ticking[position]); 
      myholder.cbox.setGravity(Gravity.TOP); 
      myholder.id=position; 
      return conview; 
     } 


    } 
    class viewholder{ 
     ImageView img; 
     CheckBox cbox; 
     int id; 
    } 

} 
나의 문제에 대한 해답을 발견
0

확인을 좀 도와주십시오.

관련 문제