好的,我正在编辑这个,因为我想到了一个更简单的方法,它只是试图实现它。我已经看到了一些我认为可以工作的代码,将其修改为我需要的代码但是我遇到了一些问题。需要做的是按钮需要启动下载。
我的代码是'/ **当用户点击获取我的图像按钮时调用* / 按钮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 connection =(HttpURLConnection)baseUrl1.openConnection();
我收到错误“”类型字符串未定义方法openConnection()。
如果有人可以告诉我哪里出了问题会很棒。我将更改文件保存目录的名称。
非常感谢 吉姆
答案 0 :(得分:0)
将字符串传递给新活动
Intent intent = new Intent(this, ToClass.class);
intent.putExtra("url", "http://..");
startActivity(i);
Intent intent = getIntent();
String url = intent.getExtras().getString("url");