在sdCard android上保存位图到文件时出错

时间:2013-06-18 17:55:05

标签: android file bitmap sd-card

我有代码将bitamp保存到sdcard上的文件但是当我运行此代码时它会出现此错误

java.io.IOException: open failed: EACCES (Permission denied)

代码:

 Bitmap photo = extras.getParcelable("data");
                    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                    photo.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
                    File f = new File(Environment.getExternalStorageDirectory()+ File.separator + "test.jpg");
                    try {
                            f.createNewFile();
                            FileOutputStream fo = new FileOutputStream(f);
                            fo.write(bytes.toByteArray());
                            fo.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                        Log.d("ERROR", e.toString());
                    }

我尝试在AndroidManifest.xml上添加它并且不起作用

=======

的AndroidManifest.xml          

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.test"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-feature android:name="android.hardware.camera"></uses-feature> 

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.test.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

1 个答案:

答案 0 :(得分:0)

我改变时解决了我的问题

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

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