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.joeyturczak.jtscanner.utils.Utility.java

public static void createSpreadsheet(Context context, TodayData todayData) {
    List<String> headerRow = new ArrayList<String>();
    headerRow.add("");
    headerRow.add("Machine ID");
    headerRow.add("Hot Box ID");
    headerRow.add("Cold Box ID");

    List<List> recordToAdd = new ArrayList<List>();
    recordToAdd.add(headerRow);//from  w  w  w .  j  av a 2s. com

    long currentDay = normalizeDate(System.currentTimeMillis());

    List<Asset> assets = todayData.getAssets();

    String machine, hotBox, coldBox;

    for (Asset asset : assets) {
        List<String> nextRow = new ArrayList<>();
        machine = asset.getMachine();
        hotBox = asset.getHotBox();
        coldBox = asset.getColdBox();
        nextRow.add(String.valueOf(assets.indexOf(asset) + 1));
        nextRow.add(machine);
        nextRow.add(hotBox);
        nextRow.add(coldBox);
        recordToAdd.add(nextRow);
    }

    CreateExcelSpreadsheet cls = new CreateExcelSpreadsheet(recordToAdd);
    try {
        deleteFilesOnDate(context, currentDay);
        Uri fileUri = cls.createExcelFile();
        context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, fileUri));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.miqtech.master.client.ui.PersonalHomePhotoActivity.java

public static void saveImageToGallery(Context context, Bitmap bmp) {
    // ?//w  w  w.  ja v  a  2 s  .c o  m
    File appDir = new File(Environment.getExternalStorageDirectory(), "Boohee");
    if (!appDir.exists()) {
        appDir.mkdir();
    }
    String fileName = System.currentTimeMillis() + ".jpg";
    File file = new File(appDir, fileName);
    try {
        FileOutputStream fos = new FileOutputStream(file);
        bmp.compress(CompressFormat.JPEG, 100, fos);
        fos.flush();
        fos.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // ?
    try {
        MediaStore.Images.Media.insertImage(context.getContentResolver(), file.getAbsolutePath(), fileName,
                null);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    // ?
    context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + fileName)));

}

From source file:io.github.protino.codewatch.sync.WakatimeDataSyncJob.java

private void updateWidgets() {
    Context context = getApplicationContext();
    Intent intent = new Intent(Constants.ACTION_DATA_UPDATED).setPackage(context.getPackageName());
    context.sendBroadcast(intent);
}

From source file:com.esminis.server.library.service.server.installpackage.InstallerPackage.java

private void sendBroadcast(Context context, int state, float progress) {
    final Intent intent = new Intent(MainActivity.getIntentActionInstallPackage(context));
    intent.putExtra("state", state);
    intent.putExtra("progress", progress);
    context.sendBroadcast(intent);
}

From source file:com.todotxt.todotxttouch.widget.ListWidgetProvider.java

@Override
public void onReceive(Context context, Intent intent) {
    final String action = intent.getAction();

    if (action.equals(REFRESH_ACTION)) {
        Log.d(TAG, "Widget Refresh button pressed");

        Intent i = new Intent(Constants.INTENT_START_SYNC_WITH_REMOTE);
        context.sendBroadcast(i);
        Bundle extras = intent.getExtras();

        if (extras != null) {
            int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID);
            AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
            RemoteViews rv = buildLayout(context, appWidgetId, true);
            appWidgetManager.partiallyUpdateAppWidget(appWidgetId, rv);
        }/*from   w  w  w.j a  va  2 s. co  m*/
    } else if (action.equals(Constants.INTENT_WIDGET_UPDATE)) {
        Log.d(TAG, "Update widget intent received ");

        int[] appWidgetIds = null;
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        Bundle extras = intent.getExtras();

        if (extras != null) {
            appWidgetIds = extras.getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS);
        }

        if (appWidgetIds == null) {
            appWidgetIds = appWidgetManager
                    .getAppWidgetIds(new ComponentName(context, ListWidgetProvider.class.getName()));
        }

        if (appWidgetIds != null && appWidgetIds.length > 0) {
            this.onUpdate(context, appWidgetManager, appWidgetIds);
        }
    }

    super.onReceive(context, intent);
}

From source file:com.fede.Utilities.GeneralUtils.java

public static void notifyEvent(String event, String fullDescEvent, DroidContentProviderClient.EventType type,
        Context c) {
    DroidContentProviderClient.addEvent(fullDescEvent, new Date(), event, type, c);

    if (!PrefUtils.homeAloneEnabled(c)) // if the status is disabled I dont want to show the notification
        return;/*from  ww w .  j a va 2s.  c o  m*/

    String svcName = Context.NOTIFICATION_SERVICE;
    NotificationManager notificationManager = (NotificationManager) c.getSystemService(svcName);

    String expandedText = fullDescEvent;
    String expandedTitle = c.getString(R.string.home_alone_event);

    Intent intent = new Intent(c, FirstActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra(EVENT_LIST_INTENT, true);
    PendingIntent launchIntent = PendingIntent.getActivity(c, 0, intent, 0);

    Notification notification = new NotificationCompat.Builder(c).setContentTitle(expandedTitle)
            .setContentText(expandedText).setSmallIcon(R.drawable.ic_stat_home_alone_notify)
            .setContentIntent(launchIntent).setTicker(event).build();

    notification.number = -1;

    Intent i = new Intent(HomeAloneService.HOMEALONE_EVENT_PROCESSED);
    c.sendBroadcast(i);

    // Intent to launch an activity when the extended text is clicked      

    int notificationRef = 1;
    notificationManager.notify(notificationRef, notification);
}

From source file:pj.rozkladWKD.DeviceRegistrar.java

public static void unregisterWithServer(final Context context, final String deviceRegistrationID) {
    new Thread(new Runnable() {
        public void run() {
            Intent updateUIIntent = new Intent("com.google.ctp.UPDATE_UI");
            try {

                List<NameValuePair> post = new ArrayList<NameValuePair>();
                post.add(new BasicNameValuePair("requestType", "UNREGISTER_PUSH"));
                post.add(new BasicNameValuePair("deviceId", DeviceIdGenerator.getDeviceId()));
                post.add(new BasicNameValuePair("clientRegistrationId", deviceRegistrationID));
                post.add(new BasicNameValuePair("productId", context.getString(R.string.productId)));

                JSONObject result = HttpClient.SendHttpPost(post);
            } catch (Exception e) {
                if (RozkladWKD.DEBUG_LOG) {
                    Log.e("PUSH", e.getMessage(), e);
                }/* w  w w  .  j a v a2  s  . co m*/
            } finally {
                SharedPreferences settings = Prefs.get(context);
                SharedPreferences.Editor editor = settings.edit();
                editor.remove(Prefs.REGISTRATION_ID);
                editor.commit();
                updateUIIntent.putExtra(STATUS_EXTRA, UNREGISTERED_STATUS);
            }

            // Update dialog activity
            context.sendBroadcast(updateUIIntent);
        }
    }).start();
}

From source file:pj.rozkladWKD.DeviceRegistrar.java

public static void registerWithServer(final Context context, final String deviceRegistrationID) {
    new Thread(new Runnable() {
        public void run() {
            Intent updateUIIntent = new Intent("com.google.ctp.UPDATE_UI");
            try {
                List<NameValuePair> post = new ArrayList<NameValuePair>();
                post.add(new BasicNameValuePair("requestType", "REGISTER_PUSH"));
                post.add(new BasicNameValuePair("deviceId", DeviceIdGenerator.getDeviceId()));
                post.add(new BasicNameValuePair("clientRegistrationId", deviceRegistrationID));
                post.add(new BasicNameValuePair("productId", context.getString(R.string.productId)));

                JSONObject result = HttpClient.SendHttpPost(post);

                if (result == null || result.getString("result") == "ERROR") {
                    updateUIIntent.putExtra(STATUS_EXTRA, ERROR_STATUS);

                } else {
                    updateUIIntent.putExtra(STATUS_EXTRA, REGISTERED_STATUS);
                    SharedPreferences settings = Prefs.get(context);
                    SharedPreferences.Editor editor = settings.edit();
                    editor.putString(Prefs.REGISTRATION_ID, deviceRegistrationID);
                    editor.commit();//from   w w  w  .  ja v  a  2 s . c  o m
                }

                context.sendBroadcast(updateUIIntent);

            } catch (Exception e) {
                updateUIIntent.putExtra(STATUS_EXTRA, ERROR_STATUS);
                context.sendBroadcast(updateUIIntent);
            }
        }
    }).start();
}

From source file:org.ado.minesync.gui.fragment.DropboxFragment.java

private void notifyDropboxAccountLinked(Context fragmentActivity) {
    Intent dropboxAccountIntent = new Intent(INTENT_DROPBOX_ACCOUNT);
    dropboxAccountIntent.putExtra(INTENT_PARAMETER_ACCOUNT_STATUS, INTENT_PARAMETER_VALUE_LINKED);
    fragmentActivity.sendBroadcast(dropboxAccountIntent);
}

From source file:org.herrlado.websms.connector.smsge.ConnectorSmsge.java

/**
 * Load captcha and wait for user input to solve it.
 * //from w  w  w  .j  a  va2s  . c  o  m
 * @param context
 *            {@link Context}
 * @param flow
 *            _flowExecutionKey
 * @return true if captcha was solved
 * @throws IOException
 *             IOException
 */
private String solveCaptcha(final ConnectorContext ctx) throws IOException {

    HttpGet cap = new HttpGet(URL_CAPTCHA);
    cap.addHeader("Referer", "http://www.sms.ge/ngeo/index.php");
    cap.setHeader("User-Agent", FAKE_USER_AGENT);
    HttpResponse response = ctx.getClient().execute(cap);
    int resp = response.getStatusLine().getStatusCode();
    if (resp != HttpURLConnection.HTTP_OK) {
        throw new WebSMSException(ctx.getContext(), R.string.error_http, "" + resp);
    }
    BitmapDrawable captcha = new BitmapDrawable(response.getEntity().getContent());
    final Intent intent = new Intent(Connector.ACTION_CAPTCHA_REQUEST);
    intent.putExtra(Connector.EXTRA_CAPTCHA_DRAWABLE, captcha.getBitmap());
    captcha = null;
    Context context = ctx.getContext();
    this.getSpec(context).setToIntent(intent);
    context.sendBroadcast(intent);
    try {
        synchronized (CAPTCHA_SYNC) {
            CAPTCHA_SYNC.wait(CAPTCHA_TIMEOUT);
        }
    } catch (InterruptedException e) {
        Log.e(TAG, null, e);
        return null;
    }
    if (captchaSolve == null) {
        return captchaSolve;
    }
    // got user response, try to solve captcha
    Log.d(TAG, "got solved captcha: " + captchaSolve);

    return captchaSolve;
}