我已将一些代码从普通方法移至 AsyncTask doInBackground 方法,除了文件读取器外,一切正常。我得到“无法解决上下文”。我已经尝试完全删除“context.getApplicationContext()”,但这只是让我“对于 AlarmReceiver.backgroundputFTP 类型的方法 openFileInput(String) 未定义”。请问有人有什么想法吗?
public void putFTP(Context context)
{
new backgroundputFTP().execute();
}
private class backgroundputFTP extends AsyncTask< Void, Void,Void >
{
@Override
protected Void doInBackground(Void... params)
{
//
// Push query result text file to FTP server
//
FTPClient client = new FTPClient();
FileInputStream fis = null;
Looper.prepare();
try {
client.connect(ipAddress);
client.enterLocalPassiveMode();
client.login(user, pass);
//
// Create an InputStream of the file to be uploaded
//
filename = "sdcardstats.txt";
fis = context.getApplicationContext().openFileInput(filename);