启动设置电池统计活动

时间:2015-02-20 18:24:50

标签: java android button android-intent setting

我想知道如何以意图打开手机设置应用程序的活动。我想用一个按钮来操作电池统计活动。 谢谢!

1 个答案:

答案 0 :(得分:0)

是的,谢谢!

      btnCheckBattery = (Button)findViewById(R.id.checkBattery);
        
        intentBatteryUsage = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
        ResolveInfo resolveInfo = getPackageManager().resolveActivity(intentBatteryUsage,0);
        
        if(resolveInfo == null){
         Toast.makeText(AndroidIntentBatteryUsageActivity.this, 
           "Not Support!", 
           Toast.LENGTH_LONG).show();
         btnCheckBattery.setEnabled(false);
        }else{
         btnCheckBattery.setEnabled(true);
        }
        
        btnCheckBattery.setOnClickListener(new Button.OnClickListener(){

   public void onClick(View v) {
    // TODO Auto-generated method stub
    startActivity(intentBatteryUsage);
   }});