Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8994107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:20:59+00:00 2026-06-15T23:20:59+00:00

I am trying to open any arbitrary file using Intents. However, I get the

  • 0

I am trying to open any arbitrary file using Intents. However, I get the ActivityNotFoundException for file types for which there are installed apps that can open them. In the source below, when file points to a PNG file, I get the “Complete action using” dialog. However, when I try to open an mp3, I get the exception. When I open Astro and click on the same mp3 file, I get the “Complete action using” dialog showing the installed MP3 players. How do I get the same dialog to show up from my code? The file location, extension, and MIME type all look correct when I inspect them from the debugger.

      String url = file.toURL().toString();
      String extension = MimeTypeMap.getFileExtensionFromUrl(url);
      String type = typeMap.getMimeTypeFromExtension(extension);
      mimeType.setText(type);
      boolean fileExists = file.exists();
      Intent viewIntent = new Intent(Intent.ACTION_VIEW);
      viewIntent.setData(Uri.fromFile(file));
      viewIntent.setType(type);
      MainActivity.this.startActivity(viewIntent);

The answer is that Intent.setType and Intent.setData are mutually exclusive. Calling one clears out the other. So calling setDataAndType is the fix.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:21:00+00:00Added an answer on June 15, 2026 at 11:21 pm

    Try this:

            Intent newIntent = new Intent();
            newIntent.setDataAndType(Uri.parse("file://"+filePath),mimeType);
            newIntent.setAction(Intent.ACTION_VIEW);
            try {
    
                startActivity(newIntent);
    
            } catch (android.content.ActivityNotFoundException e) {
                Toast.makeText(getApplicationContext(), "No handler for this type of file.", 4000).show();
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any recommended way to open a file using Symfony? I'm trying to
Is there any open-source software that is trying to implement and emulate the human
I'm trying to open a zip file with jython using FileInputStream and ZipInputStream. But
I am trying to open an output file which I am sure has a
I'm trying to open a file using fopen, and I am getting the error:
I'm trying to open a file in GAE that was retrieved using urlfetch() .
I am trying open a new window using url.Action. And the new Window url
I am trying open a very large file in Emacs and it fails to
I´m trying to open a tab using jquery, here is my code: $(#ecContenedorFolders).tabs({ tabTemplate:
I'm trying to open a file for input in Excel with this line :

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.