Android工具类搜集

1.检测图片是否被加工过 

/**

     *
     * @param 图片路径
     * @param 检验的数据集
     * @return
     */
    public static String checkImagePs(String path, List<String> psKey) {
        File file = new File(path);
        if (!file.exists()) return "";
        Logger.d("checkImage---->start", file.getName());
        String res = "";
        FileInputStream fo = null;
        ByteArrayOutputStream bos = null;
        try {
            fo = new FileInputStream(file);
            bos = new ByteArrayOutputStream();
            byte[] buffer = new byte[1024];
            int length;
            length = fo.read(buffer);
            bos.write(buffer, 0, length);
            String s = new String(buffer, "utf-8");
            Logger.d("原数据:", s);
            for (String str : psKey) {
                Logger.d("检查过程", "psk:" + str + "");
                if (s.contains(str)) {
                    res = str;
                    Logger.d("图片检测结果:", str);
                    return res;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (fo != null)
                    fo.close();
                if (bos != null)
                    bos.close();
            } catch (Exception e2) {
                // TODO: handle exception
                e2.printStackTrace();
            }


        }
        return res;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android崩溃收集可以通过以下步骤实现: 1. 在AndroidManifest.xml文件中添加以下权限: ``` <uses-permission android:name="android.permission.READ_LOGS"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> ``` 2. 在Application类中初始化崩溃捕获工具: ``` public class App extends Application { @Override public void onCreate() { super.onCreate(); CrashHandler.getInstance().init(this); } } ``` 3. 编写一个崩溃捕获工具类CrashHandler: ``` public class CrashHandler implements Thread.UncaughtExceptionHandler { private static CrashHandler instance = new CrashHandler(); private Thread.UncaughtExceptionHandler defaultHandler; private Context context; private CrashHandler() { } public static CrashHandler getInstance() { return instance; } public void init(Context context) { this.context = context; defaultHandler = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(this); } @Override public void uncaughtException(Thread t, Throwable e) { if (!handleException(e) && defaultHandler != null) { defaultHandler.uncaughtException(t, e); } else { try { Thread.sleep(3000); } catch (InterruptedException ex) { ex.printStackTrace(); } android.os.Process.killProcess(android.os.Process.myPid()); System.exit(1); } } private boolean handleException(Throwable e) { if (e == null) { return false; } StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); String log = sw.toString(); Log.e("CrashHandler", log); saveLogToFile(log); return true; } private void saveLogToFile(String log) { String fileName = "crash-" + System.currentTimeMillis() + ".log"; try { File file = new File(Environment.getExternalStorageDirectory(), fileName); FileOutputStream fos = new FileOutputStream(file); fos.write(log.getBytes()); fos.close(); } catch (IOException e) { e.printStackTrace(); } } } ``` 4. 在崩溃捕获工具类中,将崩溃信息输出到Logcat和文件中,方便查找和分析。 5. 最后,在应用程序崩溃时,CrashHandler将捕获异常并将其保存到文件中。可以通过查看这些文件来分析崩溃原因并进行修复。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值