2013-04-09 75 views
0
  1. 显示s JPEG图像。
  2. 在图像上显示一个按钮,允许用户将图像设置为墙纸。
  3. 将图像自动调整为用户特定的Android手机显示尺寸。
  4. 卸载应用程序后移除壁纸。

我可以做第1步和第2步很容易我只是坚持其他两个步骤任何人都可以指向正确的方向。 这里是到目前为止的代码我需要此项目的建议

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; 
     } 
    } 

} 
+0

你的问题是什么? – Pragnani 2013-04-09 16:54:41

+1

'如果应用程序已卸载,则删除墙纸.'这是不可能的,您的应用程序在卸载时不会收到回调,因此您当时不能执行任何代码。 – FoamyGuy 2013-04-09 17:09:44

回答

0

设置所需的屏幕尺寸

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(); 
} 

墙纸和第四个问题请参考this

+0

这没有完全工作的宽度似乎没有工作任何意见,因为 – user2211271 2013-04-09 20:32:28