本文整理汇总了Java中android.app.WallpaperManager.setBitmap方法的典型用法代码示例。如果您正苦于以下问题:Java WallpaperManager.setBitmap方法的具体用法?Java WallpaperManager.setBitmap怎么用?Java WallpaperManager.setBitmap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.WallpaperManager
的用法示例。
在下文中一共展示了WallpaperManager.setBitmap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setColorWallpaper
import android.app.WallpaperManager; //导入方法依赖的package包/类
/**
* Create a color filled bitmap and changes the current system wallpaper to this bitmap.
*/
public static void setColorWallpaper(Context context, int color) throws IOException {
// Get the Wallpaper Manager
final WallpaperManager wpManager = WallpaperManager.getInstance(context);
// Create the pitch black bitmap
final Bitmap pitchBlackBitmap = createColorBitmap(color, MIN_SAFE_SIZE, MIN_SAFE_SIZE);
// Set the wallpaper
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// On Android N and above use the new API to set both the general system wallpaper and
// the lock-screen-specific wallpaper
wpManager.setBitmap(pitchBlackBitmap, null, true, WallpaperManager.FLAG_SYSTEM | WallpaperManager.FLAG_LOCK);
} else {
wpManager.setBitmap(pitchBlackBitmap);
}
}
示例2: doInBackground
import android.app.WallpaperManager; //导入方法依赖的package包/类
@Override
protected Boolean doInBackground(Void... params) {
WallpaperManager wm = WallpaperManager.getInstance(context.get());
Boolean worked;
try {
try {
wm.setBitmap(scaleToActualAspectRatio(resource));
} catch (OutOfMemoryError ex) {
if (ShowcaseActivity.DEBUGGING)
Utils.showLog(context.get(), "OutOfMemoryError: " + ex.getLocalizedMessage());
showRetrySnackbar();
}
worked = true;
} catch (IOException e2) {
worked = false;
}
return worked;
}
示例3: handleCrop
import android.app.WallpaperManager; //导入方法依赖的package包/类
private void handleCrop(int resultCode, Intent result) {
if (resultCode == RESULT_OK) {
mImageView.setImageURI(Crop.getOutput(result));
WallpaperManager myWallpaperManager = WallpaperManager
.getInstance(getApplicationContext());
try {
Bitmap mBitmap = getImageBitmap();
myWallpaperManager.setBitmap(mBitmap);
Toast.makeText(DetailActivity.this, "Wallpaper set",
Toast.LENGTH_SHORT).show();
} catch (IOException e) {
Toast.makeText(DetailActivity.this,
"Error setting wallpaper", Toast.LENGTH_SHORT)
.show();
}
} else if (resultCode == Crop.RESULT_ERROR) {
Toast.makeText(this, Crop.getError(result).getMessage(), Toast.LENGTH_SHORT).show();
}
}
示例4: setWallpaper
import android.app.WallpaperManager; //导入方法依赖的package包/类
public void setWallpaper(View v) {
WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext());
try {
wallpaperManager.setBitmap(Wallpaper);
Toast toast = Toast.makeText(this, "wallpaper set", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
} catch (IOException e) {
e.printStackTrace();
}
}
示例5: onClick
import android.app.WallpaperManager; //导入方法依赖的package包/类
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which){
case 0:
boolean saveSuccess = false;
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
String[] permissions = {Manifest.permission.WRITE_EXTERNAL_STORAGE};
if(ContextCompat.checkSelfPermission(getActivity(), permissions[0]) != PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions(getActivity(),permissions,0);
}else {
saveSuccess = savePicture(pictureBitmap);
}
}else {
saveSuccess = savePicture(pictureBitmap);
}
if(saveSuccess){
Toast.makeText(getActivity(),"图片已存储在 /miaosou/picture 文件夹下",Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(getActivity(),"图片保存失败,请检查SD卡读写权限是否开启",Toast.LENGTH_SHORT).show();
}
break;
case 1:
WallpaperManager wallpaperManager = WallpaperManager.getInstance(getContext());
try {
wallpaperManager.setBitmap(pictureBitmap);
} catch (IOException e) {
e.printStackTrace();
}
break;
}
}
示例6: onSetWallpaperForBitmap
import android.app.WallpaperManager; //导入方法依赖的package包/类
/**
* 使用Bitmap设置壁纸
* 直接设置为壁纸,不会有任何界面和弹窗出现
* 壁纸切换,会有动态的渐变切换
*
* @param view
*/
public void onSetWallpaperForBitmap(View view) {
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
try {
Bitmap wallpaperBitmap = BitmapFactory.decodeResource(getResources(), R.raw.girl);
wallpaperManager.setBitmap(wallpaperBitmap);
// setWallpaper(wallpaperBitmap);
// setWallpaper(getResources().openRawResource(R.raw.girl));
} catch (IOException e) {
e.printStackTrace();
}
}
示例7: changeWallPaper
import android.app.WallpaperManager; //导入方法依赖的package包/类
public static void changeWallPaper(Context ctx, int drawableResource){
WallpaperManager myWallpaperManager
= WallpaperManager.getInstance(ctx);
try {
Bitmap bitmap = BitmapFactory.decodeResource(ctx.getResources(), drawableResource);
myWallpaperManager.setBitmap(bitmap);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例8: setWallPaper
import android.app.WallpaperManager; //导入方法依赖的package包/类
public static void setWallPaper(Context context,File file){
WallpaperManager manager = WallpaperManager.getInstance(context);
try {
manager.setBitmap(BitmapFactory.decodeFile(file.getAbsolutePath()));
} catch (IOException e) {
e.printStackTrace();
}
}
示例9: doInBackground
import android.app.WallpaperManager; //导入方法依赖的package包/类
@Override
protected Boolean doInBackground(Bitmap... params) {
Bitmap bitmap = params[0];
try {
if (bitmap != null) {
WallpaperManager wallpaperManager = WallpaperManager.getInstance(mContext);
wallpaperManager.setBitmap(bitmap);
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
示例10: onPostExecute
import android.app.WallpaperManager; //导入方法依赖的package包/类
@Override
protected void onPostExecute(Bitmap bitmap) {
WallpaperManager wallpaperManager = WallpaperManager.getInstance(mContext);
try {
wallpaperManager.setBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
} finally {
Toast.makeText(mContext, getString(R.string.msg_wallpaper_set), Toast.LENGTH_SHORT).show();
materialDialog.dismiss();
}
}
示例11: setWallpaper
import android.app.WallpaperManager; //导入方法依赖的package包/类
private void setWallpaper () {
WallpaperManager manager = WallpaperManager.getInstance(this);
boolean canSetWallpaper = true;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
canSetWallpaper &= manager.isWallpaperSupported();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
canSetWallpaper &= manager.isSetWallpaperAllowed();
}
if (canSetWallpaper) {
Song song = PlayManager.getInstance(this).getCurrentSong();
if (song != null) {
Album album = song.getAlbumObj();
if (album == null) {
return;
}
File source = new File(album.getAlbumArt());
if (source.exists()) {
Bitmap bmp = BitmapFactory.decodeFile(source.getAbsolutePath());
try {
manager.setBitmap(bmp);
} catch (IOException e) {
e.printStackTrace();
} finally {
bmp.recycle();
}
}
}
}
}
示例12: setBitmapAsWallpaper
import android.app.WallpaperManager; //导入方法依赖的package包/类
public void setBitmapAsWallpaper(WallpaperManager wpManager, Bitmap wallpaperBitmap) {
try {
// Set wallpaper.
wpManager.setBitmap(wallpaperBitmap);
// Write to temp file (to enable saving).
File tempfile = new File(this.getFilesDir(), "lastwlp.png");
FileOutputStream outStream = new FileOutputStream(tempfile);
wallpaperBitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
// Enable Save menu option if inactive.
invalidateOptionsMenu();
} catch (IOException e) {
e.printStackTrace();
}
}
示例13: undoLastWallpaperChangeSync
import android.app.WallpaperManager; //导入方法依赖的package包/类
public void undoLastWallpaperChangeSync() throws IOException {
Bitmap bitmap = retrieveLastWallpaper();
if (bitmap != null) {
WallpaperManager wallpaperMgr = WallpaperManager.getInstance(
contextWeakReference.get());
wallpaperMgr.setWallpaperOffsetSteps(0.5f, 1.0f);
wallpaperMgr.setBitmap(bitmap);
}
}
示例14: setWallpaperNow
import android.app.WallpaperManager; //导入方法依赖的package包/类
/**
* Set wallpaper
*/
private void setWallpaperNow(Bitmap source) throws IOException
{
DisplayMetrics dm = CommonUtils.getDisplayMetrics(this);
int status_bar_height = CommonUtils.getStatusBarHeight(this);
getWindowManager().getDefaultDisplay().getMetrics(dm);
int screenWidth = dm.widthPixels;
int screenHeight = dm.heightPixels - status_bar_height;
int bitmapWidth = source.getWidth();
int bitmapHeight = source.getHeight();
float scaleX = (screenWidth + 0.0f) / bitmapWidth;
float scaleY = (screenHeight + 0.0f) / bitmapHeight;
Log.D(TAG, "[scaleX=" + scaleX + ", scaleY=" + scaleY + "]");
Bitmap tempBitmap = null;
Bitmap targetBitmap = null;
try
{
// 按比例缩放达到适配手机屏幕
// targetBitmap = Bitmap.createBitmap(screenWidth, screenHeight,
// Config.ARGB_8888);
Matrix matrix = new Matrix();
matrix.postScale(scaleX, scaleY);
tempBitmap = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
Log.D(TAG, "TargetBitmap: [width=" + tempBitmap.getWidth() + ", height=" + tempBitmap.getHeight() + "]");
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
targetBitmap = Bitmap.createBitmap(screenWidth * 3, screenHeight, Config.ARGB_8888);
Canvas canvas = new Canvas(targetBitmap);
canvas.drawColor(Color.RED);
canvas.drawBitmap(tempBitmap, 0, 0, null);
canvas.drawBitmap(tempBitmap, screenWidth, 0, null);
canvas.drawBitmap(tempBitmap, screenWidth * 2, 0, null);
wallpaperManager.setBitmap(targetBitmap);
showToastOnUiThread(R.string.hint_wallpaper_ok);
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
if (tempBitmap != null && !tempBitmap.isRecycled())
{
tempBitmap.recycle();
tempBitmap = null;
}
if (targetBitmap != null && !targetBitmap.isRecycled())
{
targetBitmap.recycle();
targetBitmap = null;
}
}
}
示例15: doInBackground
import android.app.WallpaperManager; //导入方法依赖的package包/类
@Override
protected Void doInBackground(Void... params) {
try {
final WallpaperManager wallpaperManager = WallpaperManager.getInstance(activity);
Bitmap bitmap = MediaStore.Images.Media.getBitmap(activity.getContentResolver(), Uri.fromFile(new File(url)));
wallpaperManager.setBitmap(bitmap);
} catch (IOException ex) {
ex.printStackTrace();
}
return null;
}