【问题标题】:I need advice for this project [duplicate]我需要这个项目的建议[重复]
【发布时间】:2013-04-10 01:36:32
【问题描述】:
  1. 显示 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;
        }
    }

}

【问题讨论】:

  • 你有什么问题?
  • Removes the wallpaper if the app is uninstalled.这个是不可能的,你的应用在卸载时没有得到回调,因此你当时不能执行任何代码。

标签: android wallpaper


【解决方案1】:

在所需的屏幕尺寸上设置壁纸

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

【讨论】:

  • 这并没有完全起作用,宽度似乎没有任何建议
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-18
  • 1970-01-01
相关资源
最近更新 更多