Hello guys so I modified the earlier code(Camera app) to be able to change the wallpaper at the homescreen. I should mention that you have to add permission for changing wallpaper:
<uses-permission android:name="android.permission.SET_WALLPAPER"/>
Change it at the android manifest. You may also consider changing the orientation to portrait. The code for changing the wallpaper is
getApplicationContext().setWallpaper(bmp);
It should be surrounded with try-catch statements.
So now the final app looks like:
ps/ that isnt me in the photo.
Finally the code:
package com.learning.gilo;
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.ImageView;
public class Camera extends Activity implements View.OnClickListener{
Button wall,take;
ImageView pic;
Intent i;
int cameraData = 0;
Bitmap bmp;
protected void onCreate(Bundle b){
super.onCreate(b);
setContentView(R.layout.camera);
InputStream is = getResources().openRawResource(R.drawable.back_mao);
bmp = BitmapFactory.decodeStream(is);
wall = (Button) findViewById(R.id.bSet);
take = (Button) findViewById(R.id.bTake);
pic = (ImageView) findViewById(R.id.ivImage);
wall.setOnClickListener(this);
take.setOnClickListener(this);
}
public void onClick(View v){
switch(v.getId()){
case R.id.bSet:
try {
getApplicationContext().setWallpaper(bmp);
Toast.makeText(getApplicationContext(), "This is a toast that will say \"Wallpaper set\"", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
}
break;
case R.id.bTake:
i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i,cameraData);
break;
}
}
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");
pic.setImageBitmap(bmp);
}
}
}