public void setBitmap(Bitmap bitmap) throws IOException { try { ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(null); if (fd == null) { return; } FileOutputStream fos = null; try { fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd); bitmap.compress(Bitmap.CompressFormat.PNG, 90, fos); } finally { if (fos != null) { fos.close(); } } } catch (RemoteException e) { // Ignore } }
setStream接口 java
public void setStream(InputStream data) throws IOException { try { ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(null); if (fd == null) { return; } FileOutputStream fos = null; try { fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd); setWallpaper(data, fos); } finally { if (fos != null) { fos.close(); } } } catch (RemoteException e) { // Ignore } }setResource接口
public void setResource(int resid) throws IOException { try { Resources resources = mContext.getResources(); /* Set the wallpaper to the default values */ ParcelFileDescriptor fd = sGlobals.mService.setWallpaper( "res:" + resources.getResourceName(resid)); if (fd != null) { FileOutputStream fos = null; try { fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd); setWallpaper(resources.openRawResource(resid), fos); } finally { if (fos != null) { fos.close(); } } } } catch (RemoteException e) { // Ignore } }
setWallpaper方法 code
private void setWallpaper(InputStream data, FileOutputStream fos) throws IOException { byte[] buffer = new byte[32768]; int amt; while ((amt=data.read(buffer)) > 0) { fos.write(buffer, 0, amt); } }
1 orm