java - 打开文件时未找到 Activity 异常 android

标签 java android android-intent

我遇到了这个异常

06-28 21:00:48.792: W/System.err(10272): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///mnt/sdcard/01 - 3G - Kaise Bataaoon [SongsPK.info] (2).mp3 typ=audio/mpeg }

我正在尝试通过以下代码打开此文件:

    File sdCard = Environment.getExternalStorageDirectory();

                            Intent intnt = new Intent(Intent.ACTION_VIEW);

                            String ext = fileToOpen.substring(fileToOpen.lastIndexOf('.')+1) ;
                            //Intent j = Intent.createChooser(intnt, "Choose an application to open with:");
                            //startActivity(j);
                            File fl = new File(sdCard.getAbsolutePath()+"/"+ fileToOpen);
                            if(fl.exists())
                            {
                                Log.d("FILEMANAGERACTIVITY",fl.getPath() + "0"+ ext);
                                MimeTypeMap mim = MimeTypeMap.getSingleton();
                                String type= mim.getMimeTypeFromExtension(ext);
                                intnt.setDataAndType(Uri.fromFile(fl) , type);
                                startActivity(intnt);
                            }

最佳答案

确保您在 intnt.setDataAndType(Uri.fromFile(fl) , type); 中发送的数据和类型正确,似乎 Intent.ACTION_VIEW 没有任何匹配项 Intent 数据,因此没有 Activity 来处理该 Intent ...

问候!

关于java - 打开文件时未找到 Activity 异常 android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17369183/

相关文章:

java - 如何避免 GeneratedSerializationConstructorAccessor 问题?

java - JScrollPane:垂直条可见但不活动

java - docx4j 中的斜体(强调)段落

Android:如果最初的 Activity 不是从启动器启动的,则通知开始新 Activity 而不是恢复旧 Activity

Android:在我的应用程序中播放 youtube 视频

java - 将文本文件读入构造函数数组(java)

android - 改造 "IllegalStateException: Already executed"

android - 如何在 Kotlin Android 中为数据类创建空构造函数

android - 使用动画让图像扩展到 View 中

java - Android onConfigurationChanged 不起作用