在线时间178 小时
UID3096266
注册时间2015-1-27
NXP金币0
TA的每日心情 | 郁闷 2021-3-10 19:44 |
---|
签到天数: 7 天 [LV.3]偶尔看看II
金牌会员
- 积分
- 2018
- 最后登录
- 2023-12-25
|
本帖最后由 MDebug 于 2016-11-29 14:34 编辑
APP主要用于对插座上各个继电器进行控制。此软件通过手机与WIFI模块建立连接,然后通过串口方式将数据发送到插座的MCU上,通过对数据的处理达到对插座相应控制。界面显示内容有:插座端WIFI模块IP地址,端口号(事先将此项设置好,使用的时候不用再改变)。端口号后面显示的为连接状态。ON、OFF分别表示继电器的控制状态,即每个插孔的工作状态。 做工很粗糙,也没有优化。 部分代码:
Part1:
Part2:
- <uses-permission
-
- android:name= "android.permission.GET_TASKS" />
-
- //判断当前手机是否处于锁屏(睡眠)状态
- public static boolean isSleeping(Context context) {
-
- KeyguardManager kgMgr = (KeyguardManager) context
-
- .getSystemService(Context.KEYGUARD_SERVICE);
-
- boolean isSleeping = kgMgr.inKeyguardRestrictedInputMode();
-
- return isSleeping;
-
- }
- public static boolean isOnline(Context context) {
-
- ConnectivityManager manager = (ConnectivityManager) context
-
- .getSystemService(Activity.CONNECTIVITY_SERVICE);
-
- NetworkInfo info = manager.getActiveNetworkInfo();
-
- if (info != null && info.isConnected()) {
-
- return true ;
-
- }
-
- return false ;
-
- }
- public static boolean isWifiConnected(Context context) {
-
- ConnectivityManager connectivityManager = (ConnectivityManager) context
-
- .getSystemService(Context.CONNECTIVITY_SERVICE);
-
- NetworkInfo wifiNetworkInfo = connectivityManager
-
- .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
-
- if (wifiNetworkInfo.isConnected()) {
-
- return true ;
-
- }
-
- return false ;
-
- }
- public static void installApk(Context context, File file) {
-
- Intent intent = new Intent();
-
- intent.setAction( "android.intent.action.VIEW" );
-
- intent.addCategory( "android.intent.category.DEFAULT" );
-
- intent.setType( "application/vnd.android.package-archive" );
-
- intent.setDataAndType(Uri.fromFile(file),
-
- "application/vnd.android.package-archive" );
-
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-
- context.startActivity(intent);
-
- }
- public static boolean isPhone(Context context) {
-
- TelephonyManager telephony = (TelephonyManager) context
-
- .getSystemService(Context.TELEPHONY_SERVICE);
-
- if (telephony.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE) {
-
- return false ;
-
- } else {
-
- return true ;
-
- }
-
- }@SuppressWarnings ( "deprecation" )
-
- public static int getDeviceWidth(Context context) {
-
- WindowManager manager = (WindowManager) context
-
- .getSystemService(Context.WINDOW_SERVICE);
-
- return manager.getDefaultDisplay().getWidth();
-
- }
-
- @SuppressWarnings ( "deprecation" )
-
- public static int getDeviceHeight(Context context) {
-
- WindowManager manager = (WindowManager) context
-
- .getSystemService(Context.WINDOW_SERVICE);
-
- return manager.getDefaultDisplay().getHeight();
-
- }
-
- @TargetApi (Build.VERSION_CODES.CUPCAKE)
-
- public static String getDeviceIMEI(Context context) {
-
- String deviceId;
-
- if (isPhone(context)) {
-
- TelephonyManager telephony = (TelephonyManager) context
-
- .getSystemService(Context.TELEPHONY_SERVICE);
-
- deviceId = telephony.getDeviceId();
-
- } else {
-
- deviceId = Settings.Secure.getString(context.getContentResolver(),
-
- Settings.Secure.ANDROID_ID);
-
- }
-
- return deviceId;
-
- }
- public static String getAppVersion(Context context) {
-
- String version = "0" ;
-
- try {
-
- version = context.getPackageManager().getPackageInfo(
-
- context.getPackageName(), 0 ).versionName;
-
- } catch (PackageManager.NameNotFoundException e) {
-
- e.printStackTrace();
-
- }
-
- return version;
-
- }
- public static Properties collectDeviceInfo(Context context) {
-
- Properties mDeviceCrashInfo = new Properties();
-
- try {
-
- PackageManager pm = context.getPackageManager();
-
- PackageInfo pi = pm.getPackageInfo(context.getPackageName(),
-
- PackageManager.GET_ACTIVITIES);
-
- if (pi != null ) {
-
- mDeviceCrashInfo.put(VERSION_NAME,
-
- pi.versionName == null ? "not set" : pi.versionName);
-
- mDeviceCrashInfo.put(VERSION_CODE, pi.versionCode);
-
- }
-
- } catch (PackageManager.NameNotFoundException e) {
-
- Log.e(TAG, "Error while collect package info" , e);
-
- }
-
- Field[] fields = Build. class .getDeclaredFields();
-
- for (Field field : fields) {
-
- try {
-
- field.setAccessible( true );
-
- mDeviceCrashInfo.put(field.getName(), field.get( null ));
-
- } catch (Exception e) {
-
- Log.e(TAG, "Error while collect crash info" , e);
-
- }
-
- }
-
- return mDeviceCrashInfo;
-
- }
-
- public static String collectDeviceInfoStr(Context context) {
-
- Properties prop = collectDeviceInfo(context);
-
- Set deviceInfos = prop.keySet();
-
- StringBuilder deviceInfoStr = new StringBuilder( "{\n" );
-
- for (Iterator iter = deviceInfos.iterator(); iter.hasNext();) {
-
- Object item = iter.next();
-
- deviceInfoStr.append( "\t\t\t" + item + ":" + prop.get(item)
-
- + ", \n" );
-
- }
-
- deviceInfoStr.append( "}" );
-
- return deviceInfoStr.toString();
-
- }
-
- @TargetApi (Build.VERSION_CODES.CUPCAKE)
-
- public static void hideSoftInput(Activity activity) {
-
- View view = activity.getWindow().peekDecorView();
-
- if (view != null ) {
-
- InputMethodManager inputmanger = (InputMethodManager) activity
-
- .getSystemService(Context.INPUT_METHOD_SERVICE);
-
- inputmanger.hideSoftInputFromWindow(view.getWindowToken(), 0 );
-
- }
-
- }
-
- @TargetApi (Build.VERSION_CODES.CUPCAKE)
-
- public static void hideSoftInput(Context context, EditText edit) {
-
- edit.clearFocus();
-
- InputMethodManager inputmanger = (InputMethodManager) context
-
- .getSystemService(Context.INPUT_METHOD_SERVICE);
-
- inputmanger.hideSoftInputFromWindow(edit.getWindowToken(), 0 );
-
- }
-
- @TargetApi (Build.VERSION_CODES.CUPCAKE)
-
- public static void showSoftInput(Context context, EditText edit) {
-
- edit.setFocusable( true );
-
- edit.setFocusableInTouchMode( true );
-
- edit.requestFocus();
-
- InputMethodManager inputManager = (InputMethodManager) context
-
- .getSystemService(Context.INPUT_METHOD_SERVICE);
-
- inputManager.showSoftInput(edit, 0 );
-
- }
-
- @TargetApi (Build.VERSION_CODES.CUPCAKE)
-
- public static void toggleSoftInput(Context context, EditText edit) {
-
- edit.setFocusable( true );
-
- edit.setFocusableInTouchMode( true );
-
- edit.requestFocus();
-
- InputMethodManager inputManager = (InputMethodManager) context
-
- .getSystemService(Context.INPUT_METHOD_SERVICE);
-
- inputManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0 );
-
- }
-
- public static void goHome(Context context) {
-
- Intent mHomeIntent = new Intent(Intent.ACTION_MAIN);
-
- mHomeIntent.addCategory(Intent.CATEGORY_HOME);
-
- mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
-
- | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
-
- context.startActivity(mHomeIntent);
-
- }
- @TargetApi (Build.VERSION_CODES.CUPCAKE)
-
- public static int getStatusBarHeight(Activity activity) {
-
- Rect frame = new Rect();
-
- activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
-
- return frame.top;
-
- }
- public static int getTopBarHeight(Activity activity) {
-
- return activity.getWindow().findViewById(Window.ID_ANDROID_CONTENT)
-
- .getTop();
-
- }
复制代码
|
|