日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > Android >内容正文

Android

获取壁纸设置背景android,【Android学习】获取Bing 15天前到明天的壁纸,并设置为背景...

發(fā)布時間:2023/12/4 Android 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 获取壁纸设置背景android,【Android学习】获取Bing 15天前到明天的壁纸,并设置为背景... 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

//設(shè)置壁紙

public void setWallpaper() {

new Thread() {

public void run() {

try {

WebImage web = new WebImage(imgRealPath);

Bitmap bmp = web.getBitmap(MainActivity.this);

Message msg = new Message();

msg.obj = bmp;

msg.what = 2;

mHandler.sendMessage(msg);

} catch (Exception e) {

e.printStackTrace();

}

}

}.start();

}

public void Prev(View v)// 前一張

{

if (MyUtils.SelectDay == 15) {

Toast.makeText(this, "您只能預(yù)覽明天到15天前的必應(yīng)壁紙哦,已經(jīng)到最前面的壁紙啦", 300).show();

} else {

MyUtils.SelectDay += 1;

if (MyUtils.SelectDay == 0)

Toast.makeText(this, "今天的壁紙", 300).show();

else

Toast.makeText(this, MyUtils.SelectDay + "天前的壁紙", 300).show();

}

buildPath();

}

//拼接完整的請求地址

public void buildPath() {

path = "http://test.dou.ms/bing/day/" + MyUtils.SelectDay + "/mkt/" + MyUtils.SelectCountry;

gogetImage();

}

public void Next(View v)// 后一張

{

if (MyUtils.SelectDay == -1) {

Toast.makeText(this, "您只能預(yù)覽明天到15天前的必應(yīng)壁紙哦,已經(jīng)到明天的壁紙啦", 300).show();

} else {

MyUtils.SelectDay -= 1;

if (MyUtils.SelectDay == -1)

Toast.makeText(this, "明天的壁紙", 300).show();

else if (MyUtils.SelectDay == 0)

Toast.makeText(this, "今天的壁紙", 300).show();

else

Toast.makeText(this, MyUtils.SelectDay + "天前的壁紙", 300).show();

}

buildPath();

}

public void gogetImage() {

new Thread() {

public void run() {

try {

URL url = new URL(path);

HttpURLConnection conn = (HttpURLConnection) url.openConnection();

conn.setConnectTimeout(5000);

conn.setRequestMethod("GET");

InputStream is = conn.getInputStream();

BufferedInputStream bis = new BufferedInputStream(is);

ByteArrayBuffer baf = new ByteArrayBuffer(50);

int current = 0;

while ((current = bis.read()) != -1) {

baf.append((byte) current);

}

String result = EncodingUtils.getString(baf.toByteArray(), "UTF-8");

String realimgpath = GetBingImageUrl(result);

int code = conn.getResponseCode();

if (code == 200) {

Message msg = new Message();

msg.obj = realimgpath;

msg.what = 1;

mHandler.sendMessage(msg);

}

} catch (Exception e) {

e.printStackTrace();

}

}

}.start();

}

// 截取字符串中 圖片的地址

public static String GetBingImageUrl(String str) {

strArray = str.split("地址:");

return strArray[1];

}

總結(jié)

以上是生活随笔為你收集整理的获取壁纸设置背景android,【Android学习】获取Bing 15天前到明天的壁纸,并设置为背景...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。