sumanth
sumanth

Reputation: 145

How to solve "No activity found to handle intent" exception?

I'm writing an Android FTP server program. I need to select files to send to client, so I need a file chooser and I wrote this code:

Java:

Intent filechooser= new Intent(Intent.ACTION_GET_CONTENT);

    filechooser.addCategory("*/*");
    filechooser.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
    startActivityForResult(filechooser, 10);

XML:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sender">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".Chooser"></activity>
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
</manifest>

I get a No activity found to handle intent exception.

Upvotes: 0

Views: 162

Answers (1)

DHAVAL A.
DHAVAL A.

Reputation: 2321

You are using wrong file category(/). It should be a type instead of category.

If you want to choose any file from storage you need code like below.

private void showFileChooser() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 
    intent.setType("*/*"); 
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    try {
        startActivityForResult(
                Intent.createChooser(intent, "Select a File to Upload"),
                FILE_SELECT_CODE);
    } catch (android.content.ActivityNotFoundException ex) {
        // Potentially direct the user to the Market with a Dialog
        Toast.makeText(this, "Please install a File Manager.", 
                Toast.LENGTH_SHORT).show();
    }
}

Source: here

Upvotes: 1

Related Questions