Android 용 간단한 이미지 갤러리 앱을 만들고 있습니다. SMS, 전자 메일, 채팅 응용 프로그램에 이미지를 추가 할 때 사용자가 이미지를 선택할 수있게하려는 경우 ... 내 응용 프로그램을 응용 프로그램 선택기에 표시하기 위해 의도 필터를 사용했습니다. 사용자가 이미지를 추가하고 싶은 메뉴 :Android - 의도에 대한 응답으로 이미지를 다른 응용 프로그램에 전달
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.OPENABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="vnd.android.cursor.dir/image" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="vnd.android.cursor.dir/image" />
</intent-filter>
<intent-filter>
<action android:name="android.media.action.IMAGE_CAPTURE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
그런 다음 사용자가 이미지를 선택할 수 있습니다,하지만 난 발신자 응용 프로그램에 응답하는 가장 좋은 방법을 찾고 있어요.
나는 임시 파일로 이미지를 저장하고이 작동 해당 파일
public void respondWithImage(Bitmap bitmap){
try {
//If needed create temp folder
File folder = new File(Environment.getExternalStorageDirectory() + "/temp/");
if (!folder.exists()) {
folder.mkdirs();
}
File nomediaFile = new File(folder, ".nomedia");
if (!nomediaFile.exists()) {
nomediaFile.createNewFile();
}
//Create temp image file
FileOutputStream out = new FileOutputStream(
Environment.getExternalStorageDirectory()
+ "/temp/temp.png");
bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
File bitmapFile = new File(
Environment.getExternalStorageDirectory()
+ "/temp/temp.png");
//Tell parent activity to respond with the image
if (bitmapFile.exists()) {
Intent localIntent = new Intent().setData(Uri
.fromFile(bitmapFile));
parentActivity.setResult(Activity.RESULT_OK, localIntent);
} else {
parentActivity.setResult(Activity.RESULT_CANCELED);
}
parentActivity.finish();
} catch (Exception e) {
e.printStackTrace();
Log.d("error", "Error writing data");
}
}
의 URI를 보내려고 노력했지만 나는 전화가 더 SDCARD가없는 경우는 어떻게 할 것인지 궁금합니다. 그 옵션을 시도 할 수 없다. 분명히 ext 카드로 자신의 메모리를 고려한 GS3을 가지고 있기 때문이다. (내가 틀렸다면 나에게 맞춰라.)
드로어 블을 가리키는 URI를 다시 보내려고했다. 내 애플 내 리소스 (PNG 파일) (내 애플 리케이션 리소스에 이미지가 문제가되지 않을)하지만 그것은 호출 응용 프로그램 (MMS) 충돌하게하고 디버거에서 오류를 catch하지 않습니다.
올바른 방법은 무엇입니까?
다른 앱에 리소스를 전달할 수 없습니다. –
왜 를 하나의 필터에 모두 넣었습니까? 첫 번째 것도 두 번째 것을 다루고 있지 않습니까? – Eftekhari