Saturday, May 5, 2012

Check battery usage, with Intent.ACTION_POWER_USAGE_SUMMARY


Check battery usage, with Intent.ACTION_POWER_USAGE_SUMMARY

To show power usage information to the user, you can start activity using Intent.ACTION_POWER_USAGE_SUMMARY.

Check battery usage, with Intent.ACTION_POWER_USAGE_SUMMARY

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);
   }});
   
    }
}

Start Display Setting, start activity with Settings.ACTION_DISPLAY_SETTINGS


Start Display Setting, start activity with Settings.ACTION_DISPLAY_SETTINGS

Start Display Setting, start activity with Settings.ACTION_DISPLAY_SETTINGS

package com.exercise.AndroidIntentDisplaySetting;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class AndroidIntentDisplaySettingActivity extends Activity {
 
 Button btnDisplaySetting;
 Intent intentDisplaySetting;
  
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        btnDisplaySetting = (Button)findViewById(R.id.displaySetting);
        
        intentDisplaySetting = new Intent(Settings.ACTION_DISPLAY_SETTINGS);
        ResolveInfo resolveInfo = getPackageManager().resolveActivity(intentDisplaySetting,0);
        
        if(resolveInfo == null){
         Toast.makeText(AndroidIntentDisplaySettingActivity.this, 
           "Not Support!", 
           Toast.LENGTH_LONG).show();
         btnDisplaySetting.setEnabled(false);
        }else{
         btnDisplaySetting.setEnabled(true);
        }
        
        btnDisplaySetting.setOnClickListener(new Button.OnClickListener(){

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

Bringing C and C++ Games to Android


Bringing C and C++ Games to Android

Google I/O 2011: Bringing C and C++ Games to Android

Want to make great Android games, but you're not a Java programmer? This talk is for you. Android supports a toolchain for building applications in C/C++. In December 2010 it got a makeover specifically aimed at making life better for game developers. This presentation gives an introduction to Android programming in C/C++, covers what's new and improved since last year, and shows best practices for building and debugging games with the NDK.