1
我几乎完成了我的应用程序,即时通讯上的菜单项工作现在, 的问题是设置一个位图作为墙纸和保存它从菜单项SD卡。位图:在SD卡设置壁纸和保存在菜单项
我想的东西,第一个是创造它正在采取从以前的活动-again-同样的数据的意图,-I有失败 -
用同样的意图第二-i已经失败 -
这是我的代码。
谢谢
public class Fullpic extends Activity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// menu
getMenuInflater().inflate(R.layout.menu_pics, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.menu_set:
// setting as wallpaper
return true;
case R.id.menu_save:
// save the image on sdcard
return true;
case R.id.menu_back:
return true;
default:
return super.onOptionsItemSelected(item);
}
}
//menu end
// XML node keys
static final String KEY_THUMB_URL = "source";
static final String HEIGHT_MAX = "600";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_single_pic);
// getting intent data
Intent in = getIntent();
// Get XML values from previous intent dude
String bid = in.getStringExtra(KEY_THUMB_URL);
int hoppa= Integer.parseInt(in.getStringExtra(HEIGHT_MAX));
// Displaying all values on the screen
ImageView balls = (ImageView) findViewById(R.id.bals_label);
balls.getLayoutParams().height = hoppa-30;
URL url = null;
try {
url = new URL(bid);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Bitmap bmp = null;
try {
bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
balls.setImageBitmap(bmp);
}
public Object fetch(String address) throws MalformedURLException,
IOException {
URL url = new URL(address);
Object content = url.getContent();
return content;
}
private Drawable ImageOperations(Context ctx, String url) {
try {
InputStream is = (InputStream) this.fetch(url);
Drawable d = Drawable.createFromStream(is, "source");
return d;
} catch (MalformedURLException e) {
return null;
} catch (IOException e) {
return null;
}
}
}
我不知道是你有困难哪方面,如果只是下载您可以创建从InputStream您制作绘制对象时创建一个新的文件并将其保存到所需的位置后,将图像保存。 – kabuto178
@ kabuto178你能帮我吗?我真的不能 – LikePod
这是你想要做什么? – kabuto178