我在Android和工作,通過攝像頭捕捉的照片應用程序新設置爲wallpaper.Here的代碼:拍照與Android相機,並將其設置爲牆紙
public class camera extends Activity implements View.OnClickListener {
private ImageButton imgb;
private ImageView imgv;
private Button b;
Intent i;
static int cameraData =0;
Bitmap bmp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.image);
cleaning();
InputStream is=getResources().openRawResource(R.drawable.ic_launcher);
bmp=BitmapFactory.decodeStream(is);
}
private void cleaning() {
imgb=(ImageButton) findViewById(R.id.imgbutt);
imgv=(ImageView) findViewById(R.id.iv);
b=(Button) findViewById(R.id.butt);
imgb.setOnClickListener(this);
b.setOnClickListener(this);
}
@Override
public void onClick(View arg0) {
switch(arg0.getId()){
case R.id.imgbutt:
i=new Intent (android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, cameraData);
break;
case R.id.butt :
try {
getApplicationContext().setWallpaper(bmp);
} catch (IOException e) {
e.printStackTrace();
}
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode==RESULT_OK){
Bundle extras=data.getExtras();
bmp=(Bitmap) extras.get("data");
imgv.setImageBitmap(bmp);
}
}
}
的問題是每當我點擊「拍照」按鈕時我收到一個錯誤說: 應用程序意外停止