This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<span style="font-size:14px;">package com.test.twiceexit; | |
import java.util.Timer; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.os.Handler; | |
import android.os.Message; | |
import android.view.KeyEvent; | |
import android.view.Menu; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static final void collapseStatusBar(Context ctx) { | |
Object sbservice = ctx.getSystemService("statusbar"); | |
try { | |
Class<?> statusBarManager = Class.forName("android.app.StatusBarManager"); | |
Method collapse; | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { | |
collapse = statusBarManager.getMethod("collapsePanels"); | |
} else { | |
collapse = statusBarManager.getMethod("collapse"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static boolean checkNickname(String sequence) { | |
final String format = "[^\\u4E00-\\u9FA5\\uF900-\\uFA2D\\w-_]"; | |
Pattern pattern = Pattern.compile(format); | |
Matcher matcher = pattern.matcher(sequence); | |
return !matcher.find(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static boolean isIntentAvailable(Context context, String action) { | |
final PackageManager packageManager = context.getPackageManager(); | |
final Intent intent = new Intent(action); | |
List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); | |
return list.size() > 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context; | |
public class DensityUtil { | |
/** | |
* 根据手机的分辨率从 dp 的单位 转成为 px(像素) | |
*/ | |
public static int dip2px(Context context, float dpValue) { | |
final float scale = context.getResources().getDisplayMetrics().density; | |
return (int) (dpValue * scale + 0.5f); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void saveCurrentPosition() { | |
if (mListView != null) { | |
int position = mListView.getFirstVisiblePosition(); | |
View v = mListView.getChildAt(0); | |
int top = (v == null) ? 0 : v.getTop(); | |
//保存position和top | |
} | |
} | |
private void restorePosition() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String getNetworkTypeName(Context context) { | |
if (context != null) { | |
ConnectivityManager connectMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); | |
if (connectMgr != null) { | |
NetworkInfo info = connectMgr.getActiveNetworkInfo(); | |
if (info != null) { | |
switch (info.getType()) { | |
case ConnectivityManager.TYPE_WIFI: | |
return "WIFI"; | |
case ConnectivityManager.TYPE_MOBILE: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 解压一个压缩文档 到指定位置 | |
* | |
* @param zipFileString 压缩包的名字 | |
* @param outPathString 指定的路径 | |
* @throws Exception | |
*/ | |
public static void UnZipFolder(String zipFileString, String outPathString) throws Exception { | |
java.util.zip.ZipInputStream inZip = new java.util.zip.ZipInputStream(new java.io.FileInputStream(zipFileString)); | |
java.util.zip.ZipEntry zipEntry; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 从assets 文件夹中读取文本数据 */ | |
public static String getTextFromAssets(final Context context, String fileName) { | |
String result = ""; | |
try { | |
InputStream in = context.getResources().getAssets().open(fileName); | |
// 获取文件的字节数 | |
int lenght = in.available(); | |
// 创建byte数组 | |
byte[] buffer = new byte[lenght]; | |
// 将文件中的数据读到byte数组中 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String archiveFilePath="sdcard/download/Law.apk";//安装包路径 | |
PackageManager pm = getPackageManager(); | |
PackageInfo info = pm.getPackageArchiveInfo(archiveFilePath, PackageManager.GET_ACTIVITIES); | |
if(info != null){ | |
ApplicationInfo appInfo = info.applicationInfo; | |
String appName = pm.getApplicationLabel(appInfo).toString(); | |
String packageName = appInfo.packageName; //得到安装包名称 | |
String version=info.versionName; //得到版本信息 | |
Toast.makeText(test4.this, "packageName:"+packageName+";version:"+version, Toast.LENGTH_LONG).show(); | |
Drawable icon = pm.getApplicationIcon(appInfo);//得到图标信息 |
OlderNewer