安卓(Android) 怎么Gen应用程序主图标

2019年10月17日22:00:09安卓(Android) 怎么Gen应用程序主图标已关闭评论 290 1462字阅读4分52秒

1.简介

安卓(Android) 怎么Gen应用程序主图标?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */

import java.io.File;
import java.io.FileOutputStream;
import java.util.List;
import org.wolink.app.appcategory.Category.Items;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.PaintDrawable;
import android.net.Uri;
import android.os.Environment;

public class Main{
    public static void genAppMainIcon(Context context) {
        Bitmap bm = Bitmap.createBitmap(72, 72, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bm);
        Drawable d1 = context.getResources().getDrawable(
                R.drawable.icon_back);
        d1.setBounds(new Rect(0, 0, 72, 72));
        d1.draw(canvas);

        d1 = context.getResources().getDrawable(R.drawable.default_folder);
        d1.setBounds(new Rect(0, 0, 72, 72));
        d1.draw(canvas);

        byte[] bmBytes = CategoryInfo.flattenBitmap(bm);
        String state = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(state)) {
            
            File rootDir = Environment.getExternalStorageDirectory();
            File file = new File(rootDir.getPath() + File.separator
                    + "icon.png");
            try {
                file.createNewFile();
                FileOutputStream fos = new FileOutputStream(file);
                fos.write(bmBytes);
                fos.close();
            } catch (Exception e) {

            }
        }
    }
}

 
继续阅读
编程十万个怎么办