Store Battery Level Status In a txt File
<p>I am a New B to Android. I have been Able to get the Battery Status/Level with the Following Code:</p>

<pre><code>private void BattStatus() {
        BroadcastReceiver batteryLevelReceiver = new BroadcastReceiver() {
            public void onReceive(Context context, Intent intent) {
                context.unregisterReceiver(this);
                int rawlevel = intent.getIntExtra("level", -1);
                int scale = intent.getIntExtra("scale", -1);
                int level = -1;
                if (rawlevel &gt;= 0 &amp;&amp; scale &gt; 0) {
                    level = (rawlevel * 100) / scale;
                }
                batteryLevel = level;
                BattStatus.setText("Battery Level : " + batteryLevel + "%");

            }
        };
        IntentFilter batteryLevelFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
        registerReceiver(batteryLevelReceiver, batteryLevelFilter);
    }
</code></pre>

<p>I would Like to Store the Battery Level In A text file (Using a thread). Code :</p>

<pre><code>public final Runnable DBThread = new Runnable() {
        String AllInfo = batteryLevel+"%"+" , "+new SimpleDateFormat("HH:mm , dd.MM.yy ").format(new Date());
        public void run() {
            try {
                Log.d("DBThread","Battery :"+batteryLevel);
                Log.d("DBThread","Updating DB");
                myDbHelper.CreateAndWriteFile(sdDir+"/", AllInfo );
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        mHandler.postAtTime(this, SystemClock.uptimeMillis() + 2000);
        Log.d("DBThread","Updated DB");
        Log.d("DBThread",AllInfo);

    }
</code></pre>

<p>Unfortunately the Battery Status/Level returns 0% in the text file, when I test it using the Log function in the thread it returns the correct value.</p>

<p>Please could some one be so kind to tell me what I am doing wrong or what I am not doing, and maybe provide me with a code snippet as I am new to Development.And Sorry If My Post is incorrect First timer on Stack Overflow :)</p>

<p>Thank you very much!</p>
