乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      新手必備的常用代碼片段整理(一)

       scxingm 2015-12-08

      以下內(nèi)容來自多個(gè)開源項(xiàng)目的整理和自己的項(xiàng)目積累

      • 撥打電話

      • 跳轉(zhuǎn)至撥號(hào)界面

      • 發(fā)送短信

      • 喚醒屏幕并解鎖

      • 判斷當(dāng)前App處于前臺(tái)還是后臺(tái)狀態(tài)

      • 判斷當(dāng)前手機(jī)是否處于鎖屏睡眠狀態(tài)

      • 判斷當(dāng)前是否有網(wǎng)絡(luò)連接

      • 判斷當(dāng)前是否是WIFI連接狀態(tài)

      • 安裝APK

      • 判斷當(dāng)前設(shè)備是否為手機(jī)

      • 獲取當(dāng)前設(shè)備寬高單位px

      • 獲取當(dāng)前設(shè)備的IMEI需要與上面的isPhone一起使用

      • 獲取當(dāng)前設(shè)備的MAC地址

      • 獲取當(dāng)前程序的版本號(hào)

      撥打電話


      1
      2
      3
      public static void call(Context context, String phoneNumber) {
      context.startActivity(new Intent(Intent.ACTION_CALL, Uri.parse('tel:' + phoneNumber)));
      }

      跳轉(zhuǎn)至撥號(hào)界面


      1
      2
      3
      public static void callDial(Context context, String phoneNumber) {
      context.startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse('tel:' + phoneNumber)));
      }

      發(fā)送短信


      1
      2
      3
      4
      5
      6
      7
      8
      public static void sendSms(Context context, String phoneNumber,
      String content) {
      Uri uri = Uri.parse('smsto:'
      + (TextUtils.isEmpty(phoneNumber) ? '' : phoneNumber));
      Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
      intent.putExtra('sms_body', TextUtils.isEmpty(content) ? '' : content);
      context.startActivity(intent);
      }

      喚醒屏幕并解鎖


      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      public static void wakeUpAndUnlock(Context context){
      KeyguardManager km= (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
      KeyguardManager.KeyguardLock kl = km.newKeyguardLock('unLock');
      //解鎖
      kl.disableKeyguard();
      //獲取電源管理器對(duì)象
      PowerManager pm=(PowerManager) context.getSystemService(Context.POWER_SERVICE);
      //獲取PowerManager.WakeLock對(duì)象,后面的參數(shù)|表示同時(shí)傳入兩個(gè)值,最后的是LogCat里用的Tag
      PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK,'bright');
      //點(diǎn)亮屏幕
      wl.acquire();
      //釋放
      wl.release();
      }

      需要添加權(quán)限


      1
      2
      <uses-permission android:name='android.permission.WAKE_LOCK' />
      <uses-permission android:name='android.permission.DISABLE_KEYGUARD' />

      判斷當(dāng)前App處于前臺(tái)還是后臺(tái)狀態(tài)


      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      public static boolean isApplicationBackground(final Context context) {
      ActivityManager am = (ActivityManager) context
      .getSystemService(Context.ACTIVITY_SERVICE);
      @SuppressWarnings('deprecation')
      List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1);
      if (!tasks.isEmpty()) {
      ComponentName topActivity = tasks.get(0).topActivity;
      if (!topActivity.getPackageName().equals(context.getPackageName())) {
      return true;
      }
      }
      return false;
      }


      需要添加權(quán)限


      1
      2
      <uses-permission

      android:name='android.permission.GET_TASKS' />


      判斷當(dāng)前手機(jī)是否處于鎖屏(睡眠)狀態(tài)


      1
      2
      3
      4
      5
      6
      public static boolean isSleeping(Context context) {
      KeyguardManager kgMgr = (KeyguardManager) context
      .getSystemService(Context.KEYGUARD_SERVICE);
      boolean isSleeping = kgMgr.inKeyguardRestrictedInputMode();
      return isSleeping;
      }

      判斷當(dāng)前是否有網(wǎng)絡(luò)連接


      1
      2
      3
      4
      5
      6
      7
      8
      9
      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;
      }

      判斷當(dāng)前是否是WIFI連接狀態(tài)


      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      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;
      }

      安裝APK


      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      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);
      }

      判斷當(dāng)前設(shè)備是否為手機(jī)


      1
      2
      3
      4
      5
      6
      7
      8
      9
      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;
      }
      }

      獲取當(dāng)前設(shè)備寬高,單位px


      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      @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();
      }

      獲取當(dāng)前設(shè)備的IMEI,需要與上面的isPhone()一起使用


      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      @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;
      }

      獲取當(dāng)前設(shè)備的MAC地址


      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      public static String getMacAddress(Context context) {
      String macAddress;
      WifiManager wifi = (WifiManager) context
      .getSystemService(Context.WIFI_SERVICE);
      WifiInfo info = wifi.getConnectionInfo();
      macAddress = info.getMacAddress();
      if (null == macAddress) {
      return '';
      }
      macAddress = macAddress.replace(':', '');
      return macAddress;
      }

      獲取當(dāng)前程序的版本號(hào)


      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      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;
      }


      轉(zhuǎn)載地址:http://blog.csdn.net/zhaokaiqiang1992


        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多