好的,我正在编辑它,因为我想到了一种更简单的方法,它只是试图实现它。我看到了一些我认为可以工作的代码,将其修改为我需要的,但我遇到了一些问题。需要做的是按钮需要启动下载。
我的代码是 ' /** 当用户单击“获取我的图像”按钮时调用 */ Button viewimagebutton = (Button) findViewById(R.id.imagedownloader); viewimagebutton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v)
{
boolean success = (new File("/sdcard/dirname")).mkdir();
if (!success)
{
Log.w("directory not created", "directory not created");
}
try
{
final String baseUrl = "http://flickholdr.com/";
EditText editText1 = (EditText) findViewById(R.id.pixelw);
EditText editText2 = (EditText) findViewById(R.id.pixelh);
EditText editText3 = (EditText) findViewById(R.id.pixels);
EditText editText4 = (EditText) findViewById(R.id.picnumber);
String baseUrl1 = baseUrl1 + editText1.getText().toString() + "/"
+ editText2.getText().toString() + "/"
+ editText3.getText().toString() + "/"
+ editText4.getText().toString() + "/";
HttpURLConnection connection = (HttpURLConnection) baseUrl1.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
String data1 = String.valueOf(String.format("/sdcard/dirname/%d.jpg",System.currentTimeMillis()));
FileOutputStream stream = new FileOutputStream(data1);
ByteArrayOutputStream outstream = new ByteArrayOutputStream();
myBitmap.compress(Bitmap.CompressFormat.JPEG, 85, outstream);
byte[] byteArray = outstream.toByteArray();
stream.write(byteArray);
stream.close();
Toast.makeText(getApplicationContext(), "Downloading Completed", Toast.LENGTH_SHORT).show();
}
catch (Exception e)
{
e.printStackTrace();
}
}
});
}
;});
};{;}}'
但上线
HttpURLConnection 连接 = (HttpURLConnection) baseUrl1.openConnection();
我收到“未为类型字符串定义方法 openConnection() 的错误。
如果有人可以就出了什么问题提出建议,那就太好了。我将更改文件保存目录的名称。
非常感谢吉姆