注 -即使即時通信使用phonegap,問題是不是關於一些問題。
嗨,即時通訊開發一個Android應用程序。我的應用程序使用phonegap 1.3。
mi問題...
即時通訊使用phonegap apis拍照並顯示在我的應用程序。但是,最新發生的原因是操作系統在相機啓動後會殺死我的應用程序,所以點擊照片後,我的應用程序會重新啓動,並且不會獲取拍攝照片的信息。
作爲解決此問題的(the problem),因此我設計了在應用程序開始檢查是否在拍攝圖像時(一些標誌代碼)的應用程序已經墜毀一個PhoneGap的插件,如果它崩潰後重新啓動,它檢索產品圖.jpg由相機拍攝並嘗試顯示它。 問題是,它無法獲得正確的圖像,甚至沒有正確的.jpg文件。
安卓phonegap應用程序:無法檢索使用我自己的代碼(不phonegapgap)相機拍攝的圖像
英里代碼...
的PhoneGap做的意圖,啓動攝像頭並將其創建爲它傳遞給startActivityForResult該意圖的Pic.jpg的URI。
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
File photo = new File(DirectoryManager.getTempDirectoryPath(ctx), "Pic.jpg");
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
this.imageUri = Uri.fromFile(photo);
this.ctx.startActivityForResult((Plugin) this, intent, 0);
注意 - 上面的代碼是從的PhoneGap的文件 CameraLauncher.java。
現在,IM假定startActivityForResult存儲用戶捕獲在其通過在上面的代碼「照片」創建該文件的圖像。因此,即使在操作系統在相機打開時關閉應用程序後(請參閱 - the problem),照片也會存儲在那裏。如果這個假設是錯誤的,請糾正我,或者如果照片可能被保存在其他地方。
所以考慮到這個假設我寫以檢索使用其中的PhoneGap使用相同的邏輯這個圖象的一個插件中 CameraLauncher.java
Uri imageUri;
ExifHelper exif = new ExifHelper();
exif.createInFile(getTempDirectoryPath(ctx) + "/Pic.jpg");
exif.readExifData();
File photo = new File(getTempDirectoryPath(ctx), "Pic.jpg");
imageUri = Uri.fromFile(photo);
Bitmap bitmap = null;
bitmap = android.provider.MediaStore.Images.Media.getBitmap(this.ctx.getContentResolver(), imageUri);
ContentValues values = new ContentValues();
values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
Uri uri = null;
try {
uri = this.ctx.getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
} catch (UnsupportedOperationException e) {
uri = this.ctx.getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
}
// Add compressed version of captured image to returned media store Uri
OutputStream os = this.ctx.getContentResolver().openOutputStream(uri);
bitmap.compress(Bitmap.CompressFormat.JPEG, 20, os);
os.close();
exif.createOutFile(getRealPathFromURI(uri, this.ctx));
exif.writeExifData();
bitmap.recycle();
bitmap = null;
System.gc();
result = new PluginResult(Status.OK, uri.toString());
這大致相同的邏輯的PhoneGap使用。 (我已經刪除了所有的異常處理,因此假設沒有任何編譯錯誤。)所以,我基本上試圖檢索Pic.jpg並將其返回給我的phonegap應用程序。
但是最新情況是,即時獲取一個損壞的文件abt 150kb甚至不是一個jpg(沒有打開)。
請告訴我,如果它甚至有可能是死於開始執行的照相機的活動後檢索以這種方式圖像。如果可能的話,那我做錯了什麼。請幫忙!