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:io.teak.sdk.TeakNotification.java

static void cancel(Context context, int platformId) {
    if (notificationManager == null) {
        try {/* w ww .ja  v a  2  s.  com*/
            notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        } catch (Exception e) {
            Log.e(LOG_TAG, Log.getStackTraceString(e));
            return;
        }
    }

    if (Teak.isDebug) {
        Log.d(LOG_TAG, "Canceling notification id: " + platformId);
    }

    notificationManager.cancel(NOTIFICATION_TAG, platformId);
    context.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));

    Thread updateThread = TeakNotification.notificationUpdateThread.get(platformId);
    if (updateThread != null) {
        updateThread.interrupt();
    }
}

From source file:com.browsertophone.C2DMReceiver.java

@Override
public void onError(Context context, String errorId) {
    context.sendBroadcast(new Intent("com.browsertophone.btp.UPDATE_UI"));
}

From source file:com.amaze.filemanager.utils.files.FileUtils.java

/**
 * Triggers {@link Intent#ACTION_MEDIA_SCANNER_SCAN_FILE} intent to refresh the media store.
 *
 * @param uri File's {@link Uri}/*  w  w w  .j  a v a 2 s  . c  om*/
 * @param c {@link Context}
 */
public static void scanFile(@NonNull Uri uri, @NonNull Context c) {
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri);
    c.sendBroadcast(mediaScanIntent);
}

From source file:com.bandbaaja.c2dm.C2DMReceiver.java

@Override
public void onError(Context context, String errorId) {
    //TODO: handle error particularly in registration
    context.sendBroadcast(new Intent("com.google.ctp.UPDATE_UI"));
}

From source file:library.artaris.cn.library.utils.SystemUtils.java

/**
 * ???//  ww w  .  j a  v  a 2  s. c o m
 * @param context
 * @param shortCutName
 * @param icon
 * @param cls
 */
public static void createDeskShortCut(Context context, String shortCutName, int icon, Class<?> cls) {
    Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    shortcutIntent.putExtra("duplicate", false);
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortCutName);
    Parcelable ico = Intent.ShortcutIconResource.fromContext(context.getApplicationContext(), icon);
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, ico);
    Intent intent = new Intent(context, cls);
    intent.setAction("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.LAUNCHER");
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
    context.sendBroadcast(shortcutIntent);
}

From source file:com.google.android.apps.chrometophone.DeviceRegistrar.java

public static void registerWithServer(final Context context, final String deviceRegistrationID) {
    new Thread(new Runnable() {
        @Override/*  ww  w. j  a v  a 2s . c o  m*/
        public void run() {
            Intent updateUIIntent = new Intent("com.google.ctp.UPDATE_UI");
            try {
                HttpResponse res = makeRequest(context, deviceRegistrationID, REGISTER_PATH);
                if (res.getStatusLine().getStatusCode() == 200) {
                    GCMRegistrar.setRegisteredOnServer(context, true);
                    updateUIIntent.putExtra(STATUS_EXTRA, REGISTERED_STATUS);
                } else if (res.getStatusLine().getStatusCode() == 400) {
                    updateUIIntent.putExtra(STATUS_EXTRA, AUTH_ERROR_STATUS);
                } else {
                    Log.w(TAG, "Registration error " + String.valueOf(res.getStatusLine().getStatusCode()));
                    updateUIIntent.putExtra(STATUS_EXTRA, ERROR_STATUS);
                }
                context.sendBroadcast(updateUIIntent);
                // Check if this is an update from C2DM to GCM - if it is, remove the
                // old registration id.
                SharedPreferences settings = Prefs.get(context);
                String c2dmRegId = settings.getString("deviceRegistrationID", null);
                if (c2dmRegId != null) {
                    Log.i(TAG, "Removing old C2DM registration id");
                    SharedPreferences.Editor editor = settings.edit();
                    editor.remove("deviceRegistrationID");
                    editor.commit();
                }
            } catch (AppEngineClient.PendingAuthException pae) {
                // Get setup activity to ask permission from user.
                Intent intent = new Intent(SetupActivity.AUTH_PERMISSION_ACTION);
                intent.putExtra("AccountManagerBundle", pae.getAccountManagerBundle());
                context.sendBroadcast(intent);
            } catch (Exception e) {
                Log.w(TAG, "Registration error " + e.getMessage());
                updateUIIntent.putExtra(STATUS_EXTRA, ERROR_STATUS);
                context.sendBroadcast(updateUIIntent);
            }
        }
    }).start();
}

From source file:com.guinatal.refreshgallery.PluginRefreshGallery.java

/**
 * Executes the request and returns PluginResult.
 *
 * @param action            The action to execute.
 * @param args              JSONArry of arguments for the plugin.
 * @param callbackContext   The callback id used when calling back into JavaScript.
 * @return                  A PluginResult object with a status and message.
 *//*from  ww  w  .ja v  a2  s . co m*/

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {

    this.callbackContext = callbackContext;

    try {

        if (action.equals("refresh")) {

            String filePath = checkFilePath(args.getString(0));

            if (filePath.equals("")) {
                PluginResult r = new PluginResult(PluginResult.Status.ERROR);
                callbackContext.sendPluginResult(r);
                return true;
            }

            File file = new File(filePath);

            Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
            scanIntent.setData(Uri.fromFile(file));

            Context context = webView.getContext();
            context.sendBroadcast(scanIntent);
        }

        PluginResult r = new PluginResult(PluginResult.Status.OK);
        callbackContext.sendPluginResult(r);
        return true;

    } catch (JSONException e) {

        PluginResult r = new PluginResult(PluginResult.Status.JSON_EXCEPTION);
        callbackContext.sendPluginResult(r);
        return true;

    } catch (Exception e) {

        PluginResult r = new PluginResult(PluginResult.Status.ERROR);
        callbackContext.sendPluginResult(r);
        return true;
    }
}

From source file:com.lvlstudios.android.gtmessage.C2DMReceiver.java

@Override
public void onError(Context context, String errorId) {
    Log.e(TAG, "C2DMReceiver.onError: " + errorId);
    context.sendBroadcast(new Intent("com.google.ctp.UPDATE_UI"));
}

From source file:locationkitapp.locationkit.locationkitapp.ServiceReceiver.java

private void notifyVisitUpdated(Context context) {
    Intent i = new Intent(AppConstants.VISIT_UPDATED);
    context.sendBroadcast(i);
}

From source file:com.thyn.broadcast.MyGcmListenerService.java

public void updateChatRoomFragment(String sender, String profileID, String message) {

    Intent intent = new Intent("unique_chat_name");

    //put whatever data you want to send, if any
    intent.putExtra("message", message);
    intent.putExtra("sender", sender);
    intent.putExtra("profileID", profileID);

    Context context = this.getApplicationContext();
    //send broadcast
    context.sendBroadcast(intent);
}