No Activity found to handle Intent : android.inten

2019-01-06 11:20发布

This is my code to play the recorded audio 3gp file

 Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
        Uri data = Uri.parse(path);
        intent.setDataAndType(data, "audio/mp3");
        startActivity(intent);

But while running it in my HTC device (Android 2.2 Froyo) shows an exception:

05-04 16:37:37.597: WARN/System.err(4065): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=/mnt/sdcard/mnt/sdcard/audio-android.3gp typ=audio/mp3 }
05-04 16:37:37.597: WARN/System.err(4065):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1567)
05-04 16:37:37.597: INFO/ActivityManager(92): Starting activity: Intent { act=android.intent.action.VIEW dat=/mnt/sdcard/mnt/sdcard/audio-android.3gp typ=audio/mp3 }
05-04 16:37:37.607: WARN/System.err(4065):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1537)
05-04 16:37:37.607: WARN/System.err(4065):     at android.app.Activity.startActivityForResult(Activity.java:2858)
05-04 16:37:37.607: WARN/System.err(4065):     at android.app.Activity.startActivity(Activity.java:2964)
05-04 16:37:37.607: WARN/System.err(4065):     at com.ey.camera.AudioRecorder.playAudio(AudioRecorder.java:244)
05-04 16:37:37.607: WARN/System.err(4065):     at com.ey.camera.AudioRecorder$4.onClick(AudioRecorder.java:225)
05-04 16:37:37.607: WARN/System.err(4065):     at android.view.View.performClick(View.java:2408)
05-04 16:37:37.607: WARN/System.err(4065):     at android.view.View$PerformClick.run(View.java:8817)
05-04 16:37:37.607: WARN/System.err(4065):     at android.os.Handler.handleCallback(Handler.java:587)
05-04 16:37:37.607: WARN/System.err(4065):     at android.os.Handler.dispatchMessage(Handler.java:92)
05-04 16:37:37.607: WARN/System.err(4065):     at android.os.Looper.loop(Looper.java:144)
05-04 16:37:37.607: WARN/System.err(4065):     at android.app.ActivityThread.main(ActivityThread.java:4937)
05-04 16:37:37.607: WARN/System.err(4065):     at java.lang.reflect.Method.invokeNative(Native Method)
05-04 16:37:37.607: WARN/System.err(4065):     at java.lang.reflect.Method.invoke(Method.java:521)
05-04 16:37:37.607: WARN/System.err(4065):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-04 16:37:37.607: WARN/System.err(4065):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-04 16:37:37.607: WARN/System.err(4065):     at dalvik.system.NativeStart.main(Native Method)

In Galaxy tablet it's working fine. How can I resolve this issue?

11条回答
Summer. ? 凉城
2楼-- · 2019-01-06 11:31

For me when trying to open a link :

Uri uri = Uri.parse("https://www.facebook.com/abc/");
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                startActivity(intent);

I got the same error android.content.ActivityNotFoundException: No Activity found to handle Intent

The problem was because i didnt have any app that can open URLs (i.e. browsers) installed in my phone. So after Installing a browser the problem was solved.

*Lesson : Make sure there is at least one app which handles the intent you are calling *

查看更多
干净又极端
3楼-- · 2019-01-06 11:31

check this useful method

URLUtil.guessUrl(urlString)

it makes google.com -> http://goolge.com

查看更多
爷的心禁止访问
4楼-- · 2019-01-06 11:32

Url addresses must be preceded by http://

Uri uri = Uri.parse("www.google.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);

throws an ActivityNotFoundException. If you prepend "http://", problem solved.

Uri uri = Uri.parse("http://www.google.com");

May not help OP, but I ended up here searching for the same exception and maybe it helps others.

查看更多
戒情不戒烟
5楼-- · 2019-01-06 11:34

If you have these error in your logcat then use these code it help me

 Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.fromFile(new File(data.getLocation())), "audio/*");
            try {
                context.startActivity(intent);
            } catch (ActivityNotFoundException e) {
                Log.d("error", e.getMessage());
            }

also

   Intent intent = new Intent(MediaStore.INTENT_ACTION_MUSIC_PLAYER);
            intent.setDataAndType(Uri.fromFile(new File(data.getLocation())), "audio/*");
            try {
                context.startActivity(intent);
            } catch (ActivityNotFoundException e) {
                Log.d("error", e.getMessage());
            }
查看更多
聊天终结者
6楼-- · 2019-01-06 11:46

If you are also getting this error when trying to open a web page from your android app it is because your url looks like this:

www.google.com

instead of: https://www.google.com or http://www.google.com

add this code to your Activity/Fragment:

 public void openWebPage(String url) {

    Uri webpage = Uri.parse(url);

    if (!url.startsWith("http://") && !url.startsWith("https://")) {
        webpage = Uri.parse("http://" + url);
    }

    Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }
}

just pass your url to openWebPage(). If it is already prefixed with https:// or http:// then you are good to go, else the if statement handles that for you

查看更多
登录 后发表回答