2015-08-31 31 views
2

最後,我啓動了一個服務,我將要致電該課程並更換我的手機壁紙。如何從活動課外改變android壁紙?

在MainActivity Java文件

我可以只寫>

DisplayMetrics metrics = new DisplayMetrics(); 
    getWindowManager().getDefaultDisplay().getMetrics(metrics); 
    int height = metrics.heightPixels; 
    int width = metrics.widthPixels; 

Bitmap bmap2 = BitmapFactory.decodeResource(getResources(), R.drawable.superman); 
      Bitmap bitmap = Bitmap.createScaledBitmap(bmap2, width, height, true); 

      WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext()); 
      // Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.superman); 
      try { 
       wallpaperManager.setBitmap(bitmap); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 

這個偉大工程......它上傳壁紙和澱粉以適合屏幕

,但我不能用它另一個Java類,

我怎麼做到這一點的另一個Java類,再後來就從我爲myService類打電話了嗎?

+0

任何人都知道答案?請問? –

回答

1

也許不使用getWindowManager,從你的活動外?因爲你不能在活動課外使用它

+0

關閉coures,但沒有人有一個例子?爲了這 ? –