Android Internal Storage error

I tried to write internal storage somethings.Open an dir.. and fileoutputstream.I managed to write a file but when I try to use this file and get an error(There is not an error at Logcat.When "Startactivity" part run open an dialog.Write "There is a packet parsing error" on the dialog on android device).Actually the file is exist but I don't use the file. My aim with startactivity: open an intent which load the apk file to android device.

My path on internal storage

mydir = getDir("mydir", MODE_WORLD_READABLE);
filewithmydir = new File(mydir,fileName+".apk");
fileOutPutStream = new FileOutputStream(filewithmydir);

Write something to file with progressbar from inputstream(This part is succesfull)

    byte[] data = new byte[1024];
    long total = 0;
    int count;
    while ((count = inputStream.read(data)) != -1) {

        total += count;
        publishProgress((int) total * 100 / fileLength);

        fileOutPutStream.write(data, 0, count);
    }

The part which use the file

            intent.setDataAndType(Uri.fromFile(new File(mydir.getAbsolutePath()+"/incomingplus.apk")), "application/vnd.android.package-archive");
            startActivity(intent);// Error is here!

My permissions

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

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

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

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

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


In case you open file by external application, it has not access to your file. Also you use different variables: intent and intentGuncelle in intent.setDataAndType(Uri.fromFile(new File(mydir.getAbsolutePath()+"/incomingplus.apk")), "application/vnd.android.package-archive"); startActivity(intentGuncelle);// Error is here! intent.setDataAndType(Uri.fromFile(new File(mydir.getAbsolutePath()+"/incomingplus.apk")), "application/vnd.android.package-archive"); startActivity(intentGuncelle);// Error is here!


你有没有在清单中包含许可?

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
链接地址: http://www.djcxy.com/p/67504.html

上一篇: android将图片保存到内部存储器的麻烦

下一篇: Android内部存储错误