Example usage for android.content Intent getFlags

List of usage examples for android.content Intent getFlags

Introduction

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

Prototype

public @Flags int getFlags() 

Source Link

Document

Retrieve any special flags associated with this intent.

Usage

From source file:com.android.settings.HWSettings.java

@Override
public void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    // If it is not launched from history, then reset to top-level
    if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0) {
        if (mFirstHeader != null && !onIsHidingHeaders() && onIsMultiPane()) {
            switchToHeaderLocal(mFirstHeader);
        }/*from  w ww.  j av a 2  s.co m*/
        getListView().setSelectionFromTop(0, 0);
    }
}

From source file:com.heightechllc.breakify.MainActivity.java

/**
 * Handles a new intent, either from onNewIntent() or onCreate()
 * @param intent The intent to handle/*from   w ww.  j a va2 s . c o  m*/
 * @return Whether we should attempt to restore the saved timer state. Will be false when
 *  this method opens another Activity.
 */
private boolean handleIntent(Intent intent) {
    boolean shouldRestoreSavedTimer = true;

    if (intent.getBooleanExtra(EXTRA_SNOOZE, false)) {
        // The activity was launched from the expanded notification's "Snooze" action

        snoozeTimer();
        // In case user didn't interact with the RingingActivity, and instead snoozed directly
        //  from the notification
        AlarmRinger.stop(this);

        // Don't restore, since we're about to open a new Activity
        shouldRestoreSavedTimer = false;

    } else if (intent.getBooleanExtra(EXTRA_ALARM_RING, false)) {
        // The Activity was launched from AlarmReceiver, meaning the timer finished and we
        //  need to ring the alarm

        Intent ringingIntent = new Intent(this, RingingActivity.class);
        // Pass along FLAG_ACTIVITY_NO_USER_ACTION if it was set when calling this activity
        if ((intent.getFlags() & Intent.FLAG_ACTIVITY_NO_USER_ACTION) != 0)
            ringingIntent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION);
        startActivityForResult(ringingIntent, RingingActivity.REQUEST_ALARM_RING);

        // Don't restore, since we're about to open a new Activity
        shouldRestoreSavedTimer = false;

    } else if (intent.getBooleanExtra(EXTRA_SCHEDULED_START, false)) {
        // The Activity was launched from ScheduledStartReceiver, meaning it's time for the
        //  scheduled start

        // Show a dialog prompting the user to start
        new AlertDialog.Builder(this).setTitle(R.string.scheduled_dialog_title)
                .setMessage(R.string.scheduled_dialog_message)
                .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        // Start the timer
                        circleTimer.performClick();
                    }
                }).setNeutralButton(R.string.action_settings, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        // Show the settings activity with the Scheduled Start settings
                        Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
                        intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT,
                                ScheduledStartSettingsFragment.class.getName());
                        intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT_TITLE,
                                R.string.pref_category_scheduled);
                        startActivity(intent);
                    }
                }).setNegativeButton(R.string.cancel, null).show();
    }

    return shouldRestoreSavedTimer;
}

From source file:com.HumanDecisionSupportSystemsLaboratory.DD_P2P.Main.java

@TargetApi(Build.VERSION_CODES.KITKAT)
@Override/*  ww  w.  jav a2  s . c om*/
protected void onActivityResult(int requestCode, int resultCode, Intent resultData) {
    if (resultCode == RESULT_OK && requestCode == this.RESULT_ADD_PEER) {
        byte[] _pi = resultData.getByteArrayExtra(AddSafe.PI);
        net.ddp2p.common.hds.PeerInput pi = null;
        if (_pi != null)
            try {
                pi = new PeerInput().decode(new Decoder(_pi));
            } catch (Exception e) {
                e.printStackTrace();
            }
        if (pi == null)
            pi = Safe.peerInput;
        new PeerCreatingThread(pi).start();

        super.onActivityResult(requestCode, resultCode, resultData);
        return;
    }
    if (resultCode == RESULT_OK && resultData != null) {
        Uri uri = null;

        if (requestCode == SELECT_PHOTO) {
            uri = resultData.getData();
            Log.i("Uri", "Uri: " + uri.toString());
        } else if (requestCode == SELECT_PHOTO_KITKAT) {
            uri = resultData.getData();
            Log.i("Uri_kitkat", "Uri: " + uri.toString());
            final int takeFlags = resultData.getFlags()
                    & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            // Check for the freshest data.
            getContentResolver().takePersistableUriPermission(uri, takeFlags);
        }

        selectedImagePath = FileUtils.getPath(this, uri);
        Log.i("path", "path: " + selectedImagePath);

        selectImageFile = new File(selectedImagePath);
        String error;
        StegoStructure adr[] = DD.getAvailableStegoStructureInstances();
        int[] selected = new int[1];
        try {
            error = DD.loadBMP(selectImageFile, adr, selected);
            Log.i("error", "error: " + error);
            if (error == "") {
                adr[selected[0]].save();
                Toast.makeText(this, "add new safe other successfully!", Toast.LENGTH_SHORT).show();
            }
        } catch (Exception e) {
            Toast.makeText(this, "Unable to load safe from this photo!", Toast.LENGTH_SHORT).show();
            e.printStackTrace();
        }

    }
    super.onActivityResult(requestCode, resultCode, resultData);
}

From source file:androidx.navigation.NavController.java

/**
 * Checks the given Intent for a Navigation deep link and navigates to the deep link if present.
 * This is called automatically for you the first time you set the graph if you've passed in an
 * {@link Activity} as the context when constructing this NavController, but should be manually
 * called if your Activity receives new Intents in {@link Activity#onNewIntent(Intent)}.
 * <p>/*from   w  w w .j a  v  a  2s .  c  o  m*/
 * The types of Intents that are supported include:
 * <ul>
 *     <ol>Intents created by {@link NavDeepLinkBuilder} or
 *     {@link #createDeepLink()}. This assumes that the current graph shares
 *     the same hierarchy to get to the deep linked destination as when the deep link was
 *     constructed.</ol>
 *     <ol>Intents that include a {@link Intent#getData() data Uri}. This Uri will be checked
 *     against the Uri patterns added via {@link NavDestination#addDeepLink(String)}.</ol>
 * </ul>
 * <p>The {@link #getGraph() navigation graph} should be set before calling this method.</p>
 * @param intent The Intent that may contain a valid deep link
 * @return True if the navigation controller found a valid deep link and navigated to it.
 * @see NavDestination#addDeepLink(String)
 */
public boolean onHandleDeepLink(@Nullable Intent intent) {
    if (intent == null) {
        return false;
    }
    Bundle extras = intent.getExtras();
    int[] deepLink = extras != null ? extras.getIntArray(KEY_DEEP_LINK_IDS) : null;
    Bundle bundle = new Bundle();
    Bundle deepLinkExtras = extras != null ? extras.getBundle(KEY_DEEP_LINK_EXTRAS) : null;
    if (deepLinkExtras != null) {
        bundle.putAll(deepLinkExtras);
    }
    if ((deepLink == null || deepLink.length == 0) && intent.getData() != null) {
        Pair<NavDestination, Bundle> matchingDeepLink = mGraph.matchDeepLink(intent.getData());
        if (matchingDeepLink != null) {
            deepLink = matchingDeepLink.first.buildDeepLinkIds();
            bundle.putAll(matchingDeepLink.second);
        }
    }
    if (deepLink == null || deepLink.length == 0) {
        return false;
    }
    bundle.putParcelable(KEY_DEEP_LINK_INTENT, intent);
    int flags = intent.getFlags();
    if ((flags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0 && (flags & Intent.FLAG_ACTIVITY_CLEAR_TASK) == 0) {
        // Someone called us with NEW_TASK, but we don't know what state our whole
        // task stack is in, so we need to manually restart the whole stack to
        // ensure we're in a predictably good state.
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(mContext)
                .addNextIntentWithParentStack(intent);
        taskStackBuilder.startActivities();
        if (mActivity != null) {
            mActivity.finish();
        }
        return true;
    }
    if ((flags & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
        // Start with a cleared task starting at our root when we're on our own task
        if (!mBackStack.isEmpty()) {
            navigate(mGraph.getStartDestination(), bundle, new NavOptions.Builder()
                    .setPopUpTo(mGraph.getId(), true).setEnterAnim(0).setExitAnim(0).build());
        }
        int index = 0;
        while (index < deepLink.length) {
            int destinationId = deepLink[index++];
            NavDestination node = findDestination(destinationId);
            if (node == null) {
                throw new IllegalStateException("unknown destination during deep link: "
                        + NavDestination.getDisplayName(mContext, destinationId));
            }
            node.navigate(bundle, new NavOptions.Builder().setEnterAnim(0).setExitAnim(0).build());
        }
        return true;
    }
    // Assume we're on another apps' task and only start the final destination
    NavGraph graph = mGraph;
    for (int i = 0; i < deepLink.length; i++) {
        int destinationId = deepLink[i];
        NavDestination node = i == 0 ? mGraph : graph.findNode(destinationId);
        if (node == null) {
            throw new IllegalStateException("unknown destination during deep link: "
                    + NavDestination.getDisplayName(mContext, destinationId));
        }
        if (i != deepLink.length - 1) {
            // We're not at the final NavDestination yet, so keep going through the chain
            graph = (NavGraph) node;
        } else {
            // Navigate to the last NavDestination, clearing any existing destinations
            node.navigate(bundle, new NavOptions.Builder().setPopUpTo(mGraph.getId(), true).setEnterAnim(0)
                    .setExitAnim(0).build());
        }
    }
    return true;
}

From source file:jackpal.androidterm.Term.java

@Override
protected void onNewIntent(Intent intent) {
    if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0) {
        // Don't repeat action if intent comes from history
        return;/*from  ww  w. j  a  va 2 s .c  o m*/
    }

    String action = intent.getAction();
    if (TextUtils.isEmpty(action) || !mPrivateAlias.equals(intent.getComponent())) {
        return;
    }

    // huge number simply opens new window
    // TODO: add a way to restrict max number of windows per caller (possibly via reusing BoundSession)
    switch (action) {
    case RemoteInterface.PRIVACT_OPEN_NEW_WINDOW:
        onResumeSelectWindow = Integer.MAX_VALUE;
        break;
    case RemoteInterface.PRIVACT_SWITCH_WINDOW:
        int target = intent.getIntExtra(RemoteInterface.PRIVEXTRA_TARGET_WINDOW, -1);
        if (target >= 0) {
            onResumeSelectWindow = target;
        } else {
            onResumeSelectWindowHandle = intent.getStringExtra(RemoteInterface.EXTRA_WINDOW_HANDLE);
        }
        break;
    }
}

From source file:org.transdroid.gui.TorrentsFragment.java

private boolean isLaunchedFromHistory(final Intent startIntent) {
    return (startIntent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0;
}

From source file:de.ub0r.android.websms.WebSMS.java

/**
 * Update {@link ConnectorSpec}s./* w  w  w  . j  ava 2s  . c o  m*/
 */
private void updateConnectors() {
    // query for connectors
    final Intent i = new Intent(Connector.ACTION_CONNECTOR_UPDATE);
    i.setFlags(i.getFlags() | Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
    Log.d(TAG, "send broadcast: " + i.getAction());
    newConnectorsExpected = this.getInstalledConnectorsCount() - CONNECTORS.size();
    updateProgressBar();
    this.sendBroadcast(i);
}

From source file:de.ub0r.android.websms.WebSMS.java

/**
 * Send a command as broadcast./*from   ww w  .j  av a 2s .c o m*/
 *
 * @param context   Current context
 * @param connector {@link ConnectorSpec}
 * @param command   {@link ConnectorCommand}
 */
static void runCommand(final Context context, final ConnectorSpec connector, final ConnectorCommand command) {
    connector.setErrorMessage((String) null);
    final Intent intent = command.setToIntent(null);
    short t = command.getType();
    boolean sendOrdered = false;
    switch (t) {
    case ConnectorCommand.TYPE_BOOTSTRAP:
        sendOrdered = true;
        intent.setAction(connector.getPackage() + Connector.ACTION_RUN_BOOTSTRAP);
        connector.addStatus(ConnectorSpec.STATUS_BOOTSTRAPPING);
        break;
    case ConnectorCommand.TYPE_SEND:
        sendOrdered = true;
        intent.setAction(connector.getPackage() + Connector.ACTION_RUN_SEND);
        connector.setToIntent(intent);
        connector.addStatus(ConnectorSpec.STATUS_SENDING);
        if (command.getResendCount() == 0) {
            WebSMSReceiver.saveMessage(me, connector, command, WebSMSReceiver.MESSAGE_TYPE_DRAFT);
        }
        break;
    case ConnectorCommand.TYPE_UPDATE:
        intent.setAction(connector.getPackage() + Connector.ACTION_RUN_UPDATE);
        connector.addStatus(ConnectorSpec.STATUS_UPDATING);
        break;
    default:
        break;
    }
    updateProgressBar();
    intent.setFlags(intent.getFlags() | Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
    Log.d(TAG, "send broadcast: " + intent.getAction());
    if (sendOrdered) {
        context.sendOrderedBroadcast(intent, null, new BroadcastReceiver() {
            @Override
            public void onReceive(final Context context, final Intent intent) {
                if (this.getResultCode() != Activity.RESULT_OK) {
                    ConnectorCommand command = new ConnectorCommand(intent);
                    ConnectorSpec specs = new ConnectorSpec(intent);
                    specs.setErrorMessage(// TODO: localize
                            "Connector did not react on message");
                    WebSMSReceiver.handleSendCommand(context, specs, command);
                }
            }
        }, null, Activity.RESULT_CANCELED, null, null);
    } else {
        context.sendBroadcast(intent);
    }
}

From source file:com.free.searcher.MainFragment.java

/**
 * After triggering the Storage Access Framework, ensure that folder is really writable. Set preferences
 * accordingly.//  w w  w  .j a  v a  2s. com
 *
 * @param requestCode The integer request code originally supplied to startActivityForResult(), allowing you to identify who
 *                    this result came from.
 * @param resultCode  The integer result code returned by the child activity through its setResult().
 * @param data        An Intent, which can return result data to the caller (various data can be attached to Intent
 *                    "extras").
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void onActivityResultLollipop(final int requestCode, final int resultCode, @NonNull final Intent data) {

    if (requestCode == INTENT_WRITE_REQUEST_CODE) {

        if (resultCode == Activity.RESULT_OK) {
            // Get Uri from Storage Access Framework. 
            Uri treeUri = data.getData();
            // Persist URI in shared preference so that you can use it later. 
            // Use your own framework here instead of PreferenceUtil. 

            FileUtils.setSharedPreferenceUri(R.string.key_internal_uri_extsdcard, treeUri);
            // Persist access permissions. 
            final int takeFlags = data.getFlags()
                    & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            System.out.println("treeUri:" + treeUri);
            System.out.println("takeFlags" + String.valueOf(takeFlags));
            System.out.println("data.getFlags()" + String.valueOf(data.getFlags()));
            activity.getContentResolver().takePersistableUriPermission(treeUri, takeFlags);
        }
    }

}

From source file:com.mb.android.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == PURCHASE_REQUEST) {
        if (resultCode == RESULT_OK) {

            if (currentProduct.getEmbyFeatureCode() != null) {

                AppstoreRegRequest request = new AppstoreRegRequest();
                request.setStore(intent.getStringExtra("store"));
                request.setApplication(AppPackageName);
                request.setProduct(currentProduct.getSku());
                request.setFeature(currentProduct.getEmbyFeatureCode());
                request.setType(currentProduct.getProductType().toString());
                if (intent.getStringExtra("storeId") != null)
                    request.setStoreId(intent.getStringExtra("storeId"));
                request.setStoreToken(intent.getStringExtra("storeToken"));
                request.setEmail(purchaseEmail);
                request.setAmt(currentProduct.getPrice());

                RespondToWebView(String.format("window.IapManager.onPurchaseComplete("
                        + jsonSerializer.SerializeToString(request) + ");"));
            } else {
                // no emby feature - just report success
                RespondToWebView(String.format("window.IapManager.onPurchaseComplete(true);"));
            }//from w w w  .  j  a va 2s. c  om
        } else {
            RespondToWebView(String.format("window.IapManager.onPurchaseComplete(false);"));
        }
    }

    else if (requestCode == REQUEST_DIRECTORY_SAF && resultCode == Activity.RESULT_OK) {

        Uri uri = intent.getData();
        final int takeFlags = intent.getFlags()
                & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        // Check for the freshest data.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getContentResolver().takePersistableUriPermission(uri, takeFlags);
        }
        RespondToWebviewWithSelectedPath(uri);
    } else if (requestCode == REQUEST_DIRECTORY && resultCode == RESULT_OK) {

        if (intent.getBooleanExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false)) {
            // For JellyBean and above
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                ClipData clip = intent.getClipData();

                if (clip != null) {
                    for (int i = 0; i < clip.getItemCount(); i++) {
                        Uri uri = clip.getItemAt(i).getUri();
                        RespondToWebviewWithSelectedPath(uri);
                    }
                }
                // For Ice Cream Sandwich
            } else {
                ArrayList<String> paths = intent.getStringArrayListExtra(FilePickerActivity.EXTRA_PATHS);

                if (paths != null) {
                    for (String path : paths) {
                        Uri uri = Uri.parse(path);
                        RespondToWebviewWithSelectedPath(uri);
                    }
                }
            }

        } else {
            Uri uri = intent.getData();
            // Do something with the URI
            if (uri != null) {
                RespondToWebviewWithSelectedPath(uri);
            }
        }
    }

    else if (requestCode == VIDEO_PLAYBACK) {

        /*boolean completed = resultCode == RESULT_OK;
        boolean error = resultCode == RESULT_OK ? false : (intent == null ? true : intent.getBooleanExtra("error", false));
                
        long positionMs = intent == null || completed ? 0 : intent.getLongExtra("position", 0);
        String currentSrc = intent == null ? null : intent.getStringExtra(VideoPlayerActivity.PLAY_EXTRA_ITEM_LOCATION);
                
        if (currentSrc == null) {
        currentSrc = "";
        }
                
        RespondToWebView(String.format("VideoRenderer.Current.onActivityClosed(%s, %s, %s, '%s');", !completed, error, positionMs, currentSrc));*/
    }
}