bvi*_*iyg 2 android android-intent mime-types
我有一项上传文件的特殊服务。上传完成后,我从服务发送了一个广播-包含一个特殊的序列化对象。该对象可能是许多类的实例。为了识别此对象类,我使用了自定义的意图类型。
外观:
// Sending broadcast
Intent intent = new Intent(UploaderService.ACTION_UPLOAD_SUCCESSFULLY);
intent.setType(UploaderService.TYPE_DOC);
intent.putExtra(UploaderService.FIELD_RESULT, object);
context.sendBroadcast(intent);
// Registering receiver
IntentFilter filter = new IntentFilter(UploaderService.ACTION_UPLOAD_SUCCESSFULLY);
filter.addDataType(UploaderService.TYPE_DOC);
registerReceiver(receiver, filter);
Run Code Online (Sandbox Code Playgroud)
在注册接收方时,我抓住了IntentFilter.MalformedMimeTypeException。
TYPE_DOC不变的样子"vnd.com.my.package.doc"。
因此,我想,我的mime类型必须在系统中注册。我如何在代码中做到这一点?
因此,我想,我的mime类型必须在系统中注册。
不,您需要使用有效的MIME类型构造。vnd.com.my.package.doc是格式错误的MIME类型。使用application/vnd.com.my.package.doc一个供应商前缀的MIME类型。
请注意,在广播中使用MIME类型是非常不寻常的行为。
| 归档时间: |
|
| 查看次数: |
2413 次 |
| 最近记录: |