App.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package com.xunao.effectdemo;
  2. import android.app.Application;
  3. import android.content.Context;
  4. import android.content.pm.PackageInfo;
  5. import android.content.pm.PackageManager;
  6. import android.os.Bundle;
  7. import android.util.Log;
  8. import com.uc.crashsdk.export.CrashApi;
  9. import com.umeng.analytics.MobclickAgent;
  10. import com.umeng.commonsdk.UMConfigure;
  11. import com.xunao.effectdemo.umeng.UmInitConfig;
  12. import java.security.MessageDigest;
  13. import java.security.NoSuchAlgorithmException;
  14. import java.util.Locale;
  15. import cn.jpush.android.api.JPushInterface;
  16. /**
  17. * author : 程中强
  18. * e-mail : 740479946@qq.com
  19. * date : 2022/8/315:31
  20. * desc :
  21. * version: 1.0
  22. */
  23. public class App extends Application {
  24. public static App app;
  25. public static App getInstance() {
  26. return app;
  27. }
  28. @Override
  29. public void onCreate() {
  30. super.onCreate();
  31. initUmengSDK();
  32. app = this;
  33. JPushInterface.setDebugMode(true);
  34. JPushInterface.init(this);
  35. // getSHA1Signature(this);
  36. }
  37. /**
  38. * 初始化友盟SDK
  39. */
  40. private void initUmengSDK() {
  41. // sharedPreferencesHelper=new SharedPreferencesHelper(this,"umeng");
  42. //设置LOG开关,默认为false
  43. UMConfigure.setLogEnabled(true);
  44. //友盟预初始化
  45. UMConfigure.preInit(getApplicationContext(),"6304343088ccdf4b7e0d67bb","Umeng");
  46. /**
  47. * 打开app首次隐私协议授权,以及sdk初始化,判断逻辑请查看SplashTestActivity
  48. */
  49. //判断是否同意隐私协议,uminit为1时为已经同意,直接初始化umsdk
  50. //友盟正式初始化
  51. UmInitConfig umInitConfig=new UmInitConfig();
  52. umInitConfig.UMinit(getApplicationContext());
  53. final Bundle customInfo = new Bundle();
  54. customInfo.putBoolean("mCallNativeDefaultHandler",true);
  55. CrashApi.getInstance().updateCustomInfo(customInfo);
  56. // 自动采集选择
  57. MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.AUTO);
  58. // 支持在子进程中统计自定义事件
  59. UMConfigure.setProcessEvent(true);
  60. }
  61. public void getSHA1Signature(Context context) {
  62. try {
  63. PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES);
  64. byte[] cert = info.signatures[0].toByteArray();
  65. MessageDigest md = MessageDigest.getInstance("MD5");
  66. byte[] publicKey = md.digest(cert);
  67. StringBuilder hexString = new StringBuilder();
  68. for (int i = 0; i < publicKey.length; i++) {
  69. String appendString = Integer.toHexString(0xFF & publicKey[i])
  70. .toUpperCase(Locale.US);
  71. if (appendString.length() == 1)
  72. hexString.append("0");
  73. appendString.replaceAll(":","");
  74. hexString.append(appendString);
  75. hexString.append(":");
  76. }
  77. Log.e("MyTag","签名:"+hexString.toString());
  78. } catch (PackageManager.NameNotFoundException e) {
  79. e.printStackTrace();
  80. } catch (NoSuchAlgorithmException e) {
  81. e.printStackTrace();
  82. }
  83. }
  84. /**
  85. * 将给定字符串中给定的区域的字符转换成小写
  86. *
  87. * @param str 给定字符串中
  88. * @param beginIndex 开始索引(包括)
  89. * @param endIndex 结束索引(不包括)
  90. * @return 新的字符串
  91. */
  92. public static String toLowerCase(String str, int beginIndex, int endIndex) {
  93. return str.replaceFirst(str.substring(beginIndex, endIndex),
  94. str.substring(beginIndex, endIndex)
  95. .toLowerCase(Locale.getDefault()));
  96. }
  97. }