2

我的问题是我需要每 15 分钟使用一次同步功能,所以我想要的是,我会将 doc_id 发送到 Web 服务器,服务器将返回一个带有一些字段的新 doc_Id,我想要的是用新文档替换旧文档。

我的代码:

 public void Updatefile(String Doc_Id)
{
    try
    {
        SoapObject Subfolderrequest = new SoapObject(NAMESPACE, UPDATE_FILE_METHOD);
        Subfolderrequest.addProperty("DocumentID", Doc_Id);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(Subfolderrequest);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        androidHttpTransport.debug = true;
        androidHttpTransport.call(SOAP_ACTION_UPDATE_FILE , envelope);
        SoapObject SubfolderResponse = (SoapObject)envelope.getResponse();  
        Log.i("SubFolders", SubfolderResponse.toString());  
        for(int i=0; i < SubfolderResponse.getPropertyCount(); i++)
        {
            SoapObject SingleSubFolder = (SoapObject)SubfolderResponse.getProperty(i);      
            ID = SingleSubFolder.getProperty(0).toString();
            fileLongName = SingleSubFolder.getProperty(1).toString();
            UserFileName = SingleSubFolder.getProperty(2).toString();
            url = SingleSubFolder.getProperty(3).toString();
            fileExtension = SingleSubFolder.getProperty(4).toString();
            lastModifiedDate = SingleSubFolder.getProperty(5).toString();
            SubjectType = SingleSubFolder.getProperty(6).toString();

        }
        if(IsUpdated==true){
            DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
            request.setTitle(UserFileName);
            // in order for this if to run, you must use the android 3.2 to compile your app
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) 
                {
                    request.allowScanningByMediaScanner();
                    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                }
                    request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS + "/Downloads", UserFileName);
                    DownloadManager manager = (DownloadManager)getSystemService(Context.DOWNLOAD_SERVICE);
                    manager.enqueue(request);
        }
        else
        {

        }
    }   
    catch(Exception e) 
    {
        Log.i("Hi", "Exception");
    }
}

我想要的是,我将一个接一个地传递 id,如果文档已更新,那么它将检查来自 Web 服务器的布尔值“isupdated”,如果“isUpdated”为真,那么它将替换文档,否则不会。请让我知道如何用现有文件替换该文件。我也在广播接收器中调用方法,它在行中给出错误: : DownloadManager manager = (DownloadManager)getSystemService(Context.DOWNLOAD_SERVICE);

 //error in getSystemService... thank you. :)
4

0 回答 0