我可以做的步骤1和2 pretty的方便我只是坚持与其他两个步骤,任何人都可以点我在正确的方向。 这里是code到目前为止
公共类MainActivity扩展活动实现OnClickListener {
ImageView的IV;
按钮B;
我的意图;
BMP位图;
@覆盖
保护无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_main);
初始化();
InputStream的是= getResources()openRawResource(R.drawable.image)。
BMP = BitmapFactory.de codeStream(是);
}
私人无效初始化(){
IV =(ImageView的)findViewById(R.id.ivReturnedPic);
B =(按钮)findViewById(R.id.bSetWallpaper);
b.setOnClickListener(本);
}
@覆盖
公共布尔onCreateOptionsMenu(功能菜单){
//充气菜单;这增加了项目操作栏,如果它是present。
。getMenuInflater()膨胀(R.menu.main,菜单);
返回true;
}
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
开关(v.getId()){
案例R.id.bSetWallpaper:
尝试 {
getApplicationContext()setWallpaper(BMP)。
}赶上(IOException异常E){
e.printStackTrace();
}
打破;
}
}
}
解决方案
设置壁纸所需的屏幕尺寸
WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplication());
INT高= myWallpaperManager.getDesiredMinimumHeight();
INT宽度= myWallpaperManager.getDesiredMinimumWidth();
尝试 {
myWallpaperManager.setBitmap(Bitmap.createScaledBitmap(setAs,宽度,高度,真));
}赶上(最终IOException异常E){
Toast.makeText(getApplication(),错误设置壁纸,Toast.LENGTH_SHORT).show();
}
和第四个问题,请参阅这个
Shows s JPEG image. Display a button over the image that allows the user to set the image to their wallpaper. Auto resizes the image to the users specific Android phone display size. Removes the wallpaper if the app is uninstalled.I can do step 1 and 2 pretty easy i'm just stuck with the other two steps can anyone point me in the right direction. here is the code so far
public class MainActivity extends Activity implements OnClickListener {
ImageView iv;
Button b;
Intent i;
Bitmap bmp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initialize();
InputStream is = getResources().openRawResource(R.drawable.image);
bmp = BitmapFactory.decodeStream(is);
}
private void initialize(){
iv = (ImageView) findViewById(R.id.ivReturnedPic);
b = (Button) findViewById(R.id.bSetWallpaper);
b.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.bSetWallpaper:
try {
getApplicationContext().setWallpaper(bmp);
} catch (IOException e) {
e.printStackTrace();
}
break;
}
}
}
解决方案
to set the wallpaper on the desired screen size
WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplication());
int height = myWallpaperManager.getDesiredMinimumHeight();
int width = myWallpaperManager.getDesiredMinimumWidth();
try {
myWallpaperManager.setBitmap(Bitmap.createScaledBitmap(setAs, width , height , true));
} catch (final IOException e) {
Toast.makeText(getApplication(), "Error setting wallpaper", Toast.LENGTH_SHORT).show();
}
and for the fourth question please refer to this