简体   繁体   English

Android:如何保证文件上传到WCF服务?

[英]Android: How to guarantee file upload to WCF service?

My app create a few files dynamically and keeps track of the files through an object. 我的应用程序动态创建了一些文件,并通过对象跟踪文件。 At some point the object is passed to an IntentService. 在某个时候,该对象将传递给IntentService。 The purpose of the IntentService is to IntentService的目的是

  • Create a XML-file to contain data about the other files 创建一个XML文件以包含有关其他文件的数据
  • Add the XML-file and the other files to a ZIP-file 将XML文件和其他文件添加到ZIP文件
  • Upload the ZIP-file to a WCF-service 将ZIP文件上传到WCF服务

The ZIP-file MUST be uploaded at some point. ZIP文件必须在某个时候上传。 Things can happen; 事情可能发生; the WCF-service may be down and so on. WCF服务可能已关闭等。

What options do I have in terms of guaranteeing that ZIP-file will be uploaded? 在保证将上传ZIP文件方面,我有什么选择? My current plan is to save some info to a SQLite DB and check it every time the app is started and take it from there. 我目前的计划是将一些信息保存到SQLite数据库中,并在每次启动应用程序时进行检查,然后从那里获取信息。 Not sure that is a good idea or if there are better ways to handle this. 不知道这是一个好主意,还是不确定是否有更好的方法来解决这个问题。

Also, I am an Android newbie, but if I have understood things correctly, if the IntentService is shut down before it is done, it will automatically be re-created with the same Intent and such at some point, right? 另外,我是一名Android新手,但是如果我对事情的理解正确,并且在IntentService完成之前将其关闭,它会自动以相同的Intent进行重新创建,对吗? Else I will have to take that into account as well. 否则,我也必须考虑到这一点。

You should take a look at using the built in sync service by making use of a sync adapter Have a look at this http://naked-code.blogspot.co.uk/2011/05/revenge-of-syncadapter-synchronizing.html 您应该通过使用同步适配器来了解如何使用内置的同步服务看看此http://naked-code.blogspot.co.uk/2011/05/revenge-of-syncadapter-synchronizing。 HTML

Watch the google I/O video embedded into that page. 观看嵌入到该页面的google I / O视频。

You should take note that Virgil is suggesting that to use anything other than a sync adapter is just plain wrong. 您应该注意,Virgil建议您使用除同步适配器之外的任何其他工具是完全错误的。 SyncAdapters are simple to implement and the link above also demonstrated how to set one up. SyncAdapters易于实现,上面的链接还演示了如何设置。

A SyncAdapter will take care of re-try attempts and will choose the optimal moment to sync data for your phone. SyncAdapter将负责重试尝试,并将选择最佳时间来同步手机中的数据。 You can schedule sync adapters or you can request an immediate sync, whatever suits your needs. 您可以安排同步适配器,也可以请求立即同步,无论您需要什么。

names and passwords are not saved by the account manager. 名称和密码不会由客户经理保存。 They will; 他们会; be needed by your website or an oauth2 service but the account manager stores the token not credcentials. 是您的网站或oauth2服务所需要的,但客户经理存储令牌而不是凭证。 If the token needs refreshing then the user is shown the account manager login screen and your code is then run to fetch a new auth token. 如果令牌需要刷新,则显示用户帐户管理器登录屏幕,然后运行您的代码以获取新的身份验证令牌。

See http://developer.android.com/training/id-auth/identify.html for more details 有关更多详细信息,请参见http://developer.android.com/training/id-auth/identify.html

My current plan is to save some info to a SQLite DB and check it every time the app is started and take it from there. 我目前的计划是将一些信息保存到SQLite数据库中,并在每次启动应用程序时进行检查,然后从那里获取信息。

You're almost there. 你快到了。 Instead of checking the DB every time the app starts, use an AlarmManager and check the status of the upload every X hours / days. 无需在每次启动应用程序时检查数据库,而是使用AlarmManager并每隔X小时/天检查一次上传状态。 The upload can be initiated by an IntentService . 可以通过IntentService启动上传。

The reason an AlarmManager is better is that the user may choose to keep the app open for days or weeks ! AlarmManager更好的原因是用户可以选择将应用程序保持打开状态数天或数周! With a repeated alarm that runs your database and upload code, you can be certain that the upload attempt will happen at regular intervals. 使用运行您的数据库和上载代码的重复警报,您可以确定上载尝试将定期进行。

Take a look at this related question on scheduling recurring tasks - Scheduling recurring task in Android 看看有关安排重复任务的这个相关问题- 在Android中安排重复任务

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM