2011-10-16 39 views
3

我開發了一款帶默認相機的相機應用程序。此應用程序適用於所有其他Android手機,但一些問題,三星Galaxy S我的相機應用程序在三星Galaxy S中賦予空值

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); 

這段代碼是給一個結果,我得到一個位圖圖像。但我無法從中檢索圖像路徑。

當我給EXTRA_OUTPUT,Galaxy S返回一個空值。因此,在調用相機意圖之前,我無法定義文件路徑和名稱。當我們使用這個應用程序拍攝照片時,Galaxy S將這張照片保存在默認位置,而不是保存到預先定義的位置。

如果有人有解決這個問題,請幫助我。

回答

0

我所做的是爲EXTRA_OUTPUT定義一個位置作爲Uri,在靜態或成員變量中緩存,然後在onActivity結果中使用緩存的位置來檢索圖像。我遇到了同樣的問題,這似乎很好。唯一的缺點是有兩個圖像副本,一個在EXTRA_OUTPUT中定義的位置,另一個位於默認位置。

+0

是的。但我必須避免重複複製。像foursquare這樣的應用程序可以提供相同的功能,而不會有圖像重複。 –

+0

這裏有一個概述[這裏](http://pixelsystems.net/?page_id=79),試圖做你所描述的。基本上你會聽一個新的圖庫圖像,將它複製到你想要的位置,然後從媒體商店刪除記錄。這樣你最終只有一個圖像。 – jvergeldedios

+0

他還有一個Github帳號和他的示例代碼[在這裏](https://github.com/pr0cs/CameraTest)。 – jvergeldedios

0

找到的答案這裏是最好的例子,它是自我打擾的設備!

AndroidCameraUtils - 下載項目和庫項目由包括它下面是代碼片段可以使用!

private void setupCameraIntentHelper() { 
    mCameraIntentHelper = new CameraIntentHelper(this, new CameraIntentHelperCallback() { 
     @Override 
     public void onPhotoUriFound(Date dateCameraIntentStarted, Uri photoUri, int rotateXDegrees) { 
      messageView.setText(getString(R.string.activity_camera_intent_photo_uri_found) + photoUri.toString()); 

      Bitmap photo = BitmapHelper.readBitmap(CameraIntentActivity.this, photoUri); 
      if (photo != null) { 
       photo = BitmapHelper.shrinkBitmap(photo, 300, rotateXDegrees); 
       ImageView imageView = (ImageView) findViewById(de.ecotastic.android.camerautil.sample.R.id.activity_camera_intent_image_view); 
       imageView.setImageBitmap(photo); 
      } 
     } 

     @Override 
     public void deletePhotoWithUri(Uri photoUri) { 
      BitmapHelper.deleteImageWithUriIfExists(photoUri, CameraIntentActivity.this); 
     } 

     @Override 
     public void onSdCardNotMounted() { 
      Toast.makeText(getApplicationContext(), getString(R.string.error_sd_card_not_mounted), Toast.LENGTH_LONG).show(); 
     } 

     @Override 
     public void onCanceled() { 
      Toast.makeText(getApplicationContext(), getString(R.string.warning_camera_intent_canceled), Toast.LENGTH_LONG).show(); 
     } 

     @Override 
     public void onCouldNotTakePhoto() { 
      Toast.makeText(getApplicationContext(), getString(R.string.error_could_not_take_photo), Toast.LENGTH_LONG).show(); 
     } 

     @Override 
     public void onPhotoUriNotFound() { 
      messageView.setText(getString(R.string.activity_camera_intent_photo_uri_not_found)); 
     } 

     @Override 
     public void logException(Exception e) { 
      Toast.makeText(getApplicationContext(), getString(R.string.error_sth_went_wrong), Toast.LENGTH_LONG).show(); 
      Log.d(getClass().getName(), e.getMessage()); 
     } 
    }); 
} 

@Override 
protected void onSaveInstanceState(Bundle savedInstanceState) { 
    super.onSaveInstanceState(savedInstanceState); 
    mCameraIntentHelper.onSaveInstanceState(savedInstanceState); 
} 

@Override 
protected void onRestoreInstanceState(Bundle savedInstanceState) { 
    super.onRestoreInstanceState(savedInstanceState); 
    mCameraIntentHelper.onRestoreInstanceState(savedInstanceState); 
} 

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent intent) { 
    super.onActivityResult(requestCode, resultCode, intent); 
    mCameraIntentHelper.onActivityResult(requestCode, resultCode, intent); 
} 
} 
  • 下面添加襯裏,以體現你的活動android:configChanges="keyboardHidden|orientation|screenSize"

注意的文件: - 我試了很多例子相機utils的和ofcourse有另一種方式來處理,但對於初學者和對這個核心概念不太熟悉的人會對這個項目更加安心。謝謝!

相關問題