2011-12-18 2 views
7

내 앱이 카메라 앱인 것처럼 안드로이드에게 말하는 법이 궁금 해서요. 다른 앱이 내 앱을 시작하여 사진을 찍을 수 있다는 것을 알고 있습니다. 예. pixlr-o-matic을 사용하면 갤러리에서 이미지를 선택하거나 원하는 카메라 앱에서 이미지를 요청할 수 있습니다.android : 내 앱을 "카메라 앱"으로 등록하는 방법

편집 : 어떻게 전화하는 앱에 사진을 반환합니까?

답변

11

이것은 인 텐트 필터로 수행됩니다. 매니페스트에 다음 태그를 추가하십시오.

<activity android:name=".CameraActivity" android:clearTaskOnLaunch="true"> 
    <intent-filter> 
     <action android:name="android.media.action.IMAGE_CAPTURE" /> 
     <category android:name="android.intent.category.DEFAULT" /> 
    </intent-filter> 
</activity> 

이제 사용자가 사진을 찍을 때 응용 프로그램이 목록에 나타납니다.

편집 :

Uri saveUri = (Uri) getIntent().getExtras().getParcelable(MediaStore.EXTRA_OUTPUT); 

if (saveUri != null) 
{ 
    // Save the bitmap to the specified URI (use a try/catch block) 
    outputStream = getContentResolver().openOutputStream(saveUri); 
    outputStream.write(data); // write your bitmap here 
    outputStream.close(); 
    setResult(RESULT_OK); 
} 
else 
{ 
    // If the intent doesn't contain an URI, send the bitmap as a Parcelable 
    // (it is a good idea to reduce its size to ~50k pixels before) 
    setResult(RESULT_OK, new Intent("inline-data").putExtra("data", bitmap)); 
} 

또한 내장 Camera app source code 안드로이드를 확인할 수 있습니다 여기에

는 비트 맵을 반환하는 적절한 방법입니다.

+0

죄송합니다. 무언가를 잊어 버렸습니다. 방금 질문을 편집했습니다. – stoefln

+0

대답을 편집했습니다. – Dalmas

+0

큰 이미지를 추가하는 데 문제가 있습니까? 이미지로가는 길을 돌려주는 것이 낫지 않을까요? – stoefln

3

활동에 대한 의도 필터를 지정해야합니다.이 필터는 사진을 찍기 위해 앱을 시작할 수 있도록 지정합니다.

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

희망이 있습니다.

+0

도움이 되었습니까? –

+0

죄송합니다. 무언가를 잊어 버렸습니다. 질문을 편집했습니다. – stoefln

관련 문제