No Activity found to handle Intent : android.intent.action.VIEW
Asked Answered
D

17

141

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?

Disunion answered 4/5, 2011 at 11:30 Comment(2)
Is it because your file is a .3gp and your telling the system to play data that is mp3?Armandarmanda
@Armandarmanda i tried with 3gp bt still the exception is thrownDisunion
K
203

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");
Koehn answered 3/6, 2011 at 9:47 Comment(6)
Superb! The scheme is a must. file:// was missing in my case until I changed Uri.parse() to Uri.fromFile().Crackle
I was getting a problem when the url was encoded, so note you may need to do Uri.parse(Uri.decode(encodedString))Brinkman
If this still doesn't work, don't forget to trim() the URL string. :-)Meander
The browser knows where you at. You need to specify the path if you're calling it directly on app.Petard
what if the url start with file://, and use Uri.fromFile() still doesn't workThisbe
Ensure that there are no spaces in the URL, as this issue can also occur when there are spaces present in the URL.Perishing
E
63

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

Evangelical answered 25/1, 2017 at 10:49 Comment(0)
J
33

This is the right way to do it.

    try
    {
    Intent myIntent = new Intent(android.content.Intent.ACTION_VIEW);
    File file = new File(aFile.getAbsolutePath()); 
    String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(file).toString());
    String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
    myIntent.setDataAndType(Uri.fromFile(file),mimetype);
    startActivity(myIntent);
    }
    catch (Exception e) 
    {
        // TODO: handle exception
        String data = e.getMessage();
    }

you need to import import android.webkit.MimeTypeMap;

Judicative answered 20/6, 2011 at 9:58 Comment(5)
this is the long way to do it :dEnlist
Wrapping that much code in a try block with general exception is usually not a good idea. The behavior here is totally undefined - can you tell which inputs will print a message at a glance? What exceptions will arise, and why? This is a sign of code that has not been tested thoroughly.Waterrepellent
@Waterrepellent If you really expect some specific error to happen more or less regularly it is no exception and should be prevented before. The general exeption is a very good idea to catch them all if you don't really care about the reason and just don't want your app to crash. What exactly is undefined here? The last command in the try block starts the activity. Everything before doesn't matter and will be garbage collected. 6 lines in this try block should be a lot? Really? Don't think so.Mccrory
@TheincredibleJan As a thought experiment, why not wrap 100% of everything we write in a try block, and why isn't it already done for us by default? Exceptions are more or less designed to crash the program to make bugs more visible, unless they are explicitly caught.Waterrepellent
Ensure that there are no spaces in the URL, as this issue can also occur when there are spaces present in the URL.Perishing
D
28

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 *

Delp answered 2/8, 2016 at 7:30 Comment(8)
So how can we handle this situation?Gillies
without a custom test device with a custom ROM, you will have an internet activity. This doesn't sound right at all.Fairy
I am having the same issue being reported by a customer. So it seems that there are some devices on which there is no default internet browser installed. How to solve this?Otology
Catch the error and give an info/dialog/toast that they do not have a working browser?Delp
See a solution #22479711. In this case you will know, whether a device contains a default browser (or an application that processes a Deep link).Jordain
It solved my case, where I was trying to open a .csv file. There was no app installed to handle .csv files, thus the error. To figure it out, I had to temporary change the file extension to something I was sure I had an app to open, .txt, and it worked. So I installed an app which could handle spreadsheets.Delfinadelfine
Ensure that there are no spaces in the URL, as this issue can also occur when there are spaces present in the URL.Perishing
How can someone live without a browser? I have this error on Pixels, Samsung S23 Ultra, and Galaxy Z Fold. They all have default browsers. Only thing they can do is disable the browser. Why would someone do it?Grizzled
L
18

Answer by Maragues made me check out logcat output. Appears that the path you pass to Uri needs to be prefixed with
file:/

Since it is a local path to your storage.

You may want too look at the path itself too.

`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 }`

Mount point seems to appear twice in the full path.

Levin answered 25/8, 2011 at 18:26 Comment(3)
this seems to be right answer, but the question is old and OP was last seen almost 2 months agoKoehn
This is what I did. Sadly, I only read this answer after I found the solutions :)Gregorio
Ensure that there are no spaces in the URL, as this issue can also occur when there are spaces present in the URL.Perishing
S
15

If you don't pass the correct web URL and don't have a browser, ActivityNotFoundException occurs, so check those requirements or handle the exception explicitly. That can resolve your problem.

public static void openWebPage(Context context, String url) {
    try {
        if (!URLUtil.isValidUrl(url)) {
            Toast.makeText(context, " This is not a valid link", Toast.LENGTH_LONG).show();   
        } else {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(url));
            context.startActivity(intent);
        }
    } catch (ActivityNotFoundException e) {
        Toast.makeText(context, " You don't have any browser to open web page", Toast.LENGTH_LONG).show();
    }
}
Stevana answered 1/3, 2018 at 9:15 Comment(1)
Ensure that there are no spaces in the URL, as this issue can also occur when there are spaces present in the URL.Perishing
A
10

Check this useful method:

URLUtil.guessUrl(urlString)

It makes google.com -> http://google.com

Arbe answered 19/12, 2018 at 8:45 Comment(0)
J
7

This exception can raise when you handle Deep linking or URL for a browser, if there is no default installed. In case of Deep linking there may be no application installed that can process a link in format myapp://mylink.

You can use the tangerine solution for API up to 29:

private fun openUrl(url: String) {
    val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
    val activityInfo = intent.resolveActivityInfo(packageManager, intent.flags)
    if (activityInfo?.exported == true) {
        startActivity(intent)
    } else {
        Toast.makeText(
            this,
            "No application that can handle this link found",
            Toast.LENGTH_SHORT
        ).show()
    }
}

For API >= 30 see intent.resolveActivity returns null in API 30.

Jordain answered 23/6, 2020 at 9:7 Comment(1)
Yes! an answer that demonstrates how to handle the issue.Houseman
B
5

To avoid crash below 2 things need to be checked

  1. Check if url starts with http or https
  2. Check if device has any app that can handle url

Kotlin

if (url.startsWith("http") || url.startsWith("https")) {
    Intent(Intent.ACTION_VIEW,Uri.parse(url)).apply{
    // Below condition checks if any app is available to handle intent
    if (resolveActivity(packageManager) != null) {
           startActivity(this)
       }
    }
}
Bristow answered 19/8, 2021 at 7:46 Comment(0)
N
4

I had this same issue, so I was looking at the intent which is logged in LogCat. When viewing the video from the Gallery, it called the same Intent.View intent, but set the Type to "audio/*", which fixed my issue, and doesn't require importing MimeTypeMap. Example:

Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
Uri data = Uri.parse(path);
intent.setDataAndType(data, "audio/*");
startActivity(intent);
Nanci answered 19/12, 2011 at 14:49 Comment(2)
Also works for videos when using intent.setDataAndType(data, "video/*");Eighteen
Ensure that there are no spaces in the URL, as this issue can also occur when there are spaces present in the URL.Perishing
P
4

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());
            }
Proselytism answered 15/12, 2018 at 9:28 Comment(0)
A
3

Had this exception even changed to

"audio/*"

But thanx to @Stan i have turned very simple but usefully solution:

Uri.fromFile(File(content)) instead Uri.parse(path)

 val intent =Intent(Intent.ACTION_VIEW)
                    intent.setDataAndType(Uri.fromFile(File(content)),"audio/*")
                    startActivity(intent)
Attendant answered 23/4, 2018 at 14:17 Comment(0)
L
2

I have two ideas:

First: if you want to play 3gp file you should use mime types "audio/3gpp" or "audio/mpeg"

And second: you can try use method setData(data) for intent without any mime type.

Lanni answered 4/5, 2011 at 11:46 Comment(2)
still the exception 05-04 17:30:30.022: WARN/System.err(4937): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=/mnt/sdcard/audio-android.3gp } is showingDisunion
Is android support your 3gp file? developer.android.com/guide/appendix/media-formats.htmlLanni
L
1

First try this code inside AndroidManifest

  <application>
       
    <uses-library
        android:name="org.apache.http.legacy"
        android:required="false" />
 </application>

If this code works, so fine. But if not. Try this code from which class you want to pass the data or uri.

Intent window = new Intent(getApplicationContext(), Browser.class);
window.putExtra("LINK", "http://www.yourwebsite.com");
startActivity(window);
Luehrmann answered 10/1, 2020 at 12:14 Comment(0)
I
1

instead of using Try and catch. You should use this way

val intent = Intent(Intent.ACTION_VIEW)
                    intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
                    intent.setDataAndType(uri, type)    
startActivity(Intent.createChooser(intent, "view action"))
Ileana answered 7/6, 2021 at 3:52 Comment(0)
S
0

try checking with any Url like add

https://www.google.com

in path and start activity if its works than you are adding wrong path

Stridulate answered 29/7, 2020 at 6:54 Comment(0)
G
0

I had a problem like this case. In my case , it used to happen when I didn't have a browser app in my phone. I installed a browser app and solved my problem. Don't forget to put your code in Try/Catch block.

Gui answered 23/8, 2022 at 6:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.