Example usage for android.app Activity startActivityForResult

List of usage examples for android.app Activity startActivityForResult

Introduction

In this page you can find the example usage for android.app Activity startActivityForResult.

Prototype

public void startActivityForResult(@RequiresPermission Intent intent, int requestCode) 

Source Link

Document

Same as calling #startActivityForResult(Intent,int,Bundle) with no options.

Usage

From source file:io.github.acashjos.anarch.Session.java

/**
 * Initiates login flow./*  ww  w .  j  a  v  a 2 s  .c  o m*/
 * @param activity parent activity from which this method is called
 * @param successCallback callback to be called when login completes successfully
 */
public void openNewSession(Activity activity, SuccessCallback successCallback) {
    this.callback = successCallback;
    Intent i = new Intent(activity, WebViewLogin.class);
    i.putExtra("url", url);
    activity.startActivityForResult(i, LOGIN_UI);
}

From source file:com.nuvolect.securesuite.main.SharedMenu.java

public static void sharedOnRequestPermissionsResult(Activity act, int requestCode, String[] permissions,
        int[] grantResults) {

    switch (requestCode) {

    /**//from w  w  w.j a  v  a2  s  .  c o m
     * Service the result of a permission request
     */
    case CConst.IMPORT_VCARD_REQUEST_EXTERNAL_STORAGE: {

        // If request is cancelled, the result arrays are empty.
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

            // Kickoff a browser activity here.
            // When user selects file, onActivityResult called with the result.
            Intent intent = new Intent();
            intent.setClass(act, FileBrowserImportVcf.class);
            act.startActivityForResult(intent, CConst.IMPORT_VCARD_BROWSE_ACTION);
        } else {

            Toast.makeText(act, "Sorry, external storage permission required for import", Toast.LENGTH_SHORT)
                    .show();
        }
        break;
    }
    case CConst.IMPORT_SINGLE_CONTACT_REQUEST_READ: {
        /**
         * Launch the contact picker intent.
         * Results returned in onActivityResult()
         */
        Intent contactPickerIntent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
        m_act.startActivityForResult(contactPickerIntent, CConst.IMPORT_SINGLE_CONTACT_PICKER);
        break;
    }
    case CConst.IMPORT_ACCOUNT_CONTACTS_REQUEST_READ_CONTACTS: {

        // If request is cancelled, the result arrays are empty.
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

            CloudImportDialog.openDialog(act);

        } else {

            Toast.makeText(m_act, "Sorry, read contacts permission required for import", Toast.LENGTH_SHORT)
                    .show();
        }
        break;
    }
    case CConst.CALLER_ID_REQUEST_READ_PHONE_STATE:
        // If request is cancelled, the result arrays are empty.
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

            // Do nothing
            //                    Toast.makeText(m_act, "Caller identification enabled", Toast.LENGTH_SHORT).show();

        } else {

            Toast.makeText(m_act, "Calls will not be identified without Read Phone State", Toast.LENGTH_SHORT)
                    .show();
        }
        break;
    case CConst.REQUEST_WRITE_EXTERNAL_STORAGE:
        // If request is cancelled, the result arrays are empty.
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

            // Do nothing
        } else {
            Toast.makeText(m_act, "App will be unable to save files to external storage", Toast.LENGTH_SHORT)
                    .show();
        }
        break;
    default: {

        LogUtil.log("SharedMenu sharedOnRequestPermissionResult UNMANAGED/ERROR requestCode: " + requestCode);

        for (int i = 0; i < permissions.length; i++)
            LogUtil.log("SharedMenuUtil permissions: " + permissions[i] + "  " + grantResults[i]);

    }
    }
}

From source file:io.flutter.plugins.imagepicker.ImagePickerPlugin.java

@Override
public boolean onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    if (requestCode == REQUEST_EXTERNAL_STORAGE_PERMISSIONS
            && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
        pickImageFromGallery(registrar.activity());
    } else if (requestCode == REQUEST_CAMERA_PERMISSIONS) {
        if (grantResults.length == 2 && grantResults[0] == PackageManager.PERMISSION_GRANTED
                && grantResults[1] == PackageManager.PERMISSION_GRANTED) {
            Activity activity = registrar.activity();
            if (activity == null) {
                pendingResult.error("no_activity", "image_picker plugin requires a foreground activity.", null);
            }//from   ww  w  . ja v a 2  s.com
            activity.startActivityForResult(cameraModule.getCameraIntent(activity), REQUEST_CODE_CAMERA);
        } else {
            pendingResult.error("no_permissions", "image_picker plugin requires camera permissions", null);
            pendingResult = null;
            methodCall = null;
        }
        return true;
    }
    return false;
}

From source file:com.ez.gallery.ucrop.UCrop.java

/**
 * Send the crop Intent from an Activity with a custom request code
 *
 * @param activity    Activity to receive result
 * @param requestCode requestCode for result
 *//*from  ww w  . j  a  v  a 2s .c om*/
public void start(@NonNull Activity activity, int requestCode) {
    activity.startActivityForResult(getIntent(activity), requestCode);
}

From source file:com.mobileglobe.android.customdialer.common.compat.telecom.TelecomManagerCompat.java

/**
 * Places a new outgoing call to the provided address using the system telecom service with
 * the specified intent.//from   www . jav a2  s.  c om
 *
 * @param activity {@link Activity} used to start another activity for the given intent
 * @param telecomManager the {@link TelecomManager} used to place a call, if possible
 * @param intent the intent for the call
 */
public static void placeCall(@Nullable Activity activity, @Nullable TelecomManager telecomManager,
        @Nullable Intent intent) {
    if (activity == null || telecomManager == null || intent == null) {
        return;
    }
    if (CompatUtils.isMarshmallowCompatible()) {
        if (ActivityCompat.checkSelfPermission(activity,
                Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
            return;
        }
        telecomManager.placeCall(intent.getData(), intent.getExtras());
        return;
    }
    activity.startActivityForResult(intent, 0);
}

From source file:m2.android.archetype.example.aquery.fb.base.PQuery.java

public void start(Activity act, Intent intent, int requestCode, Object handler, String method) {

    // String clsName = handler.getClass().getName();

    intent.putExtra(FW_CB, method);/*from  w w w.ja  va 2s. c  o m*/

    if (handler instanceof Fragment) {
        Fragment frag = (Fragment) handler;
        intent.putExtra(FW_ID, frag.getId());
    }

    act.startActivityForResult(intent, requestCode);

}

From source file:com.bilibili.boxing.utils.CameraPickerHelper.java

private void startActivityForResult(Activity activity, Fragment fragment, final Intent intent,
        final int reqCodeCamera) throws ActivityNotFoundException {
    if (fragment == null) {
        activity.startActivityForResult(intent, reqCodeCamera);
    } else {//from ww w . j a  va 2 s . com
        fragment.startActivityForResult(intent, reqCodeCamera);
    }
}

From source file:org.onebusaway.android.report.ui.InfrastructureIssueActivity.java

/**
 * Starts the InfrastructureIssueActivity with a given open311 service category selected
 *
 * startActivityForResult was used to close the calling activity. This used in BaseReportActivity
 * to close it when a user submits an issue.
 *
 * @param activity       The parent activity.
 * @param intent         The Intent containing focusId, lat, lon of the map
 * @param obaArrivalInfo Arrival info for trip problems
 *//*from   w  w w  .j av a  2  s.  co m*/
public static void startWithService(Activity activity, Intent intent, String serviceKeyword,
        ObaArrivalInfo obaArrivalInfo, String agencyName) {
    intent = makeIntent(activity, intent);
    // Put trip issue specific data
    intent.putExtra(SELECTED_SERVICE, serviceKeyword);
    intent.putExtra(TRIP_INFO, obaArrivalInfo);
    intent.putExtra(AGENCY_NAME, agencyName);

    activity.startActivityForResult(intent, REQUEST_CODE);
}

From source file:org.mozilla.mozstumbler.client.navdrawer.MetricsView.java

public MetricsView(View view) {
    mView = view;/*  w  w w .jav a  2  s . c om*/

    LocalBroadcastManager.getInstance(mView.getContext()).registerReceiver(new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            Bundle bundle = intent.getExtras();
            mPersistedStats = (Properties) bundle.get(PersistedStats.EXTRAS_PERSISTENT_SYNC_STATUS_UPDATED);
            updateSentStats();
        }
    }, new IntentFilter(PersistedStats.ACTION_PERSISTENT_SYNC_STATUS_UPDATED));

    mOnMapShowMLS = (CheckBox) mView.findViewById(R.id.checkBox_show_mls);
    mOnMapShowMLS.setVisibility(View.GONE);
    mOnMapShowMLS.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            ClientPrefs.getInstance(mView.getContext()).setOnMapShowMLS(mOnMapShowMLS.isChecked());
            if (mMapLayerToggleListener.get() != null) {
                mMapLayerToggleListener.get().setShowMLS(mOnMapShowMLS.isChecked());
            }
        }
    });

    mLastUpdateTimeView = (TextView) mView.findViewById(R.id.last_upload_time_value);
    mAllTimeObservationsSentView = (TextView) mView.findViewById(R.id.observations_sent_value);
    mQueuedObservationsView = (TextView) mView.findViewById(R.id.observations_queued_value);
    mThisSessionObservationsView = (TextView) mView.findViewById(R.id.this_session_observations_value);
    mThisSessionUniqueCellsView = (TextView) mView.findViewById(R.id.cells_unique_value);
    mThisSessionUniqueAPsView = (TextView) mView.findViewById(R.id.wifis_unique_value);

    mUploadButton = (ImageButton) mView.findViewById(R.id.upload_observations_button);
    mUploadButton.setEnabled(false);
    mUploadButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!mHasQueuedObservations) {
                return;
            }

            AsyncUploader uploader = new AsyncUploader();
            AsyncUploadParam param = new AsyncUploadParam(false /* useWifiOnly */,
                    Prefs.getInstance(mView.getContext()).getNickname(),
                    Prefs.getInstance(mView.getContext()).getEmail());
            uploader.execute(param);

            setUploadButtonToSyncing(true);
        }
    });

    mSettingsButton = (ImageButton) mView.findViewById(R.id.metrics_settings_button);
    mSettingsButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Activity mainDrawer = (Activity) v.getContext();
            assert (mainDrawer instanceof MainDrawerActivity);
            mainDrawer.startActivityForResult(new Intent(v.getContext(), PreferencesScreen.class), 1);
        }
    });

    // Remove click listener of the Drawer buttons container to avoid to get it triggered on the Map view
    mButtonsContainer = (RelativeLayout) mView.findViewById(R.id.metrics_buttons_container);
    mButtonsContainer.setOnClickListener(null);

    mHandler.postDelayed(mUpdateLastUploadedLabel, FREQ_UPDATE_UPLOADTIME);

    Button showPowerButton = (Button) mView.findViewById(R.id.button_change_power_setting);
    if (Build.VERSION.SDK_INT >= 16) {
        Drawable clone = showPowerButton.getBackground().getConstantState().newDrawable();
        clone.setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0xFF106E99));
        showPowerButton.setBackground(clone);
    }
    showPowerButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Activity mainDrawer = (Activity) v.getContext();
            assert (mainDrawer instanceof MainDrawerActivity);
            mainDrawer.startActivityForResult(new Intent(v.getContext(), PowerSavingScreen.class), 1);
        }
    });
}

From source file:com.androidquery.simplefeed.PQuery.java

public void start(Activity act, Intent intent, int requestCode, Object handler, String method) {

    //String clsName = handler.getClass().getName();

    intent.putExtra(FW_CB, method);//from  www .j  a va 2s. c o m

    if (handler instanceof Fragment) {
        Fragment frag = (Fragment) handler;
        intent.putExtra(FW_ID, frag.getId());
    }

    act.startActivityForResult(intent, requestCode);

}