本文整理匯總了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();
}
}