如何使用ACTION_VIEW

时间:2017-12-15 16:57:57

标签: android gluon gluon-mobile

我正在开发类似于电子邮件客户端的应用程序。视图“A”是单击消息时显示消息详细信息的消息列表以及作为视图“B”的附件列表。单击其中一个附件时,通过ACTION_VIEW打开一个新的Intent(查看'C')。

单击Android中的后退按钮后,我无法返回到消息详细信息视图“B”。 (需要多次点击才能返回) 回来后,ListView的附件没有响应点击次数。

这就是我发布Intent的方式

    @Override
public void openFile(String absoluteFilePath) {
    try
{
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
File file = new File(absoluteFilePath);
String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(file).toString());
String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
intent.setDataAndType(Uri.fromFile(file),mimetype);
FXActivity.getInstance().startActivityForResult(intent, 36); 
FXActivity.getInstance().setOnActivityResultHandler((requestCode, resultCode, data)
    -> {         
             if (requestCode == 36) {

                 try {
                 SwtichViewHelper.switchToPrevious();
                 } catch(Exception e) {
                     System.out.println(e.getMessage());
                 }

             }
 }); 
}
catch (Exception e)
{
}

    }

单击返回时输出,直到看到视图B

12-15 12:56:19.910 28138 28138 V FXActivity: onActivityResult with requestCode 36 and resultCode = 0 and intent = null
12-15 12:56:19.910 28138 28138 I System.out: result code ****** 36
12-15 12:56:19.910 28138 28138 I System.out: result code  36  handler******
12-15 12:56:19.912 28138 28138 I System.out: This operation is permitted on the event thread only; currentThread = main
12-15 12:56:19.912 28138 28138 V FXActivity: onActivityResult with requestCode 36 and resultCode = 0 and intent = null
12-15 12:56:19.912 28138 28138 I System.out: result code ****** 36
12-15 12:56:19.912 28138 28138 I System.out: result code  36  handler****** 
12-15 12:56:19.913 28138 28138 V FXActivity: onRestart
12-15 12:56:19.915 28138 28138 V FXActivity: onStart
12-15 12:56:19.915 28138 28138 V FXActivity: onResume
12-15 12:56:19.915 28138 28163 I System.out: Application is resumed.**************************
12-15 12:56:19.926 28138 28138 V FXEntity: Surface created.
每次失败后都会出现

错误:

2-15 13:19:09.268  1539 19855 E ActivityManager: Sending non-protected broadcast com.motorola.motocare.INTENT_TRIGGER from system 3963:com.motorola.process.system/1000 pkg com.motorola.motgeofencesvc
12-15 13:19:09.268  1539 19855 E ActivityManager: java.lang.Throwable
12-15 13:19:09.268  1539 19855 E ActivityManager:       at com.android.server.am.ActivityManagerService.broadcastIntentLocked(ActivityManagerService.java:18226)
12-15 13:19:09.268  1539 19855 E ActivityManager:       at com.android.server.am.ActivityManagerService.broadcastIntent(ActivityManagerService.java:18826)
12-15 13:19:09.268  1539 19855 E ActivityManager:       at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:512)
12-15 13:19:09.268  1539 19855 E ActivityManager:       at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2906)
12-15 13:19:09.268  1539 19855 E ActivityManager:       at android.os.Binder.execTransact(Binder.java:565)
12-15 13:19:09.290  1539  4670 E ActivityManager: Sending non-protected broadcast com.motorola.motocare.INTENT_TRIGGER from system 3963:com.motorola.process.system/1000 pkg com.motorola.motgeofencesvc
12-15 13:19:09.290  1539  4670 E ActivityManager: java.lang.Throwable
12-15 13:19:09.290  1539  4670 E ActivityManager:       at com.android.server.am.ActivityManagerService.broadcastIntentLocked(ActivityManagerService.java:18226)
12-15 13:19:09.290  1539  4670 E ActivityManager:       at com.android.server.am.ActivityManagerService.broadcastIntent(ActivityManagerService.java:18826)
12-15 13:19:09.290  1539  4670 E ActivityManager:       at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:512)
12-15 13:19:09.290  1539  4670 E ActivityManager:       at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2906)
12-15 13:19:09.290  1539  4670 E ActivityManager:       at android.os.Binder.execTransact(Binder.java:565)
12-15 13:19:09.356  6284  6284 I GoogleInputMethod: onFinishInput() : Dummy InputConnection bound

0 个答案:

没有答案