vetriselvan vetri

vetriselvan vetri

  • NA
  • 28
  • 8.1k

Unfortunately app has been stopped in this,how to solve

Apr 23 2015 6:34 AM
public class MainActivity extends ActionBarActivity {
    TextView textView1, Btrylevel;
    private Intent intent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Postdata();
    }
    public void Postdata() {
        TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        textView1 = (TextView) findViewById(R.id.textView1);
        final String Imei = tm.getDeviceId();
        textView1.setText("IMEI NUMBER  " + Imei);

      Btrylevel=(TextView)this.findViewById(R.id.textView2);
        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 >= 0 && scale > 0) {
                    level = (rawlevel * 100) / scale;
                }
                Btrylevel.setText("Battery Level: " + level + "%");

            }
        };
        IntentFilter batteryLevelFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
        registerReceiver(batteryLevelReceiver, batteryLevelFilter);
            // Create a new HttpClient and Post Header
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://10.0.2.2/api/IMeis");

            try {
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
                nameValuePairs.add(new BasicNameValuePair("IMei", Imei));
                nameValuePairs.add(new BasicNameValuePair("Btrylevel",Btrylevel.toString()));

                 httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));


                HttpResponse response = httpclient.execute(httppost);

            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
            } catch (IOException e) {
                // TODO Auto-generated catch block
            }
    }
}