package hu.sjjd.com.contorlpc.utils.commonlogcollector.util;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Environment;
import android.telephony.TelephonyManager;
import android.util.Log;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
/**
*
* @author jiabin
*
*/
public class LogCollectorUtility {
private static final String TAG = "CrashHandler_TAG";
public static boolean isNetworkConnected(Context context) {
if (context != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
if (mNetworkInfo != null) {
return mNetworkInfo.isAvailable() && mNetworkInfo.isConnected();
}
}
return false;
}
public static boolean isWifiConnected(Context context) {
if (context != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mWiFiNetworkInfo = mConnectivityManager
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (mWiFiNetworkInfo != null) {
return mWiFiNetworkInfo.isAvailable() && mWiFiNetworkInfo.isConnected();
}
}
return false;
}
/**
* 获取程序外部(sd)的目录
*
* @param context
* @return
*/
public static File getExternalDir(Context context , String dirName) {
final String cacheDir = "/Android/data/" + context.getPackageName()
+ "/";
return new File(Environment.getExternalStorageDirectory().getAbsolutePath()
+ cacheDir + dirName + "/");
}
public static boolean isSDcardExsit() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
return true;
}
return false;
}
public static boolean hasPermission(Context context) {
// if (context != null) {
// boolean b1 = context
// .checkCallingOrSelfPermission("android.permission.INTERNET") == 0;//
// boolean b2 = context.checkCallingOrSelfPermission("android.permission.READ_PHONE_STATE") == 0;
// boolean b3 = context.checkCallingOrSelfPermission("android.permission.WRITE_EXTERNAL_STORAGE") == 0;
// boolean b4 = context.checkCallingOrSelfPermission("android.permission.ACCESS_NETWORK_STATE") == 0;
// boolean b5 = context.checkCallingOrSelfPermission("android.permission.ACCESS_WIFI_STATE") == 0;
//
// if(!b1 || !b2 || !b3 || !b4 || !b5){
// Log.d(TAG, "没有添加权限");
// Toast.makeText(context.getApplicationContext(), "没有添加权限", Toast.LENGTH_SHORT).show();
// }
// return b1 && b2 && b3 && b4 && b5;
// }
return true;
}
public static String getCurrentTime(){
long currentTime = System.currentTimeMillis();
Date date = new Date(currentTime);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
String time = sdf.format(date);
return time;
}
public static String getVerName(Context c){
PackageManager pm = c.getPackageManager();
PackageInfo pi = null;
try {
pi = pm.getPackageInfo(c.getPackageName(), PackageManager.GET_ACTIVITIES);
} catch (NameNotFoundException e) {
Log.e(TAG, "Error while collect package info", e);
e.printStackTrace();
return "error";
}
if(pi == null){
return "error1";
}
String versionName = pi.versionName;
if(versionName == null){
return "not set";
}
return versionName;
}
public static String getVerCode(Context c){
PackageManager pm = c.getPackageManager();
PackageInfo pi = null;
try {
pi = pm.getPackageInfo(c.getPackageName(), PackageManager.GET_ACTIVITIES);
} catch (NameNotFoundException e) {
Log.e(TAG, "Error while collect package info", e);
e.printStackTrace();
return "error";
}
if(pi == null){
return "error1";
}
int versionCode = pi.versionCode;
return String.valueOf(versionCode);
}
public static String getMid(Context context) {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String imei = tm.getDeviceId();
String AndroidID = android.provider.Settings.System.getString(context.getContentResolver(), "android_id");
String serialNo = getDeviceSerialForMid2();
String m2 = getMD5Str("" + imei + AndroidID + serialNo);
return m2;
}
private static String getDeviceSerialForMid2() {
String serial = "";
try {
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class);
serial = (String) get.invoke(c, "ro.serialno");
} catch (Exception ignored) {
}
return serial;
}
public static String getMD5Str(String str) {
MessageDigest messageDigest = null;
try {
messageDigest = MessageDigest.getInstance("MD5");
messageDigest.reset();
messageDigest.update(str.getBytes("UTF-8"));
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return "";
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return "";
}
byte[] byteArray = messageDigest.digest();
StringBuffer md5StrBuff = new StringBuffer();
for (int i = 0; i < byteArray.length; i++) {
if (Integer.toHexString(0xFF & byteArray[i]).length() == 1)
md5StrBuff.append("0").append(Integer.toHexString(0xFF & byteArray[i]));
else
md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i]));
}
return md5StrBuff.toString();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
同一局域网,手机关机电脑
共46个文件
png:18个
xml:14个
java:13个
需积分: 43 7 下载量 116 浏览量
2017-09-02
16:27:34
上传
评论 1
收藏 380KB ZIP 举报
温馨提示
利用Socket,在局域网类通过在手机实现关机。操作为手机通过wifi类查找当前连接网段内实现 30000端口的ip地址。也就是获取到服务端的 ip地址。在查找到有后,进行socket连接。然后,服务端和手机端相互确定字符的格式。起到电脑的关机,重启,和取消操作的小功能。只有 src和 服务端的 .java。需要自己拷贝一次
资源推荐
资源详情
资源评论
收起资源包目录
ContorlPCClient.zip (46个子文件)
ContorlPCClient
res
mipmap-xxxhdpi
ic_launcher.png 10KB
ic_launcher_round.png 14KB
drawable
btn_close_pressed.png 2KB
btn_normal.png 672B
btn_close_focused.png 2KB
btn_close_selector.xml 456B
btn_close_normal.png 672B
acticon.png 7KB
btn_pressed.png 2KB
btn_selector.xml 432B
btn_focused.png 2KB
mipmap-hdpi
ic_launcher.png 3KB
ic_launcher_round.png 4KB
values
colors.xml 282B
public.xml 3KB
strings.xml 523B
styles.xml 2KB
ids.xml 869B
values-zh-rCN
strings.xml 545B
mipmap-xxhdpi
ic_launcher.png 8KB
ic_launcher_round.png 10KB
mipmap-mdpi
ic_launcher.png 2KB
ic_launcher_round.png 2KB
mipmap-xhdpi
ic_launcher.png 5KB
ic_launcher_round.png 6KB
drawable-hdpi-v4
icon.png 6KB
layout
activity_re_scan.xml 538B
activity_main.xml 1KB
main.xml 1KB
newmain.xml 859B
activity_scan.xml 1KB
PCService.java 3KB
java
hu
sjjd
com
contorlpc
base
MyApplication.java 613B
ui
ScanActivity.java 4KB
MyWifi.java 1KB
MainActivity.java 5KB
ReScanActivity.java 1KB
utils
LogUtils.java 2KB
commonlogcollector
LogCollector.java 950B
capture
LogFileStorage.java 3KB
CrashHandler.java 6KB
util
Constants.java 161B
LogCollectorUtility.java 6KB
LogHelper.java 922B
app-debug.apk 462KB
AndroidManifest.xml 2KB
共 46 条
- 1
资源评论
幽反丶叛冥
- 粉丝: 823
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功