com.blankj.utilcode.util.AppUtils Java Examples
The following examples show how to use
com.blankj.utilcode.util.AppUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FloatWindowService.java From FloatWindow with Apache License 2.0 | 6 votes |
@Override public void handleMessage(Message msg) { int what = msg.what; switch (what) { case HANDLER_DETECT_PERMISSION: if (FloatWindowParamManager.checkPermission(getApplicationContext())) { //对沙雕VIVO机型特殊处理,应用处于后台检查悬浮窗权限成功才能确认真的获取了悬浮窗权限 if (RomUtils.isVivoRom() && AppUtils.isAppForeground()) { Log.e(TAG, "悬浮窗权限检查成功,但App处于前台状态,特殊机型会允许App获取权限,特殊机型就是指Vivo这个沙雕"); mHandler.sendEmptyMessageDelayed(HANDLER_DETECT_PERMISSION, 500); return; } mHandler.removeMessages(HANDLER_DETECT_PERMISSION); Log.e(TAG, "悬浮窗权限检查成功"); showFloatPermissionWindow(); } else { Log.e(TAG, "悬浮窗权限检查失败"); mHandler.sendEmptyMessageDelayed(HANDLER_DETECT_PERMISSION, 500); } break; } }
Example #2
Source File: FloatWindowParamManager.java From FloatWindow with Apache License 2.0 | 6 votes |
@RequiresApi(api = Build.VERSION_CODES.KITKAT) private static boolean checkOps(Context context) { try { Object object = context.getSystemService(Context.APP_OPS_SERVICE); if (object == null) { return false; } Class localClass = object.getClass(); Class[] arrayOfClass = new Class[3]; arrayOfClass[0] = Integer.TYPE; arrayOfClass[1] = Integer.TYPE; arrayOfClass[2] = String.class; Method method = localClass.getMethod("checkOp", arrayOfClass); if (method == null) { return false; } Object[] arrayOfObject1 = new Object[3]; arrayOfObject1[0] = 24; arrayOfObject1[1] = Binder.getCallingUid(); arrayOfObject1[2] = AppUtils.getAppPackageName(); int m = (Integer) method.invoke(object, arrayOfObject1); return m == AppOpsManager.MODE_ALLOWED || !RomUtils.isDomesticSpecialRom(); } catch (Exception ignore) { } return false; }
Example #3
Source File: AppInfoItem.java From AndroidUtilCode with Apache License 2.0 | 6 votes |
public static List<AppInfoItem> getAppInfoItems() { final List<AppInfoItem> appInfoItems = new ArrayList<>(); appInfoItems.add(new AppInfoItem(R.string.du_app_info_pkg_name, AppUtils.getAppPackageName())); appInfoItems.add(new AppInfoItem(R.string.du_app_info_version_name, AppUtils.getAppVersionName())); appInfoItems.add(new AppInfoItem(R.string.du_app_info_version_code, String.valueOf(AppUtils.getAppVersionCode()))); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { appInfoItems.add(new AppInfoItem(R.string.du_app_info_min_sdk_version, String.valueOf(DebugUtils.getApp().getApplicationInfo().minSdkVersion))); } appInfoItems.add(new AppInfoItem(R.string.du_app_info_target_sdk_version, String.valueOf(DebugUtils.getApp().getApplicationInfo().targetSdkVersion))); appInfoItems.add(new AppInfoItem(R.string.du_app_info_open_app_info_page, "", new OnClickListener() { @Override public void onClick(View v) { AppUtils.launchAppDetailsSettings(); } })); return appInfoItems; }
Example #4
Source File: InitializeService.java From YCAudioPlayer with Apache License 2.0 | 6 votes |
/** * 初始化腾讯bug管理平台 */ private void initBugly() { /* Bugly SDK初始化 * 参数1:上下文对象 * 参数2:APPID,平台注册时得到,注意替换成你的appId * 参数3:是否开启调试模式,调试模式下会输出'CrashReport'tag的日志 * 注意:如果您之前使用过Bugly SDK,请将以下这句注释掉。 */ CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(getApplicationContext()); // 设置版本号 strategy.setAppVersion(AppUtils.getAppVersionName()); // 设置版本名称 String appPackageName = AppUtils.getAppPackageName(); strategy.setAppPackageName(appPackageName); // 获取当前进程名 String processName = AppToolUtils.getProcessName(android.os.Process.myPid()); // 设置是否为上报进程 strategy.setUploadProcess(processName == null || processName.equals(appPackageName)); //Bugly会在启动20s后联网同步数据 strategy.setAppReportDelay(20000); //正式版 CrashReport.initCrashReport(getApplicationContext(), "521262bdd7", false, strategy); }
Example #5
Source File: AppActivity.java From Android-UtilCode with Apache License 2.0 | 6 votes |
@Override public void initView(Bundle savedInstanceState, View view) { findViewById(R.id.btn_install_app).setOnClickListener(this); findViewById(R.id.btn_install_app_silent).setOnClickListener(this); findViewById(R.id.btn_uninstall_app).setOnClickListener(this); findViewById(R.id.btn_uninstall_app_silent).setOnClickListener(this); findViewById(R.id.btn_launch_app).setOnClickListener(this); findViewById(R.id.btn_get_app_details_settings).setOnClickListener(this); TextView tvAboutApp = (TextView) findViewById(R.id.tv_about_app); tvAboutApp.setText(new SpannableStringUtils.Builder().append("app icon: ") .appendLine("").setDrawable(AppUtils.getAppIcon(), SpannableStringUtils.ALIGN_CENTER) .append(AppUtils.getAppInfo().toString()) .appendLine("isAppRoot: " + AppUtils.isAppRoot()) .appendLine("isAppDebug: " + AppUtils.isAppDebug()) .appendLine("AppSignatureSHA1: " + AppUtils.getAppSignatureSHA1()) .appendLine("isAppForeground: " + AppUtils.isAppForeground()) .create()); }
Example #6
Source File: FloatWindowParamManager.java From FloatWindow with Apache License 2.0 | 6 votes |
@RequiresApi(api = Build.VERSION_CODES.KITKAT) private static boolean checkOps(Context context) { try { Object object = context.getSystemService(Context.APP_OPS_SERVICE); if (object == null) { return false; } Class localClass = object.getClass(); Class[] arrayOfClass = new Class[3]; arrayOfClass[0] = Integer.TYPE; arrayOfClass[1] = Integer.TYPE; arrayOfClass[2] = String.class; Method method = localClass.getMethod("checkOp", arrayOfClass); if (method == null) { return false; } Object[] arrayOfObject1 = new Object[3]; arrayOfObject1[0] = 24; arrayOfObject1[1] = Binder.getCallingUid(); arrayOfObject1[2] = AppUtils.getAppPackageName(); int m = (Integer) method.invoke(object, arrayOfObject1); return m == AppOpsManager.MODE_ALLOWED || !RomUtils.isDomesticSpecialRom(); } catch (Exception ignore) { } return false; }
Example #7
Source File: FloatWindowService.java From FloatWindow with Apache License 2.0 | 6 votes |
@Override public void handleMessage(Message msg) { int what = msg.what; switch (what) { case HANDLER_DETECT_PERMISSION: if (FloatWindowParamManager.checkPermission(getApplicationContext())) { //对沙雕VIVO机型特殊处理,应用处于后台检查悬浮窗权限成功才能确认真的获取了悬浮窗权限 if (RomUtils.isVivoRom() && AppUtils.isAppForeground()) { Log.e(TAG, "悬浮窗权限检查成功,但App处于前台状态,特殊机型会允许App获取权限,特殊机型就是指Vivo这个沙雕"); mHandler.sendEmptyMessageDelayed(HANDLER_DETECT_PERMISSION, 500); return; } mHandler.removeMessages(HANDLER_DETECT_PERMISSION); Log.e(TAG, "悬浮窗权限检查成功"); showFloatPermissionWindow(); } else { Log.e(TAG, "悬浮窗权限检查失败"); mHandler.sendEmptyMessageDelayed(HANDLER_DETECT_PERMISSION, 500); } break; } }
Example #8
Source File: AppService.java From V2EX with GNU General Public License v3.0 | 6 votes |
public static void checkNotifycation(String errorLog,ResponseListener<String> responseListener){ Map<String, String> form = new HashMap<String,String>(){{ put("version", AppUtils.getAppVersionName() + AppUtils.getAppVersionCode()); put("deviceModel", DeviceUtils.getModel()); put("sdkVersion", String.valueOf(DeviceUtils.getSDKVersionCode())); put("screen", ScreenUtils.getScreenDensity() + " " + ScreenUtils.getScreenHeight() + "x" + ScreenUtils.getScreenWidth()); put("errorLog", errorLog); }}; RetrofitManager.create(AppApi.class) .checkNotifycation(form) .compose(RxUtil.io2main()) .subscribe(new RxObserver<JsonObject>() { @Override public void _onNext(JsonObject jsonObject) { } }); }
Example #9
Source File: FloatWindowService.java From FloatWindow with Apache License 2.0 | 5 votes |
private Intent getStartAppIntent(Context context) { Intent intent = context.getPackageManager() .getLaunchIntentForPackage(AppUtils.getAppPackageName()); if (intent != null) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); } return intent; }
Example #10
Source File: BaseFragment.java From AndroidUtilCode with Apache License 2.0 | 5 votes |
protected void log(String msg) { if (isDebug == null) { isDebug = AppUtils.isAppDebug(); } if (isDebug) { Log.d("BaseFragment", getClass().getSimpleName() + ": " + msg); } }
Example #11
Source File: BaseApplication.java From AndroidUtilCode with Apache License 2.0 | 5 votes |
private void initCrash() { CrashUtils.init(new CrashUtils.OnCrashListener() { @Override public void onCrash(String crashInfo, Throwable e) { LogUtils.e(crashInfo); AppUtils.relaunchApp(); } }); }
Example #12
Source File: FeedbackPresenter.java From SuperNote with GNU General Public License v3.0 | 5 votes |
private Feedback getFeedback(String content,String contact){ Feedback feedback=new Feedback(); feedback.setContent(content); feedback.setContact(contact); feedback.setSdk(DeviceUtils.getSDKVersion()); feedback.setVersion(AppUtils.getAppVersionName()); return feedback; }
Example #13
Source File: FloatWindowService.java From FloatWindow with Apache License 2.0 | 5 votes |
private Intent getStartAppIntent(Context context) { Intent intent = context.getPackageManager() .getLaunchIntentForPackage(AppUtils.getAppPackageName()); if (intent != null) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); } return intent; }
Example #14
Source File: MainActivity.java From DanDanPlayForAndroid with MIT License | 5 votes |
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { if (System.currentTimeMillis() - touchTime > 1500) { ToastUtils.showShort("再按一次退出应用"); touchTime = System.currentTimeMillis(); } else { if (ServiceUtils.isServiceRunning(TorrentService.class)) ServiceUtils.stopService(TorrentService.class); AppUtils.exitApp(); } } return false; }
Example #15
Source File: QPMGetAppInfoExecutor.java From QPM with Apache License 2.0 | 5 votes |
@Override public void exec() throws QPMException { jmAppAnalysis.onCollectAppInfo(AppUtils.getAppPackageName(), AppUtils.getAppName(), AppUtils.getAppVersionName(), AppUtils.getAppVersionCode(), BuildConfig.VERSION_CODE, System.currentTimeMillis(), 0); }
Example #16
Source File: DataPickBean.java From DoraemonKit with Apache License 2.0 | 5 votes |
DataPickBean() { //初始化基础数据 this.pId = DokitConstant.PRODUCT_ID; this.appName = AppUtils.getAppName(); this.appId = AppUtils.getAppPackageName(); this.dokitVersion = BuildConfig.DOKIT_VERSION; this.platform = "Android"; this.phoneMode = DeviceUtils.getModel(); this.time = "" + TimeUtils.getNowMills(); this.systemVersion = DeviceUtils.getSDKVersionName(); this.language = Locale.getDefault().getDisplayLanguage(); }
Example #17
Source File: ImageCapture.java From DoraemonKit with Apache License 2.0 | 5 votes |
public void init(Context context, Bundle bundle, ColorPickerDokitView colorPickerDokitView) throws Exception { this.mColorPickerDokitView = colorPickerDokitView; PackageManager packageManager = DoraemonKit.APPLICATION.getPackageManager(); ApplicationInfo applicationInfo = packageManager.getApplicationInfo(AppUtils.getAppPackageName(), 0); //适配Android Q if (applicationInfo.targetSdkVersion >= 29) { if (ColorPickManager.getInstance().getMediaProjection() != null) { colorPickerDokitView.onScreenServiceReady(); } else { try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { Intent intent = new Intent(context, ScreenRecorderService.class); intent.putExtra("data", bundle.getParcelable("data")); context.startForegroundService(intent); } } catch (Exception e) { e.printStackTrace(); } } } else { mMediaProjectionManager = (MediaProjectionManager) context.getSystemService(Context.MEDIA_PROJECTION_SERVICE); if (mMediaProjectionManager != null) { mMediaProjection = mMediaProjectionManager.getMediaProjection(Activity.RESULT_OK, (Intent) bundle.getParcelable("data")); initImageRead(mMediaProjection); } } }
Example #18
Source File: AppHealthInfoUtil.java From DoraemonKit with Apache License 2.0 | 5 votes |
/** * 设置基本信息 * * @param caseName 用例名称 * @param testPerson 测试人员名字 */ void setBaseInfo(String caseName, String testPerson) { AppHealthInfo.BaseInfoBean baseInfoBean = new AppHealthInfo.BaseInfoBean(); baseInfoBean.setTestPerson(testPerson); baseInfoBean.setCaseName(caseName); baseInfoBean.setAppName(AppUtils.getAppName()); baseInfoBean.setAppVersion(AppUtils.getAppVersionName()); baseInfoBean.setDokitVersion(BuildConfig.DOKIT_VERSION); baseInfoBean.setPlatform("Android"); baseInfoBean.setPhoneMode(DeviceUtils.getModel()); baseInfoBean.setTime(TimeUtils.getNowString()); baseInfoBean.setSystemVersion(DeviceUtils.getSDKVersionName()); baseInfoBean.setpId("" + DokitConstant.PRODUCT_ID); mAppHealthInfo.setBaseInfo(baseInfoBean); }
Example #19
Source File: PerformanceDataManager.java From DoraemonKit with Apache License 2.0 | 5 votes |
@Override public void run() { mLastFrameRate = totalFramesPerSecond; if (mLastFrameRate > MAX_FRAME_RATE) { mLastFrameRate = MAX_FRAME_RATE; } //保存fps数据 if (AppUtils.isAppForeground()) { writeFpsDataIntoFile(); } totalFramesPerSecond = 0; //1s中统计一次 mMainHandler.postDelayed(this, FPS_SAMPLING_TIME); }
Example #20
Source File: AppToolUtils.java From YCAudioPlayer with Apache License 2.0 | 5 votes |
public static String getAidlCheckAppInfoSign(){ String appPackageName = AppUtils.getAppPackageName(); //String appPackageName = "cn.ycbjie.ycaudioplayer"; @SuppressLint("SimpleDateFormat") // 设置日期格式 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd_HH:mm"); // new Date()为获取当前系统时间,也可使用当前时间戳 String date = df.format(new Date()); return encrypt(date+"_"+appPackageName); }
Example #21
Source File: RestartAppDebug.java From AndroidUtilCode with Apache License 2.0 | 4 votes |
@Override public void onClick(View view) { AppUtils.relaunchApp(true); }
Example #22
Source File: SplashActivity.java From DanDanPlayForAndroid with MIT License | 4 votes |
@Override public void initView() { presenter.checkToken(); //是否关闭启动页 if (AppConfig.getInstance().isCloseSplashPage()) { launchActivity(); return; } getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER); AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1); alphaAnimation.setRepeatCount(Animation.ABSOLUTE); alphaAnimation.setInterpolator(new LinearInterpolator()); alphaAnimation.setDuration(2000); String appName = "弹弹play 概念版 v" + AppUtils.getAppVersionName(); appNameTv.setText(appName); textPathView.setAnimListener(new TextPathAnimView.AnimListener() { @Override public void onStart() { } @Override public void onEnd() { if (textPathView != null) textPathView.postDelayed(() -> launchActivity(), 350); } @Override public void onLoop() { } }); textPathView.startAnim(); iconSvgView.start(); addressLl.startAnimation(alphaAnimation); }
Example #23
Source File: FloatWindowParamManager.java From FloatWindow with Apache License 2.0 | 4 votes |
public static WindowManager.LayoutParams getFloatLayoutParam(boolean fullScreen, boolean touchAble) { WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { layoutParams.type = TYPE_APPLICATION_OVERLAY; //刘海屏延伸到刘海里面 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { layoutParams.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; } } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { layoutParams.type = TYPE_TOAST; } else { layoutParams.type = WindowManager.LayoutParams.TYPE_PHONE; } layoutParams.packageName = AppUtils.getAppPackageName(); layoutParams.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; //Focus会占用屏幕焦点,导致游戏无声 if (touchAble) { layoutParams.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; } else { layoutParams.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; } if (fullScreen) { layoutParams.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT; layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT; } else { layoutParams.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; layoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT; layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT; } layoutParams.format = PixelFormat.TRANSPARENT; return layoutParams; }
Example #24
Source File: AppInfoDebug.java From AndroidUtilCode with Apache License 2.0 | 4 votes |
@Override public int getIcon() { int appIconId = AppUtils.getAppIconId(); if (appIconId != 0) return appIconId; return R.drawable.du_ic_debug_app_info_default; }
Example #25
Source File: ClearStorageDebug.java From AndroidUtilCode with Apache License 2.0 | 4 votes |
@Override public void onClick(View view) { ShellUtils.execCmd("pm clear " + AppUtils.getAppPackageName(), false); }
Example #26
Source File: BaseFloatView.java From AndroidUtilCode with Apache License 2.0 | 4 votes |
@Override protected void onDetachedFromWindow() { AppUtils.unregisterAppStatusChangedListener(this); super.onDetachedFromWindow(); }
Example #27
Source File: BaseFloatView.java From AndroidUtilCode with Apache License 2.0 | 4 votes |
@Override protected void onAttachedToWindow() { super.onAttachedToWindow(); AppUtils.registerAppStatusChangedListener(this); }
Example #28
Source File: BaseApplication.java From AndroidUtilCode with Apache License 2.0 | 4 votes |
private boolean isDebug() { if (isDebug == null) isDebug = AppUtils.isAppDebug(); return isDebug; }
Example #29
Source File: AppStartInfoFragment.java From DoraemonKit with Apache License 2.0 | 4 votes |
/** * 将启动信息保存到文件并分享 */ private void export2File(final String info) { if (TextUtils.isEmpty(info)) { ToastUtils.showShort("启动信息为空"); return; } ToastUtils.showShort("启动信息保存中,请稍后..."); final String logPath = PathUtils.getInternalAppFilesPath() + File.separator + AppUtils.getAppName() + "_" + "app_launch.log"; final File logFile = new File(logPath); ThreadUtils.executeByCpu(new ThreadUtils.Task<Boolean>() { @Override public Boolean doInBackground() throws Throwable { try { FileIOUtils.writeFileFromString(logFile, info, false); return true; } catch (Exception e) { e.printStackTrace(); return false; } } @Override public void onSuccess(Boolean result) { if (result) { ToastUtils.showShort("启动信息文件保存在:" + logPath); //分享 FileUtil.systemShare(DoraemonKit.APPLICATION, logFile); } } @Override public void onCancel() { if (logFile.exists()) { FileUtils.delete(logFile); } ToastUtils.showShort("启动信息保存失败"); } @Override public void onFail(Throwable t) { if (logFile.exists()) { FileUtils.delete(logFile); } ToastUtils.showShort("启动信息保存失败"); } }); }
Example #30
Source File: AppAboutActivity.java From SuperNote with GNU General Public License v3.0 | 4 votes |
private void initVersions() { String versions = AppUtils.getAppVersionName(); tvVersions.setText("V " + versions); }