Java 如何使用广播接收器使纸张适合屏幕?

Java 如何使用广播接收器使纸张适合屏幕?,java,android,eclipse,broadcastreceiver,Java,Android,Eclipse,Broadcastreceiver,我正在制作一个墙纸应用程序,你有一堆照片,你选择的成为你的手机墙纸,一切正常,除了我重新启动手机时墙纸放大,我无法修复它,因为我无法让它选择用户选择的照片。我所能做的就是让它只适用于第一张照片,但我无法为其他照片执行。有人能告诉我该怎么做吗 以下是我尝试过的: 我的主要活动: static int tophone; ImageView display; public static Integer[] tophone2 = { R.drawable.iv1,R.drawable.iv2,R.

我正在制作一个墙纸应用程序,你有一堆照片,你选择的成为你的手机墙纸,一切正常,除了我重新启动手机时墙纸放大,我无法修复它,因为我无法让它选择用户选择的照片。我所能做的就是让它只适用于第一张照片,但我无法为其他照片执行。有人能告诉我该怎么做吗

以下是我尝试过的: 我的主要活动:

 static int tophone;
 ImageView display;
 public static Integer[] tophone2 = {
R.drawable.iv1,R.drawable.iv2,R.drawable.iv3,R.drawable.iv4 };


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);

tophone = R.drawable.iv1;
display = (ImageView) findViewById(R.id.IView);
ImageView image1 = (ImageView) findViewById(R.id.iv1);
ImageView image2 = (ImageView) findViewById(R.id.iv2);
ImageView image3 = (ImageView) findViewById(R.id.iv3);
ImageView image4 = (ImageView) findViewById(R.id.iv4);
Button setWp = (Button) findViewById(R.id.setWp);

Picasso.with(MainActivity.this).load(R.drawable.iv1_s).into(image1);
Picasso.with(MainActivity.this).load(R.drawable.iv2_s).into(image2);
Picasso.with(MainActivity.this).load(R.drawable.iv3_s).into(image3);
Picasso.with(MainActivity.this).load(R.drawable.iv4_s).into(image4);


image1.setOnClickListener(this);
image2.setOnClickListener(this);
image3.setOnClickListener(this);
image4.setOnClickListener(this);
setWp.setOnClickListener(this);
}

 @Override
 public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()){
case R.id.iv1:
    display.setImageResource(R.drawable.iv1);
    tophone = tophone2[0];
    break;
case R.id.iv2:
    display.setImageResource(R.drawable.iv2);
    tophone = tophone2[1];
    break;
case R.id.iv3:
    display.setImageResource(R.drawable.iv3);
    tophone = tophone2[2];
    break;
case R.id.iv4:
    display.setImageResource(R.drawable.iv4);
    tophone = tophone2[3];
    break;
case R.id.setWp:
    Toast WpSet = Toast.makeText(MainActivity.this,"Wallpaper Set", Toast.LENGTH_SHORT);

    SharedPreferences       sharedPreferences = getSharedPreferences("wallpaperapp",0);
    sharedPreferences.edit().putInt("position",0).commit();

    DisplayMetrics metrics = new DisplayMetrics(); 
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int height = metrics.heightPixels; 
    int width = metrics.widthPixels;
    Bitmap tempbitMap = BitmapFactory.decodeResource(getResources(), tophone);
    Bitmap bitmap = Bitmap.createScaledBitmap(tempbitMap,width,height, true);
    WallpaperManager wallpaperManager = WallpaperManager.getInstance(MainActivity.this); 
    wallpaperManager.setWallpaperOffsetSteps(1, 1);
    wallpaperManager.suggestDesiredDimensions(width, height);
    try {
      wallpaperManager.setBitmap(bitmap);
      } catch (IOException e) {
      e.printStackTrace();
    }
    WpSet.show();
    break;
 }



 }

 }
和我的广播接收器:

 public class BootReceiver extends BroadcastReceiver {
 private static final String TAG="BootReceiver";

@Override public void onReceive(Context context,Intent intent){
try{ 
SharedPreferences       sharedPreferences =   context.getSharedPreferences("wallpaperapp",0);
int position= sharedPreferences.getInt("position", 0);
    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    windowManager.getDefaultDisplay().getMetrics(metrics);
            int height = metrics.heightPixels;
            int width = metrics.widthPixels;
            Bitmap tempbitMap =  BitmapFactory.decodeResource(context.getResources(),MainActivity.tophone2[position]);
                Bitmap bitmap = Bitmap.createScaledBitmap(tempbitMap,width,height, true);
            WallpaperManager wallpaperManager = WallpaperManager.getInstance(context);
            wallpaperManager.setWallpaperOffsetSteps(1, 1);
            wallpaperManager.suggestDesiredDimensions(width, height);
            try {
              wallpaperManager.setBitmap(bitmap);
              } catch (IOException e) {
              e.printStackTrace();
            }
}catch(Exception e){
Log.e(TAG,e.toString());
}
}
}