这是我的代码:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_PICK);
// FTP URL (Starts with ftp://, sftp:// or ftps:// followed by hostname and port).
Uri ftpUri = Uri.parse("ftp://ftp.myserver.com:21");
intent.setDataAndType(ftpUri, "vnd.android.cursor.dir/lysesoft.andftp.uri");
// FTP credentials (optional)
intent.putExtra("ftp_username", "user");
intent.putExtra("ftp_password", "pass");
//intent.putExtra("ftp_keyfile", "/sdcard/dsakey.txt");
//intent.putExtra("ftp_keypass", "optionalkeypassword");
// FTP settings (optional)
intent.putExtra("ftp_pasv", "true");
//intent.putExtra("ftp_resume", "true");
//intent.putExtra("ftp_encoding", "UTF8");
// Upload
intent.putExtra("command_type", "upload");
// Activity title
intent.putExtra("progress_title", "Uploading folder ...");
intent.putExtra("local_file1", "/sdcard/DCIM/try");
// Optional initial remote folder (it must exist before upload)
//intent.putExtra("remote_folder", "remotefolder/uploadedfolder");
startActivityForResult(intent, 2);
logcat的:
03-07 17:27:49.471: W/dalvikvm(13281): threadid=1: thread exiting with uncaught exception (group=0x415c87c0)
03-07 17:27:49.471: E/AndroidRuntime(13281): FATAL EXCEPTION: main
03-07 17:27:49.471: E/AndroidRuntime(13281): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.whatsappxr/com.example.whatsappxr.MainActivity}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.PICK dat=ftp://ftp.attracto.tk:21 typ=vnd.android.cursor.dir/lysesoft.andftp.uri (has extras) }
03-07 17:27:49.471: E/AndroidRuntime(13281): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2339)
03-07 17:27:49.471: E/AndroidRuntime(13281): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
03-07 17:27:49.471: E/AndroidRuntime(13281): at android.app.ActivityThread.access$600(ActivityThread.java:153)
03-07 17:27:49.471: E/AndroidRuntime(13281): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1269)
03-07 17:27:49.471: E/AndroidRuntime(13281): at android.os.Handler.dispatchMessage(Handler.java:99)
03-07 17:27:49.471: E/AndroidRuntime(13281): at android.os.Looper.loop(Looper.java:137)
03-07 17:27:49.471: E/AndroidRuntime(13281): at android.app.ActivityThread.main(ActivityThread.java:5289)
03-07 17:27:49.471: E/AndroidRuntime(13281): at java.lang.reflect.Method.invokeNative(Native Method)
03-07 17:27:49.471: E/AndroidRuntime(13281): at java.lang.reflect.Method.invoke(Method.java:525)
03-07 17:27:49.471: E/AndroidRuntime(13281): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
03-07 17:27:49.471: E/AndroidRuntime(13281): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
03-07 17:27:49.471: E/AndroidRuntime(13281): at dalvik.system.NativeStart.main(Native Method)
03-07 17:27:49.471: E/AndroidRuntime(13281): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.PICK dat=ftp://ftp.attracto.tk:21 typ=vnd.android.cursor.dir/lysesoft.andftp.uri (has extras) }
03-07 17:27:49.471: E/AndroidRuntime(13281): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1632)
03-07 17:27:49.471: E/AndroidRuntime(13281): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
03-07 17:27:49.471: E/AndroidRuntime(13281): at android.app.Activity.startActivityForResult(Activity.java:3390)
03-07 17:27:49.471: E/AndroidRuntime(13281): at android.app.Activity.startActivityForResult(Activity.java:3351)
03-07 17:27:49.471: E/AndroidRuntime(13281): at com.example.whatsappxr.MainActivity.onCreate(MainActivity.java:37)
03-07 17:27:49.471: E/AndroidRuntime(13281): at android.app.Activity.performCreate(Activity.java:5133)
03-07 17:27:49.471: E/AndroidRuntime(13281): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-07 17:27:49.471: E/AndroidRuntime(13281): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2293)
03-07 17:27:49.471: E/AndroidRuntime(13281): ... 11 more
我该怎么做才能让它发挥作用?
答案 0 :(得分:0)
线索在例外描述中:
引起:android.content.ActivityNotFoundException:无活动 发现处理Intent {act = android.intent.action.PICK DAT = ftp://ftp.attracto.tk:21 typ = vnd.android.cursor.dir / lysesoft.andftp.uri(有额外内容)}
在Android中,您可以指定选择特定Intent的Intent
处理程序,在这种情况下android.intent.action.PICK
意图使用ftp://
网址架构
如果您的应用程序确实接受了此类Intent
,则应用程序将被打开并正确处理您的情况。
所以你想要处理用户没有安装有效应用程序的情况。
您可以使用此方法确定是否将处理意图,并且只有在返回true时才会继续:
public static boolean isIntentAvailable(Context context, Intent intentToCheck) {
final PackageManager packageManager = context.getPackageManager();
List<ResolveInfo> list =
packageManager.queryIntentActivities(intentToCheck,
PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
}
您可以更深入地了解Intents在Android here中的工作方式。