2015-10-22 67 views

回答

0

嗯。這是檢查GPS的高acurary模式。這是檢查:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 
        try { 
         if (getLocationMode(getApplicationContext()) != 3) { 
          tvmessage.setText("Please turn on GPS high Acurary"); 
          btcancel_Dialog.setText("OK"); 
          btcancel_Dialog.setOnClickListener(new OnClickListener() { 
           @Override 
           public void onClick(View v) { 
            startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)); 
            dlg.dismiss(); 
           } 
          }); 
          dlg.show(); 
         } else { 

          Intent intentvitri = new Intent(customer_textReport.this, CustomerGetLocation.class); 
          startActivityForResult(intentvitri, 111); 
         } 
        } catch (Settings.SettingNotFoundException e) { 
         e.printStackTrace(); 
        } 
       } 

和方法getLocationMode GPS的返回模式:

private int getLocationMode(Context context) throws Settings.SettingNotFoundException { 
    return Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE); 

} 
0

檢查谷歌開發者:PowerManager

在左上角,您可以更改API的水平。

正如您所看到的,isPowerSaveMode()被添加到API 21(Lollipop)中。

因此它不適用於較舊的設備。

0

在Android版本低於5.0(棒棒糖)的手機上,每個製造商的power_saving模式都不同。然而,如果你的目標版本是5.0和更高,你可以使用PowerManager描述Android Developer

0

試試這個(準備複製/粘貼):

/** 
* Checks if device is in power save mode. For older versions that do not support this API, returns false. 
* @return true if it is, false otherwise. 
*/ 
@TargetApi(Build.VERSION_CODES.LOLLIPOP) 
private static boolean isPowerSaveMode(Context context) 
{ 
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) 
    { 
     PowerManager powerManager = (PowerManager) context.get.getSystemService(Context.POWER_SERVICE); 
     return powerManager.isPowerSaveMode(); 
    } 

    // For older versions, we just say that device is not in power save mode 
    return false; 
} 
0

我結束了此功能。

注意:它不等於isPowerSaveMode()。它更像isRunningOutOfPower()或couldBePowerSaveMode()

它檢查SDK> = 21然後isPowerSaveMode功能可用。如果不是,則檢查GPS模式是否不是HIGH_ACCURACY並且電池電量低於15%,那麼它「可能是」powerSaveMode。

public static boolean couldBePowerSaveMode(Context context) { 
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); 
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
    if (powerManager != null) { 
    return powerManager.isPowerSaveMode(); 
    } 
} 

if (getLocationMode(context) != Settings.Secure.LOCATION_MODE_HIGH_ACCURACY) { 
    return getBatteryPercentage(context) <= 15; 
} 
return getBatteryPercentage(context) <= 15; 

}

相關問題