Java Code Examples for android.app.WallpaperManager#setBitmap()

The following examples show how to use android.app.WallpaperManager#setBitmap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: wallpaper.java    From cordova-plugin-wallpaper with Apache License 2.0 8 votes vote down vote up
public void echo(String image, Boolean base64, Context context)
{
	try
	{
		AssetManager assetManager = context.getAssets();
		Bitmap bitmap;
		if(base64) //Base64 encoded
		{
			byte[] decoded = android.util.Base64.decode(image, android.util.Base64.DEFAULT);
			bitmap = BitmapFactory.decodeByteArray(decoded, 0, decoded.length);
		}
		else //normal path
		{
			InputStream instr = assetManager.open("www/" + image);
			bitmap = BitmapFactory.decodeStream(instr);
		}
		WallpaperManager myWallpaperManager = WallpaperManager.getInstance(context);
		myWallpaperManager.setBitmap(bitmap);
		Log.d("console", "homescreen wallpaper set");
	}
	catch (IOException e)
	{
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
Example 2
Source File: DetailActivity.java    From Dashboard with MIT License 6 votes vote down vote up
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();
    }
}
 
Example 3
Source File: DetailActivity.java    From Dashboard with MIT License 6 votes vote down vote up
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();
    }
}
 
Example 4
Source File: WallpaperSetActivity.java    From frost with GNU General Public License v3.0 5 votes vote down vote up
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();
    }
}
 
Example 5
Source File: MainActivity.java    From LiveWallpaper with Apache License 2.0 5 votes vote down vote up
/**
     * 使用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);

            // 已过时的Api
//            setWallpaper(wallpaperBitmap);
//            setWallpaper(getResources().openRawResource(R.raw.girl));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
Example 6
Source File: SetupService.java    From astrobee_android with Apache License 2.0 5 votes vote down vote up
protected void onHandleIntent(final Intent intent) {
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.astrobee_logo_modified_background);
    WallpaperManager manager = WallpaperManager.getInstance(getApplicationContext());

    Rect cropHints = new Rect(630, 0, 2250, 1620);

    try {
        manager.setBitmap(bitmap, cropHints, false);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 7
Source File: PhotoUtil.java    From GankLock with GNU General Public License v3.0 5 votes vote down vote up
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();
    }
}
 
Example 8
Source File: SetWallpaperTask.java    From Theogony with MIT License 5 votes vote down vote up
@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;
}
 
Example 9
Source File: LockScreenWallPaper.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint("WrongConstant")
public static void setBitmap(final Bitmap bitmap) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        try {
            final WallpaperManager wallpaperManager = WallpaperManager.getInstance(xdrip.getAppContext());
            final Bitmap wallpaper = BitmapUtil.getTiled(bitmap, getScreenWidth(), getScreenHeight(), isLockScreenBitmapTiled(), Pref.getString(NumberWallPreview.ViewModel.PREF_numberwall_background, null));
            wallpaperManager.setBitmap(wallpaper, null, false, FLAG_LOCK);
            wallpaper.recycle();
        } catch (Exception e) {
            UserError.Log.e(TAG, "Failed to set wallpaper: " + e);
        }
    }
}
 
Example 10
Source File: LockScreenWallPaper.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint("WrongConstant")
public static void setBitmap(final Bitmap bitmap) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        try {
            final WallpaperManager wallpaperManager = WallpaperManager.getInstance(xdrip.getAppContext());
            final Bitmap wallpaper = BitmapUtil.getTiled(bitmap, getScreenWidth(), getScreenHeight(), isLockScreenBitmapTiled(), Pref.getString(NumberWallPreview.ViewModel.PREF_numberwall_background, null));
            wallpaperManager.setBitmap(wallpaper, null, false, FLAG_LOCK);
            wallpaper.recycle();
        } catch (Exception e) {
            UserError.Log.e(TAG, "Failed to set wallpaper: " + e);
        }
    }
}
 
Example 11
Source File: PlayDetailActivity.java    From BeMusic with Apache License 2.0 5 votes vote down vote up
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();
                }
            }
        }
    }
}
 
Example 12
Source File: wallpaper.java    From cordova-plugin-wallpaper with Apache License 2.0 5 votes vote down vote up
public void setlockwp(String image, Boolean base64, Context context)
{
	try
	{
		AssetManager assetManager = context.getAssets();
		Bitmap bitmap;
		if(base64) //Base64 encoded
		{
			byte[] decoded = android.util.Base64.decode(image, android.util.Base64.DEFAULT);
			bitmap = BitmapFactory.decodeByteArray(decoded, 0, decoded.length);
		}
		else //normal path
		{
			InputStream instr = assetManager.open("www/" + image);
			bitmap = BitmapFactory.decodeStream(instr);
		}
		if (android.os.Build.VERSION.SDK_INT>=24) {
			WallpaperManager ujWallpaperManager = WallpaperManager.getInstance(context);
			ujWallpaperManager.setBitmap(bitmap, null, true, WallpaperManager.FLAG_LOCK);
			Log.d("console", "lockscreen wallpaper set");
		}
	}
	catch (IOException e)
	{
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
Example 13
Source File: ApplyWallpaper.java    From Gallery-example with GNU General Public License v3.0 4 votes vote down vote up
@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;
}
 
Example 14
Source File: WallpaperDisposeActivity.java    From android-project-wo2b with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
		}
	}
}