Android Device/Battery Temperature Sensor Sample

Create Temperature activity and create instance for android.intent.action.BATTERY_CHANGED intend  and register with Temperature Broadcast Receiver
Download Source
package com.javaorigin.temperature;

import android.app.Activity;
import android.content.IntentFilter;
import android.os.Bundle;
import android.widget.TextView;

public class TemperatureActivity extends Activity   {
 TemperatureReceiver receiver=new TemperatureReceiver(this);
 TextView tempDisplay=null;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
   tempDisplay=(TextView) findViewById(R.id.tempDisplay);

   IntentFilter localIntentFilter = new IntentFilter();
   localIntentFilter.addAction("android.intent.action.BATTERY_CHANGED");
   registerReceiver(receiver, localIntentFilter);   
 }


}


Create Temperature Broadcast Receiver
package com.javaorigin.temperature;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class TemperatureReceiver extends BroadcastReceiver{
 TemperatureActivity activity=null;
 public TemperatureReceiver(TemperatureActivity mainActivity) {
  activity=mainActivity;
 }
 @Override
 public void onReceive(Context arg0, Intent arg1) {
  activity.tempDisplay.setText(arg1.getIntExtra("temperature", 0)/10.0D+"");
 }

}

18 comments :

  1. This comment has been removed by the author.

    ReplyDelete
  2. myTectra Placement Portal is a Web based portal brings Potentials Employers and myTectra Candidates on a common platform for placement assistance

    ReplyDelete
  3. Great blog !It is best institute.Top Training institute In chennai
    http://chennaitraining.in/openspan-training-in-chennai/
    http://chennaitraining.in/uipath-training-in-chennai/
    http://chennaitraining.in/automation-anywhere-training-in-chennai/
    http://chennaitraining.in/microsoft-azure-training-in-chennai/
    http://chennaitraining.in/workday-training-in-chennai/
    http://chennaitraining.in/vmware-training-in-chennai/

    ReplyDelete
  4. This here is really good for all newbie here.

    ReplyDelete
  5. Thank you for amazing blog.

    ReplyDelete
  6. Your articles are quite beneficial to me. It is simple to comprehend and instructive. Also, I'd like to recommend a shader pack for Minecraft. You can get the BSL Shaders ​set here, and I'm sure you'll enjoy it.

    ReplyDelete
  7. I appreciated looking at your article. Very wonderful reveal. we have one of the best hard disk cleaner called WinDirStat which will help you to clean unneeded files from your PC.

    ReplyDelete