是的,我看过一大堆教程,问题等,但没有一个有效,所以我不需要更多链接,我只需要修复我当前的代码..
到目前为止,我有这个:
public class FullscreenActivity extends Activity {
protected int[] mThumbIds;
@SuppressWarnings("unused")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fullscreen);
// get intent data
Intent i = getIntent();
// Selected image id
final int position = i.getExtras().getInt("id");
ImageAdapter imageAdapter = new ImageAdapter(this);
ImageView imageView = (ImageView) findViewById(R.id.full_image_view);
Button SetWallpaper = (Button)findViewById(R.id.setwallpaper);
imageView.setImageResource(imageAdapter.mThumbIds[position]);
}
private Object[] imageIDs;
private int position;
public void onClick(View arg0) {
try {
WallpaperManager.getInstance(this).setResource((Integer) imageIDs[position]);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
但是当我选择了图片后单击按钮时,它什么也没做?
我也有清单中的许可,但它仍然无效,所以任何帮助都会非常感激
谢谢
我不确定这与它有什么关系,但我在三星Galaxy S4上测试应用程序
答案 0 :(得分:0)
可能是它可以联系起来..
package com.Engr.android;
import java.io.IOException;
import java.io.InputStream;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
public class Camera extends Activity implements View.OnClickListener
{
ImageButton ib;
ImageView iv;
Button btn;
Intent i;
final static int cameraData = 0;
Bitmap bmp;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.photo);
Buttons();
InputStream is = getResources().openRawResource(R.drawable.ic_launcher);
bmp = BitmapFactory.decodeStream(is);
}
private void Buttons()
{
ib = (ImageButton) findViewById(R.id.ibtnTakePic);
iv = (ImageView) findViewById(R.id.ivReturnPic);
btn = (Button) findViewById(R.id.btnSetWall);
btn.setOnClickListener(this);
ib.setOnClickListener(this);
}
@SuppressWarnings("deprecation")
@Override
public void onClick(View v) {
switch(v.getId())
{
case R.id.btnSetWall:
try {
getApplicationContext().setWallpaper(bmp);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
case R.id.ibtnTakePic:
i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, cameraData);
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if(resultCode==RESULT_OK)
{
Bundle extras = data.getExtras();
bmp = (Bitmap) extras.get("data");
iv.setImageBitmap(bmp);
}
}
}