2014-02-22 2 views
1

상황에 따라이 기능을 호출하면 소스 (카메라 및 갤러리 응용 프로그램)로 응용 프로그램을 선택할 수 있습니다. 그러나 Google 이미지에서 선택한 다른 이미지를 추가하고 싶습니다. Google 이미지를 얻으려면 모든 작업 코드가 있지만 어떻게이 목록에 추가합니까? 나는 모든 잘못된 장소를보고 있었다. 어떤 방향으로 도움이 될 것입니다!다른 인 텐트 추가

private static void openImageIntent(Activity a) { 
    // Determine Uri of camera image to save. 
    final File root = new File(Environment.getExternalStorageDirectory() + File.separator + "MyDir" + File.separator); 
    root.mkdirs(); 
    final String fname = "photo"; 
    final File sdImageMainDirectory = new File(root, fname); 
    outputFileUri = Uri.fromFile(sdImageMainDirectory); 

     // Camera. 
     final List<Intent> cameraIntents = new ArrayList<Intent>(); 
     final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
     final PackageManager packageManager = a.getPackageManager(); 
     final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0); 
     for(ResolveInfo res : listCam) { 
      final String packageName = res.activityInfo.packageName; 
      final Intent intent = new Intent(captureIntent); 
      intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name)); 
      intent.setPackage(packageName); 
      intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); 
      cameraIntents.add(intent); 
     }  

     // Filesystem. 
     final Intent galleryIntent = new Intent(); 
     galleryIntent.setType("image/*"); 
     galleryIntent.setAction(Intent.ACTION_GET_CONTENT); 

     // Chooser of filesystem options. 
     final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source"); 

     // Add the camera options. 
     chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[]{})); 

     a.startActivityForResult(chooserIntent, GALLERY_PIC_REQUEST); 

    } 

enter image description here

------------------------- 편집 ------------ --------------- 알았어요!

<activity 
     android:name="com.projectCaruso.imagesearch.ImageGridActivity" 
     android:label="@string/app_name" > 

     <intent-filter> 
      <action android:name="android.media.action.IMAGE_CAPTURE" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
      <data android:mimeType="text/plain"/> 
     </intent-filter> 

     <intent-filter> 
      <action android:name="android.intent.action.GET_CONTENT" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
      <category android:name="android.intent.category.OPENABLE" /> 
      <data android:mimeType="image/*"/> 
     </intent-filter> 
    </activity> 
+0

"그러나 Google 이미지에서 선택한 다른 이미지를 추가하고 싶습니다."- 다른 것을 추가하고 싶습니까? – AndyFaizan

+0

소스 선택 옵션 – jcaruso

+0

인 텐트 필터를 사용하여 이미지 파일 유형과 관련된 이벤트를 등록 했습니까? 당신이 찾고있는 것이면 Chris의 대답은 정확합니다 – AndyFaizan

답변

1

확인이 아니라이 분야의 전문가,하지만 난 당신이 여기에 나열된 샘플 답변 찾을 생각 : 짧은에서 http://developer.android.com/guide/components/intents-common.html#Storage

, 당신은 사용자 정의 'Google 이미지에 대한 매니페스트를 확장해야 - 액티비티 '를 선택하면 생성중인 Intent의 액션 및 데이터 마임 유형에 반응합니다. 아마 다시는 이런 일을 보이지만 수 : 나는 전문가가 아니에요, 나 자신은 아직이 시도 havn't는 :

<activity ...> 
<intent-filter> 
    <action android:name="android.intent.action.GET_CONTENT" /> 
    <data android:type="image/*" /> 
    <category android:name="android.intent.category.DEFAULT" /> 
    <category android:name="android.intent.category.OPENABLE" /> 
</intent-filter> 
</activity> 

문서 상태를 당신이 당신을 강제로 OPENABLE 범주없이 구현할 수없는 "OpenableColumnsContentResolver.openFileDescriptor()"을 지원하는 ContentProvider 특수 파일을 통해 파일을 사용할 수있게 만드십시오. 사실,이 요구 사항을 준수하기 위해 접착제 코드를 작성해야 할 수도 있습니다.

+0

내 매니페스트에서 사용하려고 시도했는데 오류가 발생했습니다 : 오류 : 문자열 유형이 허용되지 않습니다 (값 '이미지'/ ' * ').' – jcaruso

+0

나는 그것을 작동하게했다! – jcaruso