0

when I run this program(I'm use the mp4prasser Library) I receive an exception:

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

but in the Manifest I set the permission:

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

this is the code(API 17):

public class MainActivity extends AppCompatActivity {
Button mButton;
String Path;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mButton=(Button)findViewById(R.id.button);
    mButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                Path= Environment.getExternalStorageDirectory().toString()
                +File.separator+"AAAATAG"+File.separator+"abcde.mp4";
                startTrim(Path,Environment.getExternalStorageDirectory().toString(),50000,100000);
            } catch (IOException e) {
                Toast.makeText(MainActivity.this, e.toString(), Toast.LENGTH_SHORT).show();
            }
        }
    });



}

to see the code of the func startTrim(): http://pastebin.com/LDjn3Y7f

israelbenh
  • 207
  • 1
  • 3
  • 12

2 Answers2

0

Please check if you have placed user permssion at the right place ? Actually I made this mistake once and took a long time to fix.

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

          ...

        <application>
            ...
              <activity> 
                    ...
              </activity

        </application>
</manifest> 
Saby
  • 718
  • 9
  • 29
0

You should look at the logcat output to verify, but it is most likely because of this line (see in your pastebin) of startTrim():

file.getParentFile().mkdirs();

This is attempting to make a destination directory, which the parent of the passed in directory name (Environment.getExternalStorageDirectory()) plus a filename you have generated. No file separator is added. Since that parent directory is a system controlled directory (and already exists) you won't have permissions to create it. The same call is made later in genVideoUsingMp4Parser().

The backtrace in the logcat output should point you right to what call was being made which resulted in the EACCESS error.

Larry Schiefer
  • 15,687
  • 2
  • 27
  • 33
  • What are you trying to accomplish with the `mkdirs()` call? Are you creating your own sub-directory to store the altered video? If so, you need to create a properly formed `File` object with the right name and create a directory with that name; then, write your modified video file there. Right now it appears to be trying to create a directory which already exists, or a new one at a level above where your app actually has permissions (likely the root filesystem path.) – Larry Schiefer Aug 05 '16 at 12:47