简体   繁体   English

是否可以在kitkat +上没有文件选择器的情况下写入sd卡

[英]Is it possible to write to the sd card without a file picker on kitkat+

I want to delete files from the SD card root without a file picker. 我想从SD卡根目录删除文件而没有文件选择器。

After searching around for a couple of days,i haven't found a way to do this.But files apps ES file explorer have no problem,does anyone know why that is? 经过几天的搜索,我还没有找到一种方法。但是文件应用程序ES文件浏览器没有问题,有人知道为什么吗?

The closest thing i found would be this How to use the new SD-Card access API presented for Lollipop? 我发现最接近的东西是“ 如何使用为棒棒糖提供的新SD卡访问API”? but i have to use a file picker 但我必须使用文件选择器

Manifest 表现

<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>
<uses-permission android:name="ANDROID.PERMISSION.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="ANDROID.PERMISSION.WRITE_EXTERNAL_STORAGE"/>

<uses-permission android:name="android.permission.GET_PACKAGE_SIZE"/>
<uses-permission android:name="android.permission.CLEAR_APP_CACHE"/>



<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:screenOrientation="portrait"
        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>

You must provide us some source code and tell what you tried. 您必须提供一些源代码,并告诉您您尝试了什么。

Check if you can create new empty files: 检查是否可以创建新的空文件:

    File newFile = new File("/storage/sdcard1/test");
    try {
        file.createNewFile();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

Edit after comment: 评论后编辑:
Add this in your manifest above application tag. 将此添加到清单上方的应用程序标记。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM