[英]Fatal Exception: android.content.ActivityNotFoundException: No Activity found to handle Intent
[英]How to solve “No activity found to handle intent” exception?
我正在編寫一個Android FTP服務器程序。 我需要選擇要發送給客戶端的文件,所以我需要一個文件選擇器,並編寫了以下代碼:
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>
我No activity found to handle intent
異常的活動。
您使用了錯誤的文件類別( / )。 它應該是類型而不是類別。
如果要從存儲中選擇任何文件,則需要如下代碼。
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();
}
}
資料來源: 這里
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.