Android开发:已经发布的APP,如何更改启动图片
来源:广州软件开发 编辑:广州软件开发公司 日期:2017-04-21
1、首先,用一个接口访问网络,下载新的启动画面的图片,我用的是ImageView里面的一张画面来实现的,代码如下:
-
View tempView = mGridView.getChildAt(0);
-
ImageView imageView = (ImageView) tempView
-
.findViewById(R.id.gv_image_detail);
-
File file = ImageUtils.saveSplashImageToSdCard(imageView);
-
2、把取到的图片存储在本地目录:
-
public static final File saveSplashImageToSdCard(ImageView image) {
-
boolean success = false;
-
String imageName = "splash.jpg";
-
File storeDir = AppData.getContext().getExternalFilesDir(null);
-
File imageFile = new File(storeDir, imageName);
-
F.makeLog(imageFile.toString());
-
BitmapDrawable drawable = (BitmapDrawable) image.getDrawable();
-
FileOutputStream outStream;
-
Bitmap bitmap = drawable.getBitmap();
-
try {
-
outStream = new FileOutputStream(imageFile);
-
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
-
// 100 to keep full quality of the image
-
outStream.flush();
-
outStream.close();
-
success = true;
-
} catch (FileNotFoundException e) {
-
e.printStackTrace();
-
} catch (IOException e) {
-
e.printStackTrace();
-
}
-
if (success) {
-
// Toast.makeText(getApplicationContext(), "Image saved with success",
-
// Toast.LENGTH_LONG).show();
-
F.makeLog("success save to sd card");
-
UserInfo.saveSplashPath(imageFile.toString());
-
return imageFile;
-
} else {
-
return null;
-
}
-
}
3、建立一个sharepreference,保存存储的路劲和更新启动画面的判断;
-
public static void saveSplashPath(String msg) {
-
SharedPreferences sharedPreferences = AppData.getContext()
-
.getSharedPreferences(USER_INFO_TAG, Context.MODE_PRIVATE);
-
SharedPreferences.Editor editor = sharedPreferences.edit();
-
editor.putString(FILE_TAG, msg);
-
editor.putBoolean(SPLASH_TAG, true);
-
editor.commit();
-
}
-
-
public static boolean isSplashImageChange() {
-
SharedPreferences sharedPreferences = AppData.getContext()
-
.getSharedPreferences(USER_INFO_TAG, Context.MODE_PRIVATE);
-
boolean change = sharedPreferences.getBoolean(SPLASH_TAG, false);
-
return change;
-
}
-
-
public static String getSplashImagePath() {
-
SharedPreferences sharedPreferences = AppData.getContext()
-
.getSharedPreferences(USER_INFO_TAG, Context.MODE_PRIVATE);
-
String path = sharedPreferences.getString(FILE_TAG, "0");
-
return path;
-
}
-
4、最后一步就是在启动画面的时候,判断是否有新的启动图片,有的话,显示新的启动图片:
-
if (UserInfo.isSplashImageChange()) {
-
String file = UserInfo.getSplashImagePath();
-
F.makeLog(file.toString());
-
// F.makeToast(file.toString());
-
Bitmap bitmap = BitmapFactory.decodeFile(file);
-
imageView.setImageBitmap(bitmap);
-
}
这样就可以实现更新启动图片了。
相关阅读