Is it possible to use AWS Android TransferUtility in Service?

こ雲淡風輕ζ 提交于 2019-12-07 21:01:44

问题


The AWS Android SDK for S3 includes classes for data transfers. Namely, the TransferUtility. The TransferUtility seems to create a service for its own use.

Is it possible to use it from a service and in particular set the transfer listener and use it to send updates to application or create notifications from within said service?


回答1:


Yes it's possible to start a service from another service.

TransferUtility may fail to work if its Amazon S3 client gets garbage collected before TransferService gets it. Normally an object is passed as a parcelable in an intent between components. However it's quite complicated to make S3 client parcelable. So the SDK takes an alternate route by passing a weak reference of it stored in a static map. The key is that the caller must keeps the S3 client alive before TransferService gets it.

See https://github.com/aws/aws-sdk-android/issues/86 for more information.




回答2:


Yes, its possible. But there are some steps you need to follow to make it work. You can also add the TransferListener to your TransferUtiltiy object and use that show notification and upload progress.

  1. Use Service instead of IntentService, because when you use TransferUtility.upload... the intent service does not wait for its completion etc and finishes instantly. So use Service class and write the uploading logic in onStartCommand method.

  2. TransferUtility uses a Service named "TransferService". So running this service via TransferUtility from your service you need to put your service and the AWS TransferService in the same process in the manifest like.

    <service
        android:name="com.amazonaws.mobileconnectors.s3.transferutility.TransferService"
        android:enabled="true"
        android:process=":sync" />
    <service
        android:name=".services.UploadService"
        android:enabled="true"
        android:process=":sync" />
    

UplaodService will be your own service that uses the TransferUtility



来源:https://stackoverflow.com/questions/34186504/is-it-possible-to-use-aws-android-transferutility-in-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!