我希望我的应用程序下载tar.tgz文件,然后在应用程序包中提取它:
/数据/数据/包
下载成功完成,但我无法解压缩tar文件。我使用AsyncTask的doInBackground()方法下载tar文件,使用PostExecute()方法来提取它。我的代码是:
class InstallPython extends AsyncTask< String, String, String >
{
@Override
protected String doInBackground( String... f_url )
{
int count = 0;
byte data[] = new byte[ 15317957 ];
try
{
//Create the URL object url for the Python binary URL.
URL url = new URL( f_url[ 0 ] );
//Create the URLConnection object connection for the previous URL object.
URLConnection conection = url.openConnection();
conection.connect();
//Create the InputStream object input for reading from url object.
InputStream input = new BufferedInputStream( url.openStream(), 15317957 );
//Create the OutputStream object output for writing.
OutputStream output = new FileOutputStream( "/data/data/com.rg.rgnettools/python.tar.tgz" );
//Read from url object and write in the new file.
while ( ( count = input.read( data ) ) != -1 )
{
output.write( data, 0, count );
}
//Close file descriptors.
output.flush();
output.close();
input.close();
}
catch ( Exception e )
{
Log.e( "Download-Python-Error: ", e.getMessage() );
}
return null;
}
@Override
protected void onPostExecute( String file_url )
{
try
{
Runtime.getRuntime().exec( new String[]{ "su", "-c", "tar -xzf /data/data/com.rg.rgnettools/python.tar.tgz" } );
}
catch ( Exception e )
{
Log.e( "SPLASHSCREENACTIVITY_ERROR", e.getMessage() );
}
}
}