Is it possible to use AWS Android TransferUtility

2019-05-23 05:14发布

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?

2条回答
乱世女痞
2楼-- · 2019-05-23 05:17

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.

查看更多
Summer. ? 凉城
3楼-- · 2019-05-23 05:38

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

查看更多
登录 后发表回答