我正在使用 Web 服务在 Android 中构建应用程序。我想做的是同步功能。我正在从 Web 服务器获取一些属性,并且我有一个布尔值,如果布尔值为真,那么它将更新我下载的文档。
但是我被困在这里,要么我需要先删除文档然后替换它,要么我可以直接替换文档。代码是这样的:
SoapObject DocResponse = (SoapObject)envelope.getResponse();
Log.i("Uspdated Documentss", DocResponse.toString());
for(int i=0; i < DocResponse.getPropertyCount(); i++)
{
SoapObject SingleSubFolder = (SoapObject)DocResponse.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();
IsUpdated = SingleSubFolder.hasProperty("IsUpdated");
db = new DMS_Database(context);
if(IsUpdated==true)
{
// How to perform replace function from database here???
// Is there any need of download manager so that again it download new folder into the phone storage or into the database???
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)Activtyclass.mAct.getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
}
db.close();
}
}
catch(Exception e)
{
e.printStackTrace();
Toast.makeText(context, " Network Exception : " + e
+ "Please check network connectivity.", Toast.LENGTH_LONG).show();
}
数据库:这是我的数据库方法……对吗???
public void update_Doc(String Id, String name, String url)
{
SQLiteDatabase db = this.getWritableDatabase();
ContentValues updatenote = new ContentValues();
updatenote.put(DOCUMENT_ID, Id);
updatenote.put(DOCUMENT_NAME, name);
updatenote.put(DOCUMENT_URL, url);
db.update(DOCUMENT_TABLE, updatenote, DOCUMENT_ID + "=?" , new String[] {String.valueOf(Id)});
}