我正在尝试在已启动的服务中使用AWS Android SDK for S3.我对SDK和服务都不熟悉.我非常有信心Transfer Utility也在运行服务.
Handler (androID.os.Handler) {11629d87} sending message to a Handler on a dead thread java.lang.IllegalStateException: Handler (androID.os.Handler) {11629d87} sending message to a Handler on a dead thread at androID.os.MessageQueue.enqueueMessage(MessageQueue.java:325) at androID.os.Handler.enqueueMessage(Handler.java:631) at androID.os.Handler.sendMessageAtTime(Handler.java:600) at androID.os.Handler.sendMessageDelayed(Handler.java:570) at sksDoneLater(TransferService.java:189) at com.amazonaws.mobileconnectors.s3.transferutility.TransferService.access0(TransferService.java:44) at com.amazonaws.mobileconnectors.s3.transferutility.TransferService.handleMessage(TransferService.java:166) at androID.os.Handler.dispatchMessage(Handler.java:98) at androID.os.Looper.loop(Looper.java:135) at androID.os.HandlerThread.run(HandlerThread.java:61)
这是我用来启动它的代码:
AmazonS3 amazonS3 = new AmazonS3ClIEnt(credentialsProvIDer); mTransferUtility = new TransferUtility(amazonS3, getApplicationContext()); TransferObserver observer = mTransferUtility.upload( S3_RAW_BUCKET_ARN, mVIDfileKey, mVIDfile); observer.setTransferListener(new TransferListener() {...})
之前它说它无法获得s3客户端.我在上面的应用程序类中创建了客户端,并成功地在一个活动中使用相同的代码来执行成功的传输,因此它必须是我不知道的服务的显而易见的东西.上面的代码在一个从服务中的onStartCommand()调用的方法中调用.
任何帮助将非常感激.
更新 – 请求全班并在此处显示:
public class VIDeoCompressionService extends Service {;private Bus bus;private TransferUtility mTransferUtility;private int mVIDWIDth;private int mVIDHeight;private file mCompressedVIDfile;private file mVIDfile;private String mVIDfileKey;private notificationmanager mnotificationmanager;private androID.support.v4.app.NotificationCompat.Builder mNotification;public VIDeoCompressionService() {}@OverrIDepublic int onStartCommand(Intent intent, int flags, int startID) { if (intent != null) { String realPath = MediaUtils.getRealVIDeoPathFromURI(this.getContentResolver(), intent.getData()); if (realPath != null) { this.mVIDfile = new file(realPath); this.mVIDfileKey = intent.getStringExtra(EXTRA_VID_file_KEY); this.mVIDWIDth = intent.getIntExtra(EXTRA_VID_WIDTH, 0); this.mVIDHeight = intent.getIntExtra(EXTRA_VID_HEIGHT, 0); this.bus = cophotoApplication.getVIDeoCompressionBus(); if (mVIDfile != null && mVIDfile.exists() && mVIDfile.canRead()) { mnotificationmanager = (notificationmanager) this.getSy@R_403_6563@Service(Context.NOTIFICATION_SERVICE); mNotification = new NotificationCompat.Builder(this) .setContentTitle("Compressing VIDeo - Step 1 of 3") .setContentText("Uploading vIDeo for processing...") .setSmallicon(R.drawable.ic_launcher); if (mVIDWIDth == 0 || mVIDHeight == 0) { MediaMetadataRetrIEver mmr = new MediaMetadataRetrIEver(); mmr.setDataSource(mVIDfile.getabsolutePath()); mVIDWIDth = Integer.parseInt(mmr.extractMetadata(MediaMetadataRetrIEver.MetaDATA_KEY_VIDEO_WIDTH)); mVIDHeight = Integer.parseInt(mmr.extractMetadata(MediaMetadataRetrIEver.MetaDATA_KEY_VIDEO_HEIGHT)); mmr.release(); } uploadVIDToS3(); } return Service.START_NOT_STICKY; } else { VIDeoCompressionService.this.stopSelf(); return Service.START_NOT_STICKY; } } else { VIDeoCompressionService.this.stopSelf(); return Service.START_NOT_STICKY; }}@Nullable@OverrIDepublic IBinder onBind(Intent intent) { return null;}private voID uploadVIDToS3() { compressionUploadStarted(); CognitoCachingCredentialsProvIDer credentialsProvIDer = new CognitoCachingCredentialsProvIDer( getApplicationContext(), "*********ID HERE********", // IDentity Pool ID Regions.US_EAST_1 // Region ); AmazonS3 amazonS3 = new AmazonS3ClIEnt(credentialsProvIDer); mTransferUtility = new TransferUtility(amazonS3, getApplicationContext()); TransferObserver observer = mTransferUtility.upload( S3_RAW_BUCKET_ARN, mVIDfileKey, mVIDfile); observer.setTransferListener(new TransferListener() { @OverrIDe public voID onStateChanged(int ID, TransferState state) { if (state == TransferState.COMPLETED) { compressionUploadFinished(true); ZencodeVIDeo(mVIDfileKey); } else if (state == TransferState.Failed) { compressionUploadFinished(false); } } @OverrIDe public voID onProgressChanged(int ID, long bytesCurrent, long bytesTotal) { int progress = Math.round(100 * ((float) bytesCurrent / bytesTotal)); String progresspercentage = String.valueOf(progress) + "%"; compressionUploadProgress(progress, progresspercentage); } @OverrIDe public voID one rror(int ID, Exception ex) { compressionUploadFinished(false); } });}private voID compressionUploadStarted() { bus.post(new CompressionUploadStartedEvent()); updateNotification();}private voID compressionUploadProgress(int progress, String progresspercentage) { bus.post(new CompressionUploadProgressEvent(progress, progresspercentage)); mNotification.setProgress(100, progress, false); updateNotification();}private voID compressionUploadFinished(boolean successfully) { bus.post(new CompressionUploadFinishedEvent(successfully)); if (successfully) { mNotification.setContentText("Upload complete"); } else { mNotification.setContentTitle("Compression Failed"); mNotification.setContentText("Upload Failed. Please try again later."); } updateNotification(); if (!successfully) { VIDeoCompressionService.this.stopSelf(); }}private voID updateNotification() { mnotificationmanager.notify(NOTIFICATION_ID, mNotification.build());}
解决方法:
我发现自己处于同样的问题……
这就是为我解决的问题:
我注意到我在Manifest中注册的SyncAdapter有以下服务:
<service androID:name=".sync.SyncService" androID:exported="true" androID:process=":sync"> <intent-filter> <action androID:name="androID.content.SyncAdapter"/> </intent-filter> <Meta-data androID:name="androID.content.SyncAdapter" androID:resource="@xml/syncadapter" /> </service>
androID:process =“:sync”告诉服务在名为:sync的私有进程中运行
所以我只是告诉Amazon SDK的TransferService在同一个线程中运行.
<service androID:name="com.amazonaws.mobileconnectors.s3.transferutility.TransferService" androID:process=":sync" androID:enabled="true" />
在那之后,我没有得到错误TransferService无法获得s3客户端,它将停止,最后能够将我的图片上传到S3
总结以上是内存溢出为你收集整理的Android AWS S3 SDK TransferUtility在服务中不起作用全部内容,希望文章能够帮你解决Android AWS S3 SDK TransferUtility在服务中不起作用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)