本文整理汇总了Java中android.app.WallpaperManager.setStream方法的典型用法代码示例。如果您正苦于以下问题:Java WallpaperManager.setStream方法的具体用法?Java WallpaperManager.setStream怎么用?Java WallpaperManager.setStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.WallpaperManager
的用法示例。
在下文中一共展示了WallpaperManager.setStream方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setWallpaper
import android.app.WallpaperManager; //导入方法依赖的package包/类
private void setWallpaper() {
try {
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
InputStream inputStream = getContentResolver().openInputStream(imageUri);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Rect croppedRect = getCroppedRect();
wallpaperManager.setStream(inputStream, croppedRect, true);
} else {
wallpaperManager.setStream(inputStream);
}
SubsamplingScaleImageView imageView = findViewById(R.id.imageView);
imageView.recycle();
this.finish();
} catch (IOException | IllegalArgumentException e) {
e.printStackTrace();
Toast.makeText(this, R.string.error, Toast.LENGTH_SHORT).show();
}
}
示例2: toSetWallPage
import android.app.WallpaperManager; //导入方法依赖的package包/类
private void toSetWallPage(Uri data) {
WallpaperManager wallpaperManager = WallpaperManager.getInstance(mActivity);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
File wallpageFile = new File(data.getPath());
Uri contentUri = getImageContentUri(mActivity,wallpageFile.getAbsolutePath());
mActivity.startActivity(wallpaperManager.getCropAndSetWallpaperIntent(contentUri));
}else{
try {
wallpaperManager.setStream(mActivity.getContentResolver().openInputStream(data));
mView.showMsg(MyApplication.getInstance().getString(R.string.set_wallpaper_success));
} catch (IOException e) {
e.printStackTrace();
mView.showMsg(e.getMessage());
}
}
}
示例3: doInBackground
import android.app.WallpaperManager; //导入方法依赖的package包/类
@Override
protected String doInBackground(final Void... params) {
try {
mPhotoPosition = mPhotoAdapter.getPosition();
String url = mPhotoAdapter.getPhotoList().get(mPhotoPosition)
.url;
url = url.replace(".webp", "_o" + ".webp");
WallpaperManager wpm = WallpaperManager
.getInstance(getActivity().getApplicationContext());
InputStream ins = new URL(url).openStream();
wpm.setStream(ins);
return null;
} catch (IOException e) {
return getString(R.string.wallpaper_error);
}
}
示例4: setWallPaper
import android.app.WallpaperManager; //导入方法依赖的package包/类
private static boolean setWallPaper(Context context,String data){
WallpaperManager mWallManager=WallpaperManager.getInstance(context);
try {
File file = Glide.with(context).load(data).downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL).get();
mWallManager.setStream(new FileInputStream(file));
return true;
}
catch (Exception e) {
e.printStackTrace();
return false;
}
}
示例5: onReceive
import android.app.WallpaperManager; //导入方法依赖的package包/类
@Override
public void onReceive(final Context context, Intent intent) {
mPrefs = new PreferenceDao(context);
String action = intent.getAction();
if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
Log.v(TAG, "端末起動完了");
if (mPrefs.isAutoWallpaperEnabled()) {
startPolling(context);
}
} else if (ACTION_CHANGE_WALLPAPER.equals(action)) {
try {
File imageDir = new RequestDownloadImage(context).getImageDir();
// どの画像を表示するのかを選択
String filePath = nextWallpaperPath(imageDir);
if (TextUtils.isEmpty(filePath)) {
// 表示する画像がなかった場合
Log.i(TAG, "壁紙がまだダウンロードされていない");
return;
}
// 壁紙の変更を行う
InputStream wpStream = new FileInputStream(filePath);
WallpaperManager wm = WallpaperManager.getInstance(context);
wm.setStream(wpStream);
wpStream.close();
Log.v(TAG, "壁紙変更完了");
} catch (IOException e) {
Log.e(TAG, "壁紙の変更に失敗", e);
}
}
}
示例6: setStream
import android.app.WallpaperManager; //导入方法依赖的package包/类
public static void setStream(Context context, final InputStream data, Rect visibleCropHint,
boolean allowBackup, int whichWallpaper) throws IOException {
WallpaperManager wallpaperManager = WallpaperManager.getInstance(context);
if (Utilities.ATLEAST_N) {
wallpaperManager.setStream(data, visibleCropHint, allowBackup, whichWallpaper);
} else {
// Fall back to previous implementation (set system)
wallpaperManager.setStream(data);
}
}
示例7: doInBackground
import android.app.WallpaperManager; //导入方法依赖的package包/类
@Override
protected Void doInBackground(Object... objects) {
DisplayMetrics metrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
int height = metrics.heightPixels;
int width = metrics.widthPixels;
WallpaperManager wallpaperManager = WallpaperManager.getInstance(getActivity());
wallpaperManager.setWallpaperOffsetSteps(1, 1);
wallpaperManager.suggestDesiredDimensions(width, height);
try {
String urlWalpaper = urlImage.replace("/r_10000_" + getActivity().getResources().getInteger(R.integer.fragment_movie_fond_height), "/r_" + (width) + "_" + (height));
wallpaperManager.setStream(new URL(urlWalpaper).openStream());
/* Bitmap bmap2 = BitmapFactory.decodeStream(new URL(urlWalpaper).openStream());
DisplayMetrics metrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
int height = metrics.heightPixels;
int width = metrics.widthPixels;
Bitmap bitmap = Bitmap.createScaledBitmap(bmap2, width, height, true);
activity.setWallpaper(bitmap);
// wallpaperManager.setBitmap(bitmap);
*/
} catch (Exception e) {
if (e.getMessage() != null)
e.printStackTrace();
}
return null;
}
示例8: setWallpaper
import android.app.WallpaperManager; //导入方法依赖的package包/类
protected void setWallpaper() {
InputStream inputStream = processImage(mActivityResultData);
WallpaperManager myWallpaperManager
= WallpaperManager.getInstance(getApplicationContext());
try {
myWallpaperManager.setStream(inputStream);
} catch (IOException e) {
e.printStackTrace();
}
}