简体   繁体   English

打开文件android时活动未找到异常

[英]Activity Not FOund Exception While Opening File android

I'm getting this exception 我收到这个例外

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 }

I'm trying to open this file via these code : 我正在尝试通过以下代码打开此文件:

    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);
                            }

Make sure the data and type you are sending in intnt.setDataAndType(Uri.fromFile(fl) , type); 确保要发送的数据和类型为intnt.setDataAndType(Uri.fromFile(fl) , type); is correct, seems like the Intent.ACTION_VIEW do not have any match for that intent data and hence there's no activity to handle that intent... 是正确的,似乎Intent.ACTION_VIEW与该Intent数据不匹配,因此没有活动可处理该Intent ...

Regards! 问候!

将活动添加到mainfist.xml可能会帮助您

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM