2

I have a method that tries to extract m3u files, but it doesn't work at api level 29. I get the following error on the Logcat screen:

2019-10-03 20:46:53.165 32591-417/? E/Google: java.io.IOException: Cleartext HTTP traffic to mysite.tk not permitted

My Method:

@SuppressLint("StaticFieldLeak")
class _loadFile extends AsyncTask<String, Void, Boolean> {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        spinner.setVisibility(View.VISIBLE);
    }

    @Override
    protected Boolean doInBackground(String... strings) {
        try { //new FileInputStream (new File(name)
            is = new FileInputStream(new File(strings[0])); // if u r trying to open file from asstes InputStream is = getassets.open(); InputStream
            M3UPlaylist playlist = parser.parseFile(is);
            mAdapter.update(playlist.getPlaylistItems());

            return true;
        } catch (Exception e) {
            Log.d("Google", "_loadFile: " + e.toString());
            return false;
        }
    }

    @Override
    protected void onPostExecute(Boolean aBoolean) {
        super.onPostExecute(aBoolean);
        spinner.setVisibility(View.GONE);
    }
}

EDİT:

I gave ClearText permission, but a new error appeared.

Google: _loadFile: java.io.FileNotFoundException: /storage/emulated/0/Netuptv/data.m3u: open failed: ENOENT (No such file or directory)

EDİT:

My file path. I think the problem is here. But I don't have the information to solve it.

   static final File DEFA = Environment.getExternalStorageDirectory();
    public static final File dir = new File(DEFA.getPath() + "/Netuptv");
    static final File filepath = new File(dir.getPath() + "/data.m3u");
Pehr Sibusiso
  • 862
  • 1
  • 14
  • 27

3 Answers3

1

Please check if you added this line android:usesCleartextTraffic="true" to your Manifest.

Since the file access API is deprecated on Android Q, I highly recommend to you to read this article by CommaneWare , as mention on this article, try to use android:requestLegacyExternalStorage="true" to avoid the file access issues

Try the following :

        String fileName = "data.m3u";
        File storageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES)
                        + "/Netuptv");
        boolean success = true;
        if (!storageDir.exists()) {
            success = storageDir.mkdirs();
        }
        if (success) {
            File file = new File(storageDir,fileName);
            filepath = file.getAbsolutePath();
        }
0

With Android 10 (api level 29) file access is deprecated, it's called scoped storage.

greywolf82
  • 21,813
  • 18
  • 54
  • 108
0

A quick but not permanent fix for testing on Android 11:

Adding android:requestLegacyExternalStorage="true"

and changing

compileSdkVersion 29 targetSdkVersion 29

both to 29 in build.gradle

DIRTY DAVE
  • 2,523
  • 2
  • 20
  • 83