title: Android app widget that will reboot phone - widget isn't doing anything?
body: <p>I am starting to pull my hair out over this! I have been trying to make an app, that will place a widget on the screen, which, when clicked will reboot the phone. The widget goes on the screen, but when clicked nothing happens. I have been following bucky's tutorial on youtube.</p>
  
  <p>The code is here, I dont know what I am doing wrong!</p>
  
  <p>reboot_widget_activeity.java:</p>
  
  <pre><code>package com.liamwli.reboot_widget;
  
  import android.app.Activity;
  import android.app.PendingIntent;
  import android.appwidget.AppWidgetManager;
  import android.content.Context;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.RemoteViews;
  
  public class reboot_widget_activeity extends Activity implements
          OnClickListener {
      /** Called when the activity is first created. */
      int awID;
      AppWidgetManager awm;
      Context c = reboot_widget_activeity.this;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
  
          Intent i = getIntent();
          Bundle extras = i.getExtras();
          if (extras != null) {
              awID = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
                      AppWidgetManager.INVALID_APPWIDGET_ID);
          }
          awm = AppWidgetManager.getInstance(c);
      }
  
      @Override
      public void onClick(View v) {
          // TODO Auto-generated method stub
  
          RemoteViews views = new RemoteViews(c.getPackageName(), R.layout.widget_layout);
  
          Intent in = new Intent(c, Reboot.class);
          PendingIntent pi = PendingIntent.getActivity(c, 0, in, 0);
          views.setOnClickPendingIntent(R.id.bRB, pi);
  
          awm.updateAppWidget(awID, views);
  
          Intent result = new Intent();
          result.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, awID);
          setResult(RESULT_OK, result);
          finish();
      }
  }
  </code></pre>
  
  <p>Reboot.java:</p>
  
  <pre><code>package com.liamwli.reboot_widget;
  
  import java.io.IOException;
  
  import android.app.Activity;
  import android.app.ProgressDialog;
  import android.os.Bundle;
  import android.widget.Toast;
  
  public class Reboot extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
          ProgressDialog wait;
          wait = new ProgressDialog(Reboot.this);
          wait.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
          wait.setMessage("Rebooting. If this hangs, then this app wont work on this device (pull battery)");
          wait.setCancelable(false);
          wait.show();
          try {
              Runtime.getRuntime().exec("su");
              Runtime.getRuntime().exec("reboot");
          } catch (IOException e) {
          }
          wait.dismiss();
          Toast.makeText(Reboot.this, "Unable to reboot. Please ensure your device is rooted!", Toast.LENGTH_LONG).show();
          finish();
      }
  
  }
  </code></pre>
  
  <p>widget.java:</p>
  
  <pre><code>package com.liamwli.reboot_widget;
  
  import android.appwidget.AppWidgetProvider;
  import android.content.Context;
  import android.widget.Toast;
  
  public class Widget extends AppWidgetProvider {
  
      @Override
      public void onDeleted(Context context, int[] appWidgetIds) {
          // TODO Auto-generated method stub
          super.onDeleted(context, appWidgetIds);
          Toast.makeText(context, "Reboot Widget Added", Toast.LENGTH_SHORT)
                  .show();
      }
  
  
  }
  </code></pre>
  
  <p>androidmanifest.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.liamwli.reboot_widget"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk android:minSdkVersion="8" /&gt;
  
      &lt;application
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name" &gt;
          &lt;activity
              android:name=".reboot_widget_activeity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
      &lt;receiver android:name=".Widget"&gt;
  
          &lt;intent-filter&gt;
              &lt;action android:name="android.appwidget.action.APPWIDGET_UPDATE" /&gt;
          &lt;/intent-filter&gt;
  
          &lt;meta-data android:name="android.appwidget.provider" android:resource="@xml/widgetstuff"/&gt;
      &lt;/receiver&gt;
  
      &lt;activity
              android:name=".Reboot"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.liamwli.reboot_widget.REBOOT" /&gt;
  
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
  
  
  
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>widgetstuff.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:minHeight="40dp" android:minWidth="40dp" android:initialLayout="@layout/widget_layout"&gt;
  
  
  &lt;/appwidget-provider&gt;
  </code></pre>
  
  <p>widget_layout.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
      &lt;Button
          android:id="@+id/bRB"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Reboot" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Eclipse gives me no errors, and I dont get any force closes. The button on the widget simply doesn't do anything - why?</p>