Example usage for android.content Intent getAction

List of usage examples for android.content Intent getAction

Introduction

In this page you can find the example usage for android.content Intent getAction.

Prototype

public @Nullable String getAction() 

Source Link

Document

Retrieve the general action to be performed, such as #ACTION_VIEW .

Usage

From source file:com.android.launcher3.InstallShortcutReceiver.java

/**
 * Returns true if the intent is a valid launch intent for a shortcut.
 * This is used to identify shortcuts which are different from the ones exposed by the
 * applications' manifest file./*from w  w  w  . java  2s  .  co  m*/
 *
 * When DISABLE_ALL_APPS is true, shortcuts exposed via the app's manifest should never be
 * duplicated or removed(unless the app is un-installed).
 *
 * @param launchIntent The intent that will be launched when the shortcut is clicked.
 */
static boolean isValidShortcutLaunchIntent(Intent launchIntent) {
    if (launchIntent != null && Intent.ACTION_MAIN.equals(launchIntent.getAction())
            && launchIntent.getComponent() != null && launchIntent.getCategories() != null
            && launchIntent.getCategories().size() == 1 && launchIntent.hasCategory(Intent.CATEGORY_LAUNCHER)
            && launchIntent.getExtras() == null && TextUtils.isEmpty(launchIntent.getDataString())) {
        return false;
    }
    return true;
}

From source file:Main.java

@NonNull
private static String prepareCheckReceiverReport(@NonNull final Context context,
        @Nullable final String exceptionMessage, @Nullable final String receiverName,
        @NonNull final Intent broadcastIntent) {
    final StringBuilder reportBuilder = new StringBuilder("checkReceiver error").append(LINE_SEPARATOR)
            .append("Exception message : ").append(exceptionMessage).append(LINE_SEPARATOR)
            .append("Expected receiverName : ").append(receiverName).append(LINE_SEPARATOR)
            .append("Intent action : ").append(broadcastIntent.getAction());

    final PackageManager packageManager = context.getPackageManager();
    final List<ResolveInfo> receivers = packageManager.queryBroadcastReceivers(broadcastIntent,
            PackageManager.GET_INTENT_FILTERS);
    if (receivers == null) {
        reportBuilder.append(LINE_SEPARATOR).append("queryBroadcastReceivers returns null");
    } else if (receivers.isEmpty()) {
        reportBuilder.append(LINE_SEPARATOR).append("queryBroadcastReceivers returns empty list");
    } else {//from  www.ja  v a 2s  .  com
        reportBuilder.append(LINE_SEPARATOR)
                .append("queryBroadcastReceivers returns not empty list. List size : ").append(receivers.size())
                .append(LINE_SEPARATOR).append("PackageName : ").append(context.getPackageName());

        int emptyPackageNameCounter = 0;
        int emptyReceiverNameCounter = 0;
        for (ResolveInfo receiver : receivers) {
            if (TextUtils.isEmpty(receiver.activityInfo.packageName)) {
                ++emptyPackageNameCounter;
            } else if (receiver.activityInfo.packageName.equals(context.getPackageName())) {
                reportBuilder.append(LINE_SEPARATOR).append("Receiver with right package : ")
                        .append(receiver.activityInfo.name);
            }
            if (TextUtils.isEmpty(receiver.activityInfo.name)) {
                ++emptyReceiverNameCounter;
            } else if (receiver.activityInfo.name.equals(receiverName)) {
                reportBuilder.append(LINE_SEPARATOR).append("Receiver with right name has package : ")
                        .append(receiver.activityInfo.packageName);
            }
        }

        reportBuilder.append(LINE_SEPARATOR).append("Receivers with empty package name : ")
                .append(emptyPackageNameCounter).append(LINE_SEPARATOR).append("Receivers with empty name : ")
                .append(emptyReceiverNameCounter);
    }

    return reportBuilder.toString();
}

From source file:com.googlecode.android_scripting.jsonrpc.JsonBuilder.java

private static JSONObject buildJsonIntent(Intent data) throws JSONException {
    JSONObject result = new JSONObject();
    result.put("data", data.getDataString());
    result.put("type", data.getType());
    result.put("extras", build(data.getExtras()));
    result.put("categories", build(data.getCategories()));
    result.put("action", data.getAction());
    ComponentName component = data.getComponent();
    if (component != null) {
        result.put("packagename", component.getPackageName());
        result.put("classname", component.getClassName());
    }/*from ww  w  .  j a va  2 s  . c om*/
    result.put("flags", data.getFlags());
    return result;
}

From source file:com.cyanogenmod.account.util.CMAccountUtils.java

public static void scheduleRetry(Context context, SharedPreferences prefs, Intent intent) {
    int backoffTimeMs = getBackoff(prefs);
    int nextAttempt = backoffTimeMs / 2 + sRandom.nextInt(backoffTimeMs);
    if (CMAccount.DEBUG)
        Log.d(TAG, "Scheduling retry, backoff = " + nextAttempt + " (" + backoffTimeMs + ") for "
                + intent.getAction());
    PendingIntent retryPendingIntent = PendingIntent.getService(context, 0, intent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    am.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + nextAttempt, retryPendingIntent);
    if (backoffTimeMs < CMAccount.MAX_BACKOFF_MS) {
        setBackoff(prefs, backoffTimeMs * 2);
    }/*from   www .  j  a v a  2  s.  c  o  m*/
}

From source file:com.phonemetra.account.util.AccountUtils.java

public static void scheduleRetry(Context context, SharedPreferences prefs, Intent intent) {
    int backoffTimeMs = getBackoff(prefs);
    int nextAttempt = backoffTimeMs / 2 + sRandom.nextInt(backoffTimeMs);
    if (Account.DEBUG)
        Log.d(TAG, "Scheduling retry, backoff = " + nextAttempt + " (" + backoffTimeMs + ") for "
                + intent.getAction());
    PendingIntent retryPendingIntent = PendingIntent.getService(context, 0, intent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    am.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + nextAttempt, retryPendingIntent);
    if (backoffTimeMs < Account.MAX_BACKOFF_MS) {
        setBackoff(prefs, backoffTimeMs * 2);
    }//from  ww  w . j  a  va 2 s. c om
}

From source file:com.andernity.launcher2.InstallShortcutReceiver.java

private static boolean installShortcut(Context context, Intent data, ArrayList<ItemInfo> items, String name,
        final Intent intent, final int screen, boolean shortcutExists, final SharedPreferences sharedPrefs,
        int[] result) {
    int[] tmpCoordinates = new int[2];
    if (findEmptyCell(context, items, tmpCoordinates, screen)) {
        if (intent != null) {
            if (intent.getAction() == null) {
                intent.setAction(Intent.ACTION_VIEW);
            } else if (intent.getAction().equals(Intent.ACTION_MAIN) && intent.getCategories() != null
                    && intent.getCategories().contains(Intent.CATEGORY_LAUNCHER)) {
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
            }//  ww w . j a v a 2 s .co m

            // By default, we allow for duplicate entries (located in
            // different places)
            boolean duplicate = data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE, true);
            if (duplicate || !shortcutExists) {
                new Thread("setNewAppsThread") {
                    public void run() {
                        synchronized (sLock) {
                            // If the new app is going to fall into the same page as before,
                            // then just continue adding to the current page
                            final int newAppsScreen = sharedPrefs.getInt(NEW_APPS_PAGE_KEY, screen);
                            SharedPreferences.Editor editor = sharedPrefs.edit();
                            if (newAppsScreen == -1 || newAppsScreen == screen) {
                                addToStringSet(sharedPrefs, editor, NEW_APPS_LIST_KEY, intent.toUri(0));
                            }
                            editor.putInt(NEW_APPS_PAGE_KEY, screen);
                            editor.commit();
                        }
                    }
                }.start();

                // Update the Launcher db
                LauncherApplication app = (LauncherApplication) context.getApplicationContext();
                ShortcutInfo info = app.getModel().addShortcut(context, data,
                        LauncherSettings.Favorites.CONTAINER_DESKTOP, screen, tmpCoordinates[0],
                        tmpCoordinates[1], true);
                if (info == null) {
                    return false;
                }
            } else {
                result[0] = INSTALL_SHORTCUT_IS_DUPLICATE;
            }

            return true;
        }
    } else {
        result[0] = INSTALL_SHORTCUT_NO_SPACE;
    }

    return false;
}

From source file:org.metawatch.manager.Monitors.java

private static void createWifiReceiver(final Context context) {
    if (wifiReceiver != null)
        return;/*w  ww.j  a va2  s .c  o m*/
    WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = wm.getConnectionInfo();
    if (info != null)
        SignalData.wifiBars = 1 + WifiManager.calculateSignalLevel(info.getRssi(), 4);
    wifiReceiver = new BroadcastReceiver() {
        int wifiBars = 0;

        @Override
        public void onReceive(Context c, Intent intent) {
            String action = intent.getAction();
            if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
                if (intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
                        WifiManager.WIFI_STATE_UNKNOWN) != WifiManager.WIFI_STATE_ENABLED) {
                    wifiBars = 0;
                }
            } else if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) {
                if (!intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED, false)) {
                    wifiBars = 0;
                }
            } else if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
                NetworkInfo netInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
                if (netInfo.getState() != NetworkInfo.State.CONNECTED) {
                    wifiBars = 0;
                } else {
                    WifiInfo wifiInfo = intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO);
                    if (wifiInfo == null) {
                        wifiBars = 0;
                    } else {
                        wifiBars = 1 + WifiManager.calculateSignalLevel(wifiInfo.getRssi(), 4);
                    }
                }
            } else if (action.equals(WifiManager.RSSI_CHANGED_ACTION)) {
                final int newRssi = intent.getIntExtra(WifiManager.EXTRA_NEW_RSSI, -200);
                wifiBars = 1 + WifiManager.calculateSignalLevel(newRssi, 4);
            }
            if (wifiBars != SignalData.wifiBars) {
                SignalData.wifiBars = wifiBars;
                Idle.updateIdle(context, true);
            }
        }
    };
    IntentFilter f = new IntentFilter();
    f.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
    f.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
    f.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
    f.addAction(WifiManager.RSSI_CHANGED_ACTION);
    context.registerReceiver(wifiReceiver, f);
}

From source file:AlarmBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    if (ACTION_ALARM.equals(intent.getAction())) {
        Toast.makeText(context, ACTION_ALARM, Toast.LENGTH_SHORT).show();
    }/*from w ww. j av  a2s  . c  om*/
}

From source file:SMSBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    if (SMS_RECEIVED.equals(intent.getAction())) {
        Bundle bundle = intent.getExtras();
        if (bundle != null) {
            Object[] pdus = (Object[]) bundle.get("pdus");
            String format = bundle.getString("format");
            final SmsMessage[] messages = new SmsMessage[pdus.length];
            for (int i = 0; i < pdus.length; i++) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i], format);
                } else {
                    messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                }//from  www.  j a  va2s  . c  om
                Toast.makeText(context, messages[0].getMessageBody(), Toast.LENGTH_SHORT).show();
            }
        }
    }
}

From source file:androidavanzato.wearablenotifications.NotificationIntentReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(ACTION_EXAMPLE)) {
        if (mEnableMessages) {
            String message = intent.getStringExtra(NotificationUtil.EXTRA_MESSAGE);
            Bundle remoteInputResults = RemoteInput.getResultsFromIntent(intent);
            CharSequence replyMessage = null;
            if (remoteInputResults != null) {
                replyMessage = remoteInputResults.getCharSequence(NotificationUtil.EXTRA_REPLY);
            }//from  w  w w . j  a  v a2s .  c om
            if (replyMessage != null) {
                message = message + ": \"" + replyMessage + "\"";
            }
            Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
        }
    } else if (intent.getAction().equals(ACTION_ENABLE_MESSAGES)) {
        mEnableMessages = true;
    } else if (intent.getAction().equals(ACTION_DISABLE_MESSAGES)) {
        mEnableMessages = false;
    }
}