
package com.exercise.IntentBatteryUsage;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class AndroidIntentBatteryUsageActivity extends Activity {
 
 Button btnCheckBattery;
 Intent intentBatteryUsage;
 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        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);
   }});
   
    }
}
Related articles:
- Detect Battery Info.
Thank you for reading this article Check battery usage, with Intent.ACTION_POWER_USAGE_SUMMARY With URL http://x-tutorials.blogspot.com/2011/06/check-battery-usage-with.html. Also a time to read the other articles.


0 comments:
Write your comment for this article Check battery usage, with Intent.ACTION_POWER_USAGE_SUMMARY above!