我是java新手,我正在开发一个连接到ftp服务器的android应用程序。我遇到了问题,因为我不知道我需要向AndroidManifest.xml添加什么权限。我也有问题因为我无法让它连接到服务器。MainActivity.java :
package com.mycompany.myapp;
import android.app.*;
import android.os.*;
import it.sauronsoftware.ftp4j.FTPClient;
import android.widget.*;
import it.sauronsoftware.ftp4j.*;
import java.io.*;public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
FTPClient client = new FTPClient();
try
{
client.connect("192.168.1.1", 21);
client.login("root", "root");
Toast.makeText(getApplicationContext(),"Connected!",Toast.LENGTH_SHORT).show();
}
catch (FTPException e)
{}
catch (IllegalStateException e)
{}
catch (IOException e)
{}
catch (FTPIllegalReplyException e)
{}
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.myapp" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
主.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">