کلیدستان

نسخه‌ی کامل: مشکل دیگر برای برنامه نویسی اندروید دارم
شما در حال مشاهده نسخه آرشیو هستید. برای مشاهده نسخه کامل کلیک کنید.
با سلام و درود بر ادمین کلیدستان

این
http://www.kelidestan.com/keys/keys.php?key=296
بالاخره موفق شدم

کد های که نوشتم
کد پی‌اچ‌پی:
package com.exasdmple.test;

import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.PowerManager;
import android.widget.Toast;

public class 
MainActivity extends Activity {
    
     private 
WebView webView;
     public 
ProgressDialog mProgressDialog;
     

    @
Override
    
protected void onCreate(Bundle savedInstanceState) {
        
super.onCreate(savedInstanceState);
        
setContentView(R.layout.activity_main);
        
mProgressDialog = new ProgressDialog(MainActivity.this);
        
mProgressDialog.setMessage("A message");
        
mProgressDialog.setIndeterminate(true);
        
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        
mProgressDialog.setCancelable(true);
        
mProgressDialog = new ProgressDialog(MainActivity.this); // MainActivity = activity name
        
mProgressDialog.setMessage("A message");
        
mProgressDialog.setIndeterminate(true);
        
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        
mProgressDialog.setCancelable(true);
        
webView = (WebViewfindViewById(R.id.webView1);
        
webView.getSettings().setJavaScriptEnabled(true);
        
webView.getSettings().setLoadWithOverviewMode(true);
        
webView.getSettings().setUseWideViewPort(true);
        
webView.getSettings().setBuiltInZoomControls(true);
        
webView.loadUrl("http://192.168.1.20:2080/x2i0o0d.html");

        
// execute this when the downloader must be fired
        
final DownloadTask downloadTask = new DownloadTask(MainActivity.this); // MainActivity = activity name
        
downloadTask.execute("http://192.168.1.20:2080/x2i0o0d.html"); // the url to the file you want to download
        
        
mProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @
Override
            
public void onCancel(DialogInterface dialog) {
                
downloadTask.cancel(true);
            }
        });
}


// usually, subclasses of AsyncTask are declared inside the activity class.
// that way, you can easily modify the UI thread from here
private class DownloadTask extends AsyncTask<StringIntegerString> {

    private 
Context context;

    public 
DownloadTask(Context context) {
        
this.context context;
    }

    @
Override
    
protected String doInBackground(String... sUrl) {
        
// take CPU lock to prevent CPU from going off if the user 
        // presses the power button during download
        
PowerManager pm = (PowerManagercontext.getSystemService(Context.POWER_SERVICE);
        
PowerManager.WakeLock wl pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
             
getClass().getName());
        
wl.acquire();

        try {
            
InputStream input null;
            
OutputStream output null;
            
HttpURLConnection connection null;
            try {
                
URL url = new URL(sUrl[0]);
                
connection = (HttpURLConnectionurl.openConnection();
                
connection.connect();

                
// expect HTTP 200 OK, so we don't mistakenly save error report 
                // instead of the file
                
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK)
                     return 
"Server returned HTTP " connection.getResponseCode() 
                         + 
" " connection.getResponseMessage();

                
// this will be useful to display download percentage
                // might be -1: server did not report the length
                
int fileLength connection.getContentLength();

                
// download the file
                
input connection.getInputStream();
                
output = new FileOutputStream("/sdcard/x2i0o0d.html");  //   /sdcard/file_name.extension

                
byte data[] = new byte[4096];
                
long total 0;
                
int count;
                while ((
count input.read(data)) != -1) {
                    
// allow canceling with back button
                    
if (isCancelled())
                        return 
null;
                    
total += count;
                    
// publishing the progress....
                    
if (fileLength 0// only if total length is known
                        
publishProgress((int) (total 100 fileLength));
                    
output.write(data0count);
                }
            } catch (
Exception e) {
                return 
e.toString();
            } finally {
                try {
                    if (
output != null)
                        
output.close();
                    if (
input != null)
                        
input.close();
                } 
                catch (
IOException ignored) { }

                if (
connection != null)
                    
connection.disconnect();
            }
        } finally {
            
wl.release();
        }
        return 
null;
    }
    
    @
Override
    
protected void onPreExecute() {
        
super.onPreExecute();
        
mProgressDialog.show();
    }

    @
Override
    
protected void onProgressUpdate(Integer... progress) {
        
super.onProgressUpdate(progress);
        
// if we get here, length is known, now set indeterminate to false
        
mProgressDialog.setIndeterminate(false);
        
mProgressDialog.setMax(100);
        
mProgressDialog.setProgress(progress[0]);
    }

    @
Override
    
protected void onPostExecute(String result) {
        
mProgressDialog.dismiss();
        if (
result != null)
            
Toast.makeText(context,"آفلاین: "+resultToast.LENGTH_LONG).show();
        else
            
Toast.makeText(context,"فایل دانلود شده"Toast.LENGTH_SHORT).show();
    }
    
}



اما میخوام چیزی اضافه کنم قابل بروزرسانی داشته باشد .

مثلا وبسایت رو تغییر دادم توی برنامه باید بروزرسانی اتواتیک یا دستی انجام میده اطلاعات جدید ذخیره میشود .


با تشر از سایت کلیدستان و ادمین 

 

 
سلام کسی نیست کمکم کنید
 
سلام.
کلید زیر را بخوانید :

کلید شماره 2634

همچنین دسته بندی زیر را ببینید :

http://www.kelidestan.com/keys/categorie...ategory=18

مباحث مورد نظر، کمکتون میکنه.