2013-04-09 74 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