当前位置: 首页 > news >正文

个人网站什么语言做吸引人的软文

个人网站什么语言做,吸引人的软文,深圳fpc人才网官网,邢台市政建设集团股份有限公司网站2019独角兽企业重金招聘Python工程师标准>>> 转载时请记得标明源地址:http://my.oschina.net/lijindou/blog demo 的 源码 地址:http://pan.baidu.com/s/1mhDsJqg 大家应该 知道 在android的 中 开发中,我们不可能 预算到各种各样…

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

 

转载时请记得标明源地址:http://my.oschina.net/lijindou/blog

 

demo  的 源码 地址:http://pan.baidu.com/s/1mhDsJqg

 

大家应该 知道 在android的 中 开发中,我们不可能 预算到各种各样的  异常  崩溃  ,本人用 淘宝的 时候 ,因为 本人的  手机问题 也出现了  好几次了 崩溃 呢  , 当用户在使用的时候  忽然出现一个崩溃 这对产品是十分  致命的,

204004_LF6Q_2728799.png

用户正在 用着APP  的时候 忽然间 闪退了 然后 出现了这个  崩溃 的 提示,本人感觉 这样 好丑 啊,即使要退出  也要有一种 体面地 退出吧  是不是 !!!

还有闪退了  ,我们 在这个 版本 闪退了,不能让 在 其他 版本 闪退,崩溃  是吧 ,那么 手机是在 用户手上 的 ,我们 不可能插在 我们的电脑 上 去调试 吧   ,是吧  , 所以我们 就要 在  app 崩溃的时候  ,   将 手机的信息和  崩溃日志 发送到 我们  能看到的地方去 ——  服务器  

 

由于我 也是 因为  项目 需求 才来 看这块的  ,  所以 原理 我也 不是太明白 , 能用 就好了 么  ,是不是 ,

好了 废话 不多说了  我直接上 代码  吧

 

 

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build;
import android.os.Environment;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.Thread.UncaughtExceptionHandler;
import java.lang.reflect.Field;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;/*** UncaughtException处理类,当程序发生Uncaught异常的时候,有该类来接管程序,并记录发送错误报告.* <p>* 需要在Application中注册,为了要在程序启动器就监控整个程序。*/
public class CrashHandler implements UncaughtExceptionHandler {public static final String TAG = "CrashHandler";//系统默认的UncaughtException处理类       private Thread.UncaughtExceptionHandler mDefaultHandler;//CrashHandler实例      private static CrashHandler instance;//程序的Context对象private Context mContext;//用来存储设备信息和异常信息      private Map<String, String> infos = new HashMap<String, String>();//用于格式化日期,作为日志文件名的一部分      private DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");/*** 保证只有一个CrashHandler实例*/private CrashHandler() {}/*** 获取CrashHandler实例 ,单例模式*/public static CrashHandler getInstance() {if (instance == null)instance = new CrashHandler();return instance;}/*** 初始化*/public void init(Context context) {mContext = context;//获取系统默认的UncaughtException处理器      mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();//设置该CrashHandler为程序的默认处理器      Thread.setDefaultUncaughtExceptionHandler(this);}/*** 当UncaughtException发生时会转入该函数来处理*/@Overridepublic void uncaughtException(Thread thread, Throwable ex) {if (!handleException(ex) && mDefaultHandler != null) {//如果用户没有处理则让系统默认的异常处理器来处理      mDefaultHandler.uncaughtException(thread, ex);} else {try {Thread.sleep(3000);} catch (InterruptedException e) {Log.e(TAG, "error : ", e);}//退出程序      android.os.Process.killProcess(android.os.Process.myPid());System.exit(1);}}/*** 自定义错误处理,收集错误信息 发送错误报告等操作均在此完成.** @param ex* @return true:如果处理了该异常信息;否则返回false.*/private boolean handleException(Throwable ex) {if (ex == null) {return false;}//收集设备参数信息       collectDeviceInfo(mContext);//使用Toast来显示异常信息      new Thread() {@Overridepublic void run() {Looper.prepare();Toast.makeText(mContext, "很抱歉,程序出现异常,即将退出.", Toast.LENGTH_SHORT).show();Looper.loop();}}.start();//保存日志文件       saveCatchInfo2File(ex);return true;}/*** 收集设备参数信息** @param ctx*/public void collectDeviceInfo(Context ctx) {try {PackageManager pm = ctx.getPackageManager();PackageInfo pi = pm.getPackageInfo(ctx.getPackageName(), PackageManager.GET_ACTIVITIES);if (pi != null) {String versionName = pi.versionName == null ? "null" : pi.versionName;String versionCode = pi.versionCode + "";infos.put("versionName", versionName);infos.put("versionCode", versionCode);}} catch (NameNotFoundException e) {Log.e(TAG, "an error occured when collect package info", e);}Field[] fields = Build.class.getDeclaredFields();for (Field field : fields) {try {field.setAccessible(true);infos.put(field.getName(), field.get(null).toString());Log.d(TAG, field.getName() + " : " + field.get(null));} catch (Exception e) {Log.e(TAG, "an error occured when collect crash info", e);}}}/*** 保存错误信息到文件中** @param ex* @return 返回文件名称, 便于将文件传送到服务器*/private String saveCatchInfo2File(Throwable ex) {StringBuffer sb = new StringBuffer();for (Map.Entry<String, String> entry : infos.entrySet()) {String key = entry.getKey();String value = entry.getValue();sb.append(key + "=" + value + "\n");}Writer writer = new StringWriter();PrintWriter printWriter = new PrintWriter(writer);ex.printStackTrace(printWriter);Throwable cause = ex.getCause();while (cause != null) {cause.printStackTrace(printWriter);cause = cause.getCause();}printWriter.close();String result = writer.toString();sb.append(result);try {long timestamp = System.currentTimeMillis();String time = formatter.format(new Date());String fileName = "crash-" + time + "-" + timestamp + ".log";if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {String path = Environment.getExternalStorageDirectory() + "/";File dir = new File(path);if (!dir.exists()) {dir.mkdirs();}FileOutputStream fos = new FileOutputStream(path + fileName);fos.write(sb.toString().getBytes());//发送给开发人员  sendCrashLog2PM(path + fileName);fos.close();}return fileName;} catch (Exception e) {Log.e(TAG, "an error occured while writing file...", e);}return null;}/*** 将捕获的导致崩溃的错误信息发送给开发人员* <p>* 目前只将log日志保存在sdcard 和输出到LogCat中,并未发送给后台。*/private void sendCrashLog2PM(String fileName) {Log.e(TAG, "sendCrashLog2PM: 路径:=-=" + fileName);if (!new File(fileName).exists()) {Toast.makeText(mContext, "日志文件不存在!", Toast.LENGTH_SHORT).show();return;}FileInputStream fis = null;BufferedReader reader = null;String s = null;try {fis = new FileInputStream(fileName);reader = new BufferedReader(new InputStreamReader(fis, "GBK"));while (true) {s = reader.readLine();if (s == null) break;//由于目前尚未确定以何种方式发送,所以先打出log日志。Log.i("info", s.toString());}} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();} finally {   // 关闭流try {reader.close();fis.close();} catch (IOException e) {e.printStackTrace();}}}
}

 

这个类是  主要的  操作的  类 ,代码 中都有  注释,大家 看看 吧  

 

 

然后 要   Application  写  个   Application类    

 

import android.app.Application;
public class MyApplication extends Application{private static MyApplication mApplication;public synchronized static MyApplication getInstance() {return mApplication;}@Overridepublic void onCreate() {super.onCreate();initData();}private void initData() {//当程序发生Uncaught异常的时候,由该类来接管程序,一定要在这里初始化
//        CrashHandler.getInstance().init(this);}}

 

亲 不要忘了 在    AndroidManifest.xml  文件里 注册 哦 

 还有权限  大家 不要 忘了   哦 

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

 

这个 是 AndroidManifest.xml 文件的 代码

 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.errey"><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /><applicationandroid:name=".MyApplication"android:allowBackup="true"android:icon="@mipmap/ic_launcher"android:label="@string/app_name"android:supportsRtl="true"android:theme="@style/AppTheme"><activity android:name=".Main2Activity"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity></application></manifest>

 

 

然后 我们 就可以 写一个 崩溃了  啊哈哈哈哈哈哈哈!!!

activity_main.xml  

 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"tools:context="com.errey.Main2Activity"><Buttonandroid:id="@+id/but"android:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:text="点击之后出现  崩溃  错误, 执行  CrashHandler  这个类中的代码  " /><TextViewandroid:id="@+id/text1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Hello World!"android:visibility="gone" />
</RelativeLayout>

 

 

Main2Activity。java

 

 

import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;public class Main2Activity extends Activity implements OnClickListener {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Button button = (Button) findViewById(R.id.but);button.setOnClickListener(this);}@Overridepublic void onClick(View v) {switch (v.getId()) {case R.id.but://自已写了一个异常信息,进行测试Button button = (Button) findViewById(R.id.text1);break;default:break;}}}

 

好了  ,代码 就 完了  ,效果的话  就要大家 自己把 代码 KOU KOU去看看 了

 

下面的 是  成功  捕捉到 崩溃 之后 日志 中 打印的     手机信息 和   崩溃 日志

 后面的是  是我自己 用翻译  猜的 ,大家 看看  如果 有神 么  不 正确 ,  啊哈哈哈哈  有劳 大家 给   指点指点  了 !!!  

让我 去 把源码 放到 上 面 去吧!!!

 

08-01 17:25:10.273 25744-25744/com.errey I/info: SUPPORTED_64_BIT_ABIS=[Ljava.lang.String;@392c43ac
08-01 17:25:10.274 25744-25744/com.errey I/info: versionCode=1                    非用户可见版本号
08-01 17:25:10.274 25744-25744/com.errey I/info: BOARD=m3note                     手机型号
08-01 17:25:10.275 25744-25744/com.errey I/info: BOOTLOADER=unknown               引导程序=未知的
08-01 17:25:10.275 25744-25744/com.errey I/info: TYPE=user                        类型=用户
08-01 17:25:10.275 25744-25744/com.errey I/info: ID=LMY47I                        ID
08-01 17:25:10.275 25744-25744/com.errey I/info: TIME=1466191121000               时间
08-01 17:25:10.275 25744-25744/com.errey I/info: BRAND=Meizu                      手机品牌
08-01 17:25:10.276 25744-25744/com.errey I/info: TAG=Build
08-01 17:25:10.276 25744-25744/com.errey I/info: SERIAL=91QECP43FK5Q              手机序列号
08-01 17:25:10.276 25744-25744/com.errey I/info: HARDWARE=mt6755
08-01 17:25:10.276 25744-25744/com.errey I/info: SUPPORTED_ABIS=[Ljava.lang.String;@177f6875
08-01 17:25:10.277 25744-25744/com.errey I/info: CPU_ABI=arm64-v8a
08-01 17:25:10.277 25744-25744/com.errey I/info: RADIO=unknown
08-01 17:25:10.277 25744-25744/com.errey I/info: IS_DEBUGGABLE=false               是否可调试
08-01 17:25:10.277 25744-25744/com.errey I/info: MANUFACTURER=Meizu                制造商
08-01 17:25:10.277 25744-25744/com.errey I/info: SUPPORTED_32_BIT_ABIS=[Ljava.lang.String;@3c593d5f
08-01 17:25:10.277 25744-25744/com.errey I/info: TAGS=release-keys
08-01 17:25:10.277 25744-25744/com.errey I/info: CPU_ABI2=
08-01 17:25:10.277 25744-25744/com.errey I/info: UNKNOWN=unknown
08-01 17:25:10.277 25744-25744/com.errey I/info: USER=flyme                         用户
08-01 17:25:10.277 25744-25744/com.errey I/info: FINGERPRINT=Meizu/meizu_m3note/m3note:5.1/LMY47I/1466190928:user/release-keys
08-01 17:25:10.277 25744-25744/com.errey I/info: HOST=mz-builder-8
08-01 17:25:10.277 25744-25744/com.errey I/info: PRODUCT=m3note
08-01 17:25:10.277 25744-25744/com.errey I/info: versionName=1.0                    用户可见的版本号
08-01 17:25:10.277 25744-25744/com.errey I/info: DISPLAY=Flyme 5.1.3.4A             手机系统版本号
08-01 17:25:10.277 25744-25744/com.errey I/info: MODEL=m3 note                      手机型号
08-01 17:25:10.277 25744-25744/com.errey I/info: DEVICE=m3note                      设备
08-01 17:25:10.277 25744-25744/com.errey I/info: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.Button    错误日志
08-01 17:25:10.277 25744-25744/com.errey I/info:     at com.errey.Main2Activity.onClick(Main2Activity.java:24)
08-01 17:25:10.277 25744-25744/com.errey I/info:     at android.view.View.performClick(View.java:4909)
08-01 17:25:10.277 25744-25744/com.errey I/info:     at android.view.View$PerformClick.run(View.java:20390)
08-01 17:25:10.277 25744-25744/com.errey I/info:     at android.os.Handler.handleCallback(Handler.java:821)
08-01 17:25:10.277 25744-25744/com.errey I/info:     at android.os.Handler.dispatchMessage(Handler.java:104)
08-01 17:25:10.277 25744-25744/com.errey I/info:     at android.os.Looper.loop(Looper.java:194)
08-01 17:25:10.277 25744-25744/com.errey I/info:     at android.app.ActivityThread.main(ActivityThread.java:5742)
08-01 17:25:10.277 25744-25744/com.errey I/info:     at java.lang.reflect.Method.invoke(Native Method)
08-01 17:25:10.278 25744-25744/com.errey I/info:     at java.lang.reflect.Method.invoke(Method.java:372)
08-01 17:25:10.278 25744-25744/com.errey I/info:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1104)
08-01 17:25:10.278 25744-25744/com.errey I/info:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)

 

 

 

 

 

转载于:https://my.oschina.net/lijindou/blog/725122

http://www.lbrq.cn/news/2615635.html

相关文章:

  • 旅游网站需求分析怎么做的有哪些营销推广方式
  • 网站建设需竞价托管外包
  • 建站助手官网百度广告开户
  • 视频背景做网站背景网络营销案例2022
  • 小程序源码破解seo就业前景如何
  • 美丽乡村 网站建设企业网址怎么注册
  • 微信怎么做网站推广自助建站平台源码
  • 一流的网站建设流程图宁波网站制作与推广价格
  • 网站seo诊断书杭州seo排名费用
  • 网站建设自助建站云建站cpa推广平台
  • 制作网页和做网站是一个意思吗企业网页
  • 建站软件有哪些功能设计本网站
  • 镇江教育云平台网站建设关键词优化的策略
  • 免费行情软件app网站大全下载免费入口上海短视频推广
  • 网站色调选择北京搜索引擎关键词优化
  • 宝鸡做网站电话网络营销是什么专业类别
  • 域名空间商seo初学教程
  • 广东科技网站建设百度推广技巧方法
  • 网站建设的经济效益怎么做一个公司网站
  • 佛山智家人网站宁波seo外包优化公司
  • 昆明公司做网站保定网站制作
  • 网站开发需要什么开发工具外汇seo公司
  • 信用中国 网站 建设方案百度退推广费是真的吗
  • b2b网站做推广什么网站好seo排名的影响因素有哪些
  • 襄阳教育云平台网站建设企业培训机构
  • 网站建设服务器是什么意思销售推广方案
  • html做网站的代码点击软件
  • wordpress没有中文版专业优化网站排名
  • 接单平台有哪些黄山网站seo
  • WordPress审核邮箱提醒广东企业网站seo哪里好
  • vscode 打开设置
  • 从零开始用 Eclipse 写第一个 Java 程序:HelloWorld 全流程 + 避坑指南
  • Perforce P4 Plan - DevOps实时规划工具
  • 一种红外遥控RGB灯带控制器-最低价MCU
  • 灰色优选模型及算法MATLAB代码
  • Vue3 defineAsyncComponent() 函数