当前位置: 首页>>代码示例>>Java>>正文


Java WallpaperManager.setBitmap方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:appgramming,项目名称:LoneColor-Android,代码行数:21,代码来源:ColorWallpaper.java

示例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;
}
 
开发者ID:PitchedApps,项目名称:Material-Glass,代码行数:19,代码来源:ApplyWallpaper.java

示例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();
    }
}
 
开发者ID:Technologx,项目名称:Fire-Bird-Dashboard-for-Zooper,代码行数:27,代码来源:DetailActivity.java

示例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();
    }
}
 
开发者ID:dkanada,项目名称:frost,代码行数:12,代码来源:WallpaperSetActivity.java

示例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;
    }
}
 
开发者ID:NicoLiutong,项目名称:miaosou,代码行数:32,代码来源:ComicReadFragment.java

示例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();
        }
    }
 
开发者ID:coolspan,项目名称:LiveWallpaper,代码行数:19,代码来源:MainActivity.java

示例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();
    }
}
 
开发者ID:alepacheco,项目名称:AndroRW,代码行数:12,代码来源:Helper.java

示例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();
    }
}
 
开发者ID:wavever,项目名称:GankLock,代码行数:9,代码来源:PhotoUtil.java

示例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;
}
 
开发者ID:VernonLee,项目名称:Theogony,代码行数:15,代码来源:SetWallpaperTask.java

示例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();
    }
}
 
开发者ID:robertmathew,项目名称:KeralaAttractions,代码行数:13,代码来源:DetailActivity.java

示例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();
                }
            }
        }
    }
}
 
开发者ID:boybeak,项目名称:BeMusic,代码行数:31,代码来源:PlayDetailActivity.java

示例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();
    }
}
 
开发者ID:glesik,项目名称:wpgen,代码行数:15,代码来源:ColorsActivity.java

示例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);
    }
}
 
开发者ID:danielgimenes,项目名称:NasaPic,代码行数:10,代码来源:SpacePicInteractor.java

示例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;
		}
	}
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:64,代码来源:WallpaperDisposeActivity.java

示例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;
}
 
开发者ID:enricocid,项目名称:Gallery-example,代码行数:18,代码来源:ApplyWallpaper.java


注:本文中的android.app.WallpaperManager.setBitmap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。