Note that there are some explanatory texts on larger screens.

plurals
  1. POwait for php script then download
    primarykey
    data
    text
    <p>i have a php script which creates a file if it not exists. the php script sends the file after it created it. now i have the problem that my download class can't download it (i don't know exactly why) when the php file is creating a new file. but if the php script sends a cached file the download works. Is there any way to let the android wait until the php script is done executing?</p> <pre><code>import java.io.BufferedInputStream; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import java.net.URL; import java.net.URLConnection; import org.json.JSONObject; import android.os.AsyncTask; import android.os.Environment; import android.os.Looper; import android.provider.ContactsContract.Directory; import android.util.Log; public class DownloadMP3 extends AsyncTask&lt;String, Integer, String&gt; { private OnTaskRunning listener; public DownloadMP3(OnTaskRunning listener){ this.listener=listener; } @Override protected String doInBackground(String... url) { int count; try { Log.d("Info", "create file"); Download down = new Download(); JSONObject jObject = new JSONObject(down.JSON(conf.d + "convert.php?v=" + url[0])); Log.d("Info","json file: " + jObject.get("fle")); URL u = new URL(conf.d + "convert.php?v=" + jObject.get("fle")); Log.d("Info", "dl u"); URLConnection conexion = u.openConnection(); Log.d("Info", "dl op"); conexion.connect(); Log.d("Info", "dl co"); File directory = new File(Environment.getExternalStorageDirectory() + "/Music/VBT Splash/"); Log.d("Info", "dl di"); if (!directory.exists() || !directory.isDirectory()){ directory.mkdirs(); } InputStream input = new BufferedInputStream(u.openStream()); String filename = conexion.getHeaderField("Content-Disposition"); String file = filename.substring(filename.indexOf("\"")+1, filename.lastIndexOf("\"")); OutputStream output = new FileOutputStream(Environment.getExternalStorageDirectory() + "/Music/VBT Splash/" + file); int lenghtOfFile = conexion.getContentLength(); byte data[] = new byte[4096]; long total = 0; listener.onTaskStarted(); while ((count = input.read(data)) != -1) { total += count; output.write(data, 0, count); publishProgress((int) (total * 100 / lenghtOfFile)); } Log.d("Info", "dl done"); listener.onTaskDone(); output.flush(); output.close(); input.close(); } catch (Exception e) { } return null; } protected void onProgressUpdate(Integer... progress) { listener.onTaskProgress(progress[0]); } protected void onPostExecute(int result) { } } </code></pre>
    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.
    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