http://blog.163.com/lixiaodaoaaa@126/blog/static/349948682012419112330446/

package mldn.lxd.SetWallPaperTest;

import java.io.IOException;
import java.io.InputStream;

import android.app.Activity;
import android.media.SoundPool.OnLoadCompleteListener;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.widget.ImageView;
import android.widget.Toast;

public class SetWallPaperActivity extends Activity {
   
   
   private ImageView imageView = null;
   
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        imageView = (ImageView)super.findViewById(R.id.myImg);
        imageView.setOnLongClickListener(new myImageOnLongClickListener());
    }
    
    private final class myImageOnLongClickListener implements OnLongClickListener
    {
      @Override
      public boolean onLongClick(View v)
      {
         try
         {
            SetWallPaperActivity.this.clearWallpaper();
         } catch (IOException e)
         {
            Toast.makeText(getApplicationContext(),"清空桌面背景失败,请稍后再试",Toast.LENGTH_LONG).show();
            e.printStackTrace();
         }
         InputStream  myImagInputStream = imageView.getResources().openRawResource(R.drawable.mydesttop);
         try
         {
            SetWallPaperActivity.this.setWallpaper(myImagInputStream);
            Toast.makeText(getApplicationContext(),"恭喜你设置成功!!",Toast.LENGTH_LONG).show();
         } catch (IOException e)
         {
            // TODO Auto-generated catch block
            Toast.makeText(getApplicationContext(),"设置桌面图标失败,请稍后再试",Toast.LENGTH_LONG).show();
            e.printStackTrace();
         }
         return false;
      }
    }
    
}
桌面成功设置了。嘎嘎看如下

更多相关文章

  1. Android(安卓)Path的使用
  2. CentOS 安装 Android
  3. Android开发人员不得不收集的代码
  4. 【Android(安卓)】零基础到飞升 | TextView(文本框)详解
  5. android WebView解析 调用html5页面
  6. Android中如何实现EditText的自动换行
  7. android 动态 布局
  8. Android(安卓)OpenGL 画简单的三角形
  9. android:设置密码隐藏与显示

随机推荐

  1. 【Android布局】在程序中设置android:gra
  2. 四大布局 使用详解
  3. Android(安卓)系统属性 Property
  4. android gradle plugin 1.3.0 以上使用 p
  5. Android中bindService的使用及Service生
  6. android使用全局变量的两种方法
  7. Android
  8. RelativeLayout的常用属性
  9. android之调用webservice 实现图片上传
  10. pygame for android汉字显示问题