Example usage for android.content Context sendBroadcast

List of usage examples for android.content Context sendBroadcast

Introduction

In this page you can find the example usage for android.content Context sendBroadcast.

Prototype

public abstract void sendBroadcast(@RequiresPermission Intent intent);

Source Link

Document

Broadcast the given intent to all interested BroadcastReceivers.

Usage

From source file:com.meiste.greg.ptw.tab.Standings.java

@Override
public void onGet(final Context context, final String json) {
    Util.log("Standings: onGet");
    update(context, json);/*from ww w  . j  a va  2  s  .  c  om*/

    // mConnecting not set for pull to refresh case
    if (!mConnecting) {
        mSwipeRefreshWidget.setRefreshing(false);
        mSwipeRefreshWidget.setEnabled(true);
        context.sendBroadcast(new Intent(PTW.INTENT_ACTION_STANDINGS));
    }
    // Verify application wasn't closed before callback returned
    else if (getActivity() != null) {
        mConnecting = false;
        mChanged = true;
        notifyChanged();
    }
}

From source file:com.daiv.android.twitter.utils.NotificationUtils.java

public static void sendToLightFlow(Context context, String title, String message) {
    Intent data = new Intent("com.daiv.android.twitter.NEW_NOTIFICATION");
    data.putExtra("title", TweetLinkUtils.removeColorHtml(title.replaceAll("<b>", "").replaceAll("</b>", ""),
            AppSettings.getInstance(context)));
    data.putExtra("message", TweetLinkUtils.removeColorHtml(
            message.replaceAll("<b>", "").replaceAll("</b>", ""), AppSettings.getInstance(context)));

    context.sendBroadcast(data);
}

From source file:saphion.fragment.alarm.alert.AlarmAlertReceiver.java

@SuppressWarnings("deprecation")
@Override/*from  w  w  w . j  a va2 s  . c  o m*/
public void onReceive(final Context context, final Intent intent) {
    String action = intent.getAction();
    int pos = intent.getIntExtra(PreferenceHelper.BAT_VALS, 0);
    level = intent.getIntExtra(PreferenceHelper.CURR_RING, 72);

    //Log.Toast(context, level + " in receiver", Toast.LENGTH_LONG);
    // int id = intent.getIntExtra(Intents.EXTRA_ID, -1);

    if (action.equals(Intents.ALARM_ALERT_ACTION)) {
        /* Close dialogs and window shade */
        Intent closeDialogs = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
        context.sendBroadcast(closeDialogs);

        // Decide which activity to start based on the state of the
        // keyguard.
        /*
         * KeyguardManager km = (KeyguardManager)
         * context.getSystemService(Context.KEYGUARD_SERVICE); if
         * (km.inKeyguardRestrictedInputMode()) { // Use the full screen
         * activity for security. c = AlarmAlertFullScreen.class; }
         */

        // Trigger a notification that, when clicked, will show the alarm
        // alert
        // dialog. No need to check for fullscreen since this will always be
        // launched from a user action.

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            Intent notify = new Intent(context, saphion.fragments.alarm.AlarmAlert.class);
            notify.putExtra(PreferenceHelper.BAT_VALS, pos);
            PendingIntent pendingNotify = PendingIntent.getActivity(context, ID, notify, 0);

            // Alarm alarm = AlarmsManager.getAlarmsManager().getAlarm(id);
            Notification n = new Notification(R.drawable.stat_notify_alarm, "abc", System.currentTimeMillis());
            n.setLatestEventInfo(context, "Battery Alarm", "Battery Level is " + level, pendingNotify);
            n.flags |= Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_ONGOING_EVENT;
            n.defaults |= Notification.DEFAULT_LIGHTS;

            // NEW: Embed the full-screen UI here. The notification manager
            // will // take care of displaying it if it's OK to do so.
            Intent alarmAlert = new Intent(context, saphion.fragments.alarm.AlarmAlert.class);
            alarmAlert.putExtra(PreferenceHelper.CURR_RING, level);
            alarmAlert.putExtra(PreferenceHelper.BAT_VALS, pos);
            alarmAlert.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
            n.fullScreenIntent = PendingIntent.getActivity(context, ID, alarmAlert, 0);

            // Send the notification using the alarm id to easily identify
            // the // correct notification.
            NotificationManager nm = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            // Log.Toast(context, "Recieved", Toast.LENGTH_LONG);
            // mNotificationManager.notify(ID, builder.build());
            nm.notify(ID, n);
        } else {
            // Log.Toast(context, "Recieved", Toast.LENGTH_LONG);
            newMethod(context, pos);
        }

    } else if (action.equals(Intents.ALARM_DISMISS_ACTION)) {
        NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        nm.cancel(ID);
    }
}

From source file:org.mariotaku.twidere.provider.TweetStoreProvider.java

private void onDatabaseUpdated(final Uri uri) {
    if (uri == null)
        return;//w ww .  j a  v a2  s.com
    if ("false".equals(uri.getQueryParameter(QUERY_PARAM_NOTIFY)))
        return;
    final Context context = getContext();
    switch (getTableId(uri)) {
    case URI_ACCOUNTS: {
        clearAccountColor();
        clearAccountName();
        context.sendBroadcast(new Intent(BROADCAST_ACCOUNT_LIST_DATABASE_UPDATED));
        break;
    }
    case URI_DRAFTS: {
        context.sendBroadcast(new Intent(BROADCAST_DRAFTS_DATABASE_UPDATED));
        break;
    }
    case URI_STATUSES:
    case URI_MENTIONS:
    case URI_DIRECT_MESSAGES_INBOX:
    case URI_DIRECT_MESSAGES_OUTBOX: {
        notifyForUpdatedUri(context, uri);
        break;
    }
    case URI_TRENDS_LOCAL: {
        context.sendBroadcast(new Intent(BROADCAST_TRENDS_UPDATED));
        break;
    }
    case URI_TABS: {
        context.sendBroadcast(new Intent(BROADCAST_TABS_UPDATED));
        break;
    }
    case URI_FILTERED_USERS:
    case URI_FILTERED_KEYWORDS:
    case URI_FILTERED_SOURCES: {
        context.sendBroadcast(new Intent(BROADCAST_FILTERS_UPDATED));
        break;
    }
    default:
        return;
    }
    context.sendBroadcast(new Intent(BROADCAST_DATABASE_UPDATED));
}

From source file:org.smap.smapTask.android.receivers.LocationChangedReceiver.java

/**
 * When a new location is received, extract it from the Intent and use
 * TODO start a service to handle new location
 *
 *///  w w  w .j  av  a2 s  .  co  m
@Override
public void onReceive(Context context, Intent intent) {
    String locationKey = LocationManager.KEY_LOCATION_CHANGED;
    String providerEnabledKey = LocationManager.KEY_PROVIDER_ENABLED;
    if (intent.hasExtra(providerEnabledKey)) {
        if (!intent.getBooleanExtra(providerEnabledKey, true)) {
            Log.i(TAG, "===================== Provider disabled");
            if (!intent.getBooleanExtra(providerEnabledKey, true)) {
                Intent providerDisabledIntent = new Intent(
                        "org.smap.smapTask.android.active_location_update_provider_disabled");
                context.sendBroadcast(providerDisabledIntent);
            }
        }
    }
    if (intent.hasExtra(locationKey)) {
        Location location = (Location) intent.getExtras().get(locationKey);

        if (isValidLocation(location) && isAccurateLocation(location)) {
            Log.d(TAG, "============== Updating location");

            // Save the current location
            Collect.getInstance().setLocation(location);

            // Notify any activity interested that there is a new location
            LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("locationChanged"));

            // Save the location in the database
            if (settings == null) {
                settings = PreferenceManager.getDefaultSharedPreferences(context);
            }
            if (settings.getBoolean(PreferencesActivity.KEY_STORE_USER_TRAIL, false)) {
                TraceUtilities.insertPoint(location);
            }
        }

    }
}

From source file:net.sourceforge.servestream.service.AppWidgetOneProvider.java

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    defaultAppWidget(context, appWidgetIds);

    // Send broadcast intent to any running MediaPlaybackService so it can
    // wrap around with an immediate update.
    Intent updateIntent = new Intent(MediaPlaybackService.SERVICECMD);
    updateIntent.putExtra(MediaPlaybackService.CMDNAME, AppWidgetOneProvider.CMDAPPWIDGETUPDATE);
    updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
    updateIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
    context.sendBroadcast(updateIntent);
}

From source file:com.meiste.greg.ptw.tab.Questions.java

@Override
public void onConnectSuccess(final Context context, final String json) {
    Util.log("Questions: onConnectSuccess: " + json);
    Toast.makeText(context, R.string.questions_success, Toast.LENGTH_SHORT).show();

    final SharedPreferences cache = context.getSharedPreferences(ACACHE, Activity.MODE_PRIVATE);
    cache.edit().putString(cachePrefix() + mRaceSelected.getId(), json).apply();

    context.sendBroadcast(new Intent(PTW.INTENT_ACTION_ANSWERS));

    // Verify application wasn't closed before callback returned
    if (getActivity() != null) {
        mSending = false;//from   ww w .  j  av  a  2s.  com
        setSubFragment();
    }
}

From source file:cn.whereyougo.framework.utils.PackageManagerUtil.java

/**
 * ????/*from w ww .  j a v  a 2  s.  com*/
 * 
 * @param mContext
 *            
 * @param TagClass
 *            ???
 * @param iconResId
 *            ??
 * @param iconName
 *            ??
 */
public static void addShortCut2Desktop(Context mContext, Class<?> TagClass, int iconResId, String iconName) {
    SharedPreferences sp = mContext.getSharedPreferences("appinfo", Context.MODE_PRIVATE);
    if (!sp.getBoolean("shortcut_flag_icon", false)) {
        sp.edit().putBoolean("shortcut_flag_icon", true).commit();
        LogUtil.d("shortcut", "first create successfull");
    } else {
        LogUtil.d("shortcut", "no created");
        return;
    }

    String ACTION_ADD_SHORTCUT = "com.android.launcher.action.INSTALL_SHORTCUT";
    Intent intent = new Intent();
    intent.setClass(mContext, TagClass);
    intent.setAction("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.LAUNCHER");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

    Intent addShortcut = new Intent(ACTION_ADD_SHORTCUT);
    Parcelable icon = Intent.ShortcutIconResource.fromContext(mContext, iconResId);// ???
    addShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, iconName);// ??
    addShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);// ??
    addShortcut.putExtra("duplicate", false);// ????
    addShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);// ??

    mContext.sendBroadcast(addShortcut);// ??
}

From source file:com.klinker.android.twitter.utils.NotificationUtils.java

public static void sendToLightFlow(Context context, String title, String message) {
    Intent data = new Intent("com.klinker.android.twitter.NEW_NOTIFICATION");
    data.putExtra("title", TweetLinkUtils.removeColorHtml(title.replaceAll("<b>", "").replaceAll("</b>", ""),
            AppSettings.getInstance(context)));
    data.putExtra("message", TweetLinkUtils.removeColorHtml(
            message.replaceAll("<b>", "").replaceAll("</b>", ""), AppSettings.getInstance(context)));

    context.sendBroadcast(data);
}

From source file:org.zywx.wbpalmstar.platform.push.PushService.java

private void start() {
    String appKey = EUExUtil.getString("appkey");
    appKey = PushReportUtility.decodeStr(appKey);
    softToken = PushReportUtility.getSoftToken(this, appKey);
    preferences = this.getSharedPreferences(PushReportConstants.SP_APP, Context.MODE_PRIVATE);
    url_push = ResoureFinder.getInstance().getString(this, "push_host");
    if (TextUtils.isEmpty(url_push)) {
        Log.w("PushService", "push_host is empty");
        return;/*from w w w.  j av  a 2s .  c  om*/
    }
    // String host_and_port = ResoureFinder.getInstance().getString(this,
    // "mam_push_host_and_port");
    // if (!TextUtils.isEmpty(host_and_port)) {
    // mamPush_ip = host_and_port.split(":")[0];
    // mamPush_port = host_and_port.split(":")[1];
    // }
    SharedPreferences sp = this.getSharedPreferences("saveData", Context.MODE_MULTI_PROCESS);
    String pushMes = sp.getString("pushMes", "0");
    String localPushMes = sp.getString("localPushMes", pushMes);
    if ("1".equals(localPushMes) && "1".equals(pushMes)) {
        type = 1;
    } else {
        type = 0;
    }
    try {
        // type = intent.getIntExtra("type", 0);
        // System.out.println("res ==== "+type);
        if (type == 0) {
            if (pushGetData != null) {
                ((MQTTService) pushGetData).onDestroy();
            }
            // runStatus = Status.PENDING;
            return;
        }
        // System.out.println("runStatus ==== RUNNING");
        // runStatus = Status.RUNNING;
        if (pushGetData == null) {
            String softToken = preferences.getString("softToken", null);
            pushGetData = new MQTTService(this, url_push, this, softToken);
            ((MQTTService) pushGetData).init();
        } else {
            /**?????? 
             * wanglei 20160314 modify*/
            Context ctx = getApplicationContext();
            Intent mQttPingIntent = new Intent(MQTTService.MQTT_PING_ACTION);
            mQttPingIntent.setPackage(ctx.getPackageName());
            ctx.sendBroadcast(mQttPingIntent);
            //                ((MQTTService) pushGetData).onDestroy();
            //                ((MQTTService) pushGetData).init();
        }

    } catch (Exception e) {
        // TODO: handle exception
    }

    // sleepTime = 1000;
    // if (isTemporary) {
    // sleepTime = 1000 * 30;
    // } else {
    // sleepTime = 1000 * 60 * 2;
    // }
    //
    // if (timer == null) {
    // timer = new Timer();
    // }
    //
    // if (myTimerTask == null) {
    // myTimerTask = new MyTimerTask();
    // }
    //
    // timer.schedule(myTimerTask, 0, sleepTime);

    // sendData = "{\"cmd\":\"reg\",\"appid\":\""
    // + preferences.getString("appid", null) + "\",\"st\":\""
    // + preferences.getString("softToken", null) + "\"}";
    // onReceive();
    // receiveData();
    // super.onStart(intent, startId);
}