2012-09-07 64 views
0

保存圖像時,此功能是用來保存關於SD卡圖像(I已經測試它在仿真器上只):權限否認SD卡

public String SaveImage(String URL,String imagename){ 

     Bitmap bitmap = null; 
     InputStream in = null; 
     String path = Environment.getExternalStorageDirectory().toString(); 
     File dir = new File(path + "/bh"); 
     if(!dir.exists()) 
      new File(path + "/bh").mkdir(); 
     Log.i("in save()", "after file"); 
     File mImageFile = new File(path+"/bh/"+imagename); 

     if(mImageFile.exists()) 
      Toast.makeText(mContext, "Saved", Toast.LENGTH_LONG).show(); 

     try{ 
      in = OpenHttpConnection(URL); 
      bitmap = BitmapFactory.decodeStream(in); 
      FileOutputStream out = new FileOutputStream(mImageFile); 
      bitmap.compress(CompressFormat.JPEG, 100,out); 
      out.flush(); 
      out.close(); 
      in.close(); 
      return imagename+".jpg"; 
     }catch(IOException ex){ 
      Log.e("==== Error in saving image ====",ex.getMessage()); 
      return ""; 
     } 
    } 

我已經加入如下面的所需權限:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="mobile.bh" 
    android:versionCode="4" 
    android:versionName="1.0.3" > 

    <uses-sdk android:minSdkVersion="8" /> 

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 

    <application 
     android:icon="@drawable/icon" 
     android:label="@string/app_name" 
     android:theme="@android:style/Theme.NoTitleBar.Fullscreen" > 
     <activity 
      android:name="mobile.bh.activities.BHActivity" 
      android:screenOrientation="portrait" > 
     </activity> 
     <activity 
      android:name="mobile.bh.activities.RecipesListActivity" 
      android:screenOrientation="portrait" > 
     </activity> 
     <activity 
      android:name="mobile.bh.activities.RecipeInfoActivity" 
      android:screenOrientation="portrait" > 
     </activity> 
     <activity 
      android:name="mobile.bh.activities.IngredientsActivity" 
      android:screenOrientation="portrait" > 
     </activity> 
     <activity 
      android:name="mobile.bh.activities.MethodActivity" 
      android:screenOrientation="portrait" > 
     </activity> 
     <activity 
      android:name="mobile.bh.activities.SpicesListActivity" 
      android:screenOrientation="portrait" > 
     </activity> 
     <activity android:name=".activities.SpicesCategoriesActivity" > 
     </activity> 
     <activity android:name=".activities.CategoryActivity" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 

</manifest> 
+2

你能發佈的logcat輸出的問題? – florianmski

+0

你把這些權限放在哪裏? Manifest的哪個標籤? – Blackbelt

+0

這裏是完整的清單文件 – Adham

回答

0

您還需要使用互聯網許可,因爲您連接到互聯網。

<uses-permission android:name="android.permission.INTERNET" /> 
+0

我已經有了它 – Adham

+0

你得到的錯誤是什麼? –