可能重複:
Android - how to set the wallpaper image我想在android.Is中以編程方式將當前壁紙更改爲另一個壁紙嗎?
我想改變當前壁紙到另一個編程中android.Is可能我做的一個項目,這取決於壁紙自動改變條件由用戶設置
可能重複:
Android - how to set the wallpaper image我想在android.Is中以編程方式將當前壁紙更改爲另一個壁紙嗎?
我想改變當前壁紙到另一個編程中android.Is可能我做的一個項目,這取決於壁紙自動改變條件由用戶設置
首先在AndroidManifest.xml
文件中添加此權限
<uses-permission android:name="android.permission.SET_WALLPAPER">
的main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:layout_margin="20dp"
android:id="@+id/set"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Set WallPaper" />
<ImageView
android:layout_margin="20dp"
android:id="@+id/preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
然後下面是Java代碼,你要實現哪些:
public class SetWallpaper extends Activity {
Bitmap bitmap;
int lastImageRef;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button buttonSetWallpaper = (Button)findViewById(R.id.set);
ImageView imagePreview = (ImageView)findViewById(R.id.ic_launcher);
imagePreview.setImageResource(R.drawable.five);
buttonSetWallpaper.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
WallpaperManager myWallpaperManager
= WallpaperManager.getInstance(getApplicationContext());
try {
myWallpaperManager.setResource(R.drawable.ic_launcher);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}});
}
}
是的你indeed can。
public void setStream (InputStream data)
改變當前系統壁紙到一個特定的字節流。給InputStream 複製到持久存儲中,現在將作爲壁紙使用 。目前它必須是JPEG或PNG 圖片。成功時,廣播意圖ACTION_WALLPAPER_CHANGED。 參數
data包含要作爲壁紙安裝的原始數據的流。
我猜它已經回答了d at http://stackoverflow.com/questions/1964193/android-how-to-set-the-wallpaper-image – the100rabh 2012-03-27 03:55:22