Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to download complete file in android app
    primarykey
    data
    text
    <p>following is my code,</p> <p><strong>From Activity class</strong> </p> <pre><code>Intent intent = new Intent(this, DownloadService.class); // Create a new Messenger for the communication back Messenger messenger = new Messenger(handler); intent.putExtra("MESSENGER", messenger); intent.setData(Uri.parse("http://www.abc.ezy.asia/E-MobApps/op.apk")); intent.putExtra("urlpath", "http://www.abc.ezy.asia/E-MobApps/op.apk"); startService(intent); </code></pre> <p><strong>I have overrided Service Class method onHandle Event</strong></p> <pre><code> // DownloadService Class @Override protected void onHandleIntent(Intent intent) { Uri data = intent.getData(); String urlPath = intent.getStringExtra("urlpath"); String fileName = data.getLastPathSegment(); File output = new File(Environment.getExternalStorageDirectory(),fileName); if (output.exists()) { output.delete(); } InputStream stream = null; FileOutputStream fos = null; try { URL url = new URL(urlPath); stream = url.openConnection().getInputStream(); fos = new FileOutputStream(output.getPath()); byte dataB[] = new byte[1024]; InputStreamReader reader = new InputStreamReader(stream); int next = -1; while ((next = reader.read()) != -1) { fos.write(next); } fos.flush(); result = Activity.RESULT_OK; } catch (Exception e) { e.printStackTrace(); } finally { if (stream != null) { try { stream.close(); } catch (IOException e) { e.printStackTrace(); } } if (fos != null) { try { fos.close(); } catch (IOException e) { e.printStackTrace(); } } } Bundle extras = intent.getExtras(); if (extras != null) { Messenger messenger = (Messenger) extras.get("MESSENGER"); Message msg = Message.obtain(); msg.arg1 = result; msg.obj = output.getAbsolutePath(); try { messenger.send(msg); } catch (android.os.RemoteException e1) { Log.w(getClass().getName(), "Exception sending message", e1); } } } } </code></pre> <p>In above code I used File Streams &amp; Input stream reader for downloading when tried to download html file then complete file was downloaded to my sdcard.But when I tried for APK. The File downloaded of 2.2 mb instead of 2.4 mb Parsing problem is there. Kindly help me to resolve the issue.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload