2017-02-05 84 views
0

所以我有點卡住了這一點。 起初,我用一個簡單的意圖來捕捉照片,並顯示在使用位圖的ImageView中它可以節省額外的費用。 保存這個,這樣我就可以將它上傳到firebase存儲中證明是困難的。 ive跟着android開發者的訓練課簡單地拍照。香港專業教育學院環顧四周,想我可能還需要與媒體評分進行掃描,但實際的照片在畫廊已經找到fileprovider不在應用程序目錄中保存圖像

我可以得到一個文件創建的,但它是在畫廊的應用程序0bytes 我實際上可以看到照片拍攝但在文件管理器和桌面瀏覽器中,我只能看到一個空文件。我真的不想要使用相機API。

此外,一旦我把照片的使用意圖應用程序拍照崩潰,然後繼續我的應用程序。文件提供商之前它會工作,並返回一個位圖 感謝您的期待。

在createfilepath方法的任何代碼冗餘我與Android 嘗試我認爲這個問題是與攝像頭的應用程序崩潰,但它發生在所有的caera應用我有它我的代碼

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
<paths xmlns:android="http://schemas.android.com/apk/res/android"> 
<external-path name="my_images" path="Android/data/com.example.testing.app/files/Pictures" /> 

</paths> 
</resources> 


public void newImage(){ 
    if(pic.resolveActivity(getActivity().getPackageManager())!=null) { 
     File photoFile = createFilePath(); 
     if(photoFile!=null){ 
      Log.d("abc", "newImage: "+photoFile.toString()); 

      Uri photoURI = FileProvider.getUriForFile(getActivity(),"com.example.testing.app.fileprovider",photoFile); 
      Log.d("abc", "newImage: "+photoURI.toString()); 
      pic.putExtra(MediaStore.EXTRA_OUTPUT,photoURI); 
      startActivityForResult(pic,1); 
     } 

    } 
} 

public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    Log.d("test", "onActivityResult: "); 
    if(requestCode==1&&resultCode==RESULT_OK){ 
    // galleryAddPic(); 
     Bundle extra= data.getExtras(); 
     bit =(Bitmap) extra.get("data"); 
     Log.d("abc", "onActivityResult: "+extra.get(MediaStore.EXTRA_OUTPUT).toString()); 
     picture.setImageBitmap(bit); 
    } 
} 


public File createFilePath(){ 
    File filepath= getActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES); 
    Log.d(TAG, "createFilePath: "+ filepath.toString()); 
    File filepath2 = new File(filepath.getAbsolutePath()); 
    File filepath3=null; 

    try { 
     filepath3 = File.createTempFile("temp", ".jpg", filepath4); 
     Log.d(TAG, "createFilePath: "); 
     return filepath3; 
    //  nCurrentPhotoPath = filepath3.getAbsolutePath(); 
    }catch(IOException e){ 
     e.printStackTrace(); 
     Log.d(TAG, "createFilePath: "); 
    } 

    return filepath3; 
} 

編輯提供商清單

<provider 
     android:name="android.support.v4.content.FileProvider" 
     android:authorities="com.example.testing.app.fileprovider" 
     android:exported="false" 
     android:grantUriPermissions="true"> 
     <meta-data 
      android:name="android.support.FILE_PROVIDER_PATHS" 
      android:resource="@xml/filepaths"/> 

    </provider> 

的功能和權限

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 


<uses-feature android:name="android.hardware.Camera" android:required="false"/> 
<uses-feature android:name="android.hardware.camera2" android:required="false"/> 
<uses-feature android:name="android.hardware.location.gps"/> 
+0

張貼您的供應商文件。 – Pztar

+0

我知道它的清單代碼 – ah4444

回答

0

一種解決方法是刪除文件提供,並採取位圖從意圖返回和onactivity使用這個答案 code

0

extra.get("data")提供的代碼是一個縮略圖, 你的真實形象是您創建的文件中photoFile

相關問題