Back to project page ShortcutsOfPower_Android.
The source code is released under:
GNU General Public License
If you think the Android project ShortcutsOfPower_Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.networkprofiles.widget; /*ww w . j a v a2 s. c o m*/ import android.app.PendingIntent; import android.app.PendingIntent.CanceledException; import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProvider; import android.content.Context; import android.content.Intent; import android.widget.RemoteViews; import com.networkprofiles.R; import com.networkprofiles.utils.NPReceiver; public class NPWidgetGps extends AppWidgetProvider { public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] widgetIds) { RemoteViews remote = new RemoteViews(context.getPackageName(), R.layout.npwidgetgps); Intent clickGps = new Intent(NPReceiver.ACTION_NP_WIDGET_GPS); clickGps.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, widgetIds); PendingIntent pendingGps = PendingIntent.getBroadcast(context.getApplicationContext(), 0, clickGps, PendingIntent.FLAG_UPDATE_CURRENT); remote.setOnClickPendingIntent(R.id.textWidgetGps, pendingGps); atStart(context, remote); appWidgetManager.updateAppWidget(widgetIds, remote); } public void onEnabled(Context context) { Intent i = new Intent("android.appwidget.action.APPWIDGET_UPDATE"); PendingIntent pendingI = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); try { pendingI.send(); } catch (CanceledException e) { e.printStackTrace(); } } public void onDisabled(Context context) { } private void atStart(Context context, RemoteViews remote) { //set the TextView for GPS // String locationProviders = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED); // if(locationProviders.contains("gps")) { // remote.setTextViewText(R.id.textWidgetGps, "GPS ON"); // } else { // remote.setTextViewText(R.id.textWidgetGps, "GPS OFF"); // } } }