本文整理了Java中android.app.Activity.startActivityForResult()
方法的一些代码示例,展示了Activity.startActivityForResult()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Activity.startActivityForResult()
方法的具体详情如下:
包路径:android.app.Activity
类名称:Activity
方法名:startActivityForResult
暂无
代码示例来源:origin: facebook/stetho
public static void showForResult(
Activity context,
int requestCode,
String hostAndMaybePort,
String nickname) {
Intent intent = new Intent(context, IRCChatActivity.class);
intent.putExtra(EXTRA_HOST_AND_MAYBE_PORT, hostAndMaybePort);
intent.putExtra(EXTRA_NICKNAME, nickname);
context.startActivityForResult(intent, requestCode);
}
代码示例来源:origin: commonsguy/cw-omnibus
public static void takePhoto(Activity requester, int requestCode) {
Intent i=new Intent(requester, CameraActivity.class);
requester.startActivityForResult(i, requestCode);
}
代码示例来源:origin: commonsguy/cw-omnibus
public static void takePhoto(Activity requester, int requestCode) {
Intent i=new Intent(requester, CameraActivity.class)
.putExtra(EXTRA_IS_PHOTO, true);
requester.startActivityForResult(i, requestCode);
}
代码示例来源:origin: commonsguy/cw-omnibus
public static void recordVideo(Activity requester, int requestCode) {
Intent i=new Intent(requester, CameraActivity.class)
.putExtra(EXTRA_IS_PHOTO, false);
requester.startActivityForResult(i, requestCode);
}
代码示例来源:origin: Yalantis/uCrop
/**
* Send the crop Intent from an Activity with a custom request code
*
* @param activity Activity to receive result
* @param requestCode requestCode for result
*/
public void start(@NonNull Activity activity, int requestCode) {
activity.startActivityForResult(getIntent(activity), requestCode);
}
代码示例来源:origin: googlesamples/easypermissions
private void startForResult(Intent intent) {
if (mActivityOrFragment instanceof Activity) {
((Activity) mActivityOrFragment).startActivityForResult(intent, mRequestCode);
} else if (mActivityOrFragment instanceof Fragment) {
((Fragment) mActivityOrFragment).startActivityForResult(intent, mRequestCode);
}
}
代码示例来源:origin: naman14/Timber
public static void navigateToEqualizer(Activity context) {
try {
// The google MusicFX apps need to be started using startActivityForResult
context.startActivityForResult(TimberUtils.createEffectsIntent(), 666);
} catch (final ActivityNotFoundException notFound) {
Toast.makeText(context, "Equalizer not found", Toast.LENGTH_SHORT).show();
}
}
代码示例来源:origin: jdamcd/android-crop
/**
* Send the crop Intent from an Activity with a custom request code
*
* @param activity Activity to receive result
* @param requestCode requestCode for result
*/
public void start(Activity activity, int requestCode) {
activity.startActivityForResult(getIntent(activity), requestCode);
}
代码示例来源:origin: k9mail/k-9
public static void actionCheckSettings(Activity context, Account account,
CheckDirection direction) {
Intent i = new Intent(context, AccountSetupCheckSettings.class);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
i.putExtra(EXTRA_CHECK_DIRECTION, direction);
context.startActivityForResult(i, ACTIVITY_REQUEST_CODE);
}
代码示例来源:origin: ArthurHub/Android-Image-Cropper
/**
* Start an activity to get image for cropping using chooser intent that will have all the
* available applications for the device like camera (MyCamera), galery (Photos), store apps
* (Dropbox), etc.<br>
* Use "pick_image_intent_chooser_title" string resource to override pick chooser title.
*
* @param activity the activity to be used to start activity from
*/
public static void startPickImageActivity(@NonNull Activity activity) {
activity.startActivityForResult(
getPickImageChooserIntent(activity), PICK_IMAGE_CHOOSER_REQUEST_CODE);
}
代码示例来源:origin: ArthurHub/Android-Image-Cropper
/**
* Start {@link CropImageActivity}.
*
* @param activity activity to receive result
*/
public void start(@NonNull Activity activity, @Nullable Class<?> cls) {
mOptions.validate();
activity.startActivityForResult(getIntent(activity, cls), CROP_IMAGE_ACTIVITY_REQUEST_CODE);
}
代码示例来源:origin: ArthurHub/Android-Image-Cropper
/**
* Start {@link CropImageActivity}.
*
* @param activity activity to receive result
*/
public void start(@NonNull Activity activity) {
mOptions.validate();
activity.startActivityForResult(getIntent(activity), CROP_IMAGE_ACTIVITY_REQUEST_CODE);
}
代码示例来源:origin: facebook/facebook-android-sdk
@Test
public void testLogInWithReadAndActivityStartsFacebookActivityWithCorrectRequest() {
LoginManager loginManager = new LoginManager();
loginManager.logInWithReadPermissions(mockActivity,
Arrays.asList("public_profile", "user_friends"));
ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class);
verify(mockActivity).startActivityForResult(intentArgumentCaptor.capture(), anyInt());
Intent intent = intentArgumentCaptor.getValue();
ComponentName componentName = intent.getComponent();
assertEquals(FacebookActivity.class.getName(), componentName.getClassName());
assertEquals(LoginBehavior.NATIVE_WITH_FALLBACK.name(), intent.getAction());
}
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldSupportStartActivityForResult() throws Exception {
activity = Robolectric.setupActivity(DialogLifeCycleActivity.class);
ShadowActivity shadowActivity = shadowOf(activity);
Intent intent = new Intent().setClass(activity, DialogLifeCycleActivity.class);
assertThat(shadowActivity.getNextStartedActivity()).isNull();
activity.startActivityForResult(intent, 142);
Intent startedIntent = shadowActivity.getNextStartedActivity();
assertThat(startedIntent).isNotNull();
assertThat(startedIntent).isSameAs(intent);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldSupportGetStartedActivitiesForResult() throws Exception {
activity = Robolectric.setupActivity(DialogLifeCycleActivity.class);
ShadowActivity shadowActivity = shadowOf(activity);
Intent intent = new Intent().setClass(activity, DialogLifeCycleActivity.class);
activity.startActivityForResult(intent, 142);
ShadowActivity.IntentForResult intentForResult = shadowActivity.getNextStartedActivityForResult();
assertThat(intentForResult).isNotNull();
assertThat(shadowActivity.getNextStartedActivityForResult()).isNull();
assertThat(intentForResult.intent).isNotNull();
assertThat(intentForResult.intent).isSameAs(intent);
assertThat(intentForResult.requestCode).isEqualTo(142);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldSupportPeekStartedActivitiesForResult() throws Exception {
activity = Robolectric.setupActivity(DialogLifeCycleActivity.class);
ShadowActivity shadowActivity = shadowOf(activity);
Intent intent = new Intent().setClass(activity, DialogLifeCycleActivity.class);
activity.startActivityForResult(intent, 142);
ShadowActivity.IntentForResult intentForResult = shadowActivity.peekNextStartedActivityForResult();
assertThat(intentForResult).isNotNull();
assertThat(shadowActivity.peekNextStartedActivityForResult()).isSameAs(intentForResult);
assertThat(intentForResult.intent).isNotNull();
assertThat(intentForResult.intent).isSameAs(intent);
assertThat(intentForResult.requestCode).isEqualTo(142);
}
代码示例来源:origin: facebook/facebook-android-sdk
@Test
public void testLogInWithReadAndAccessTokenCreatesReauthRequest() {
AccessToken accessToken = createAccessToken();
stub(method(AccessToken.class, "getCurrentAccessToken")).toReturn(accessToken);
LoginManager loginManager = new LoginManager();
loginManager.logInWithReadPermissions(mockActivity,
Arrays.asList("public_profile", "user_friends"));
int loginRequestCode = CallbackManagerImpl.RequestCodeOffset.Login.toRequestCode();
verify(mockActivity, times(1)).startActivityForResult(any(Intent.class),
eq(loginRequestCode));
}
代码示例来源:origin: facebook/facebook-android-sdk
@Test
public void testLogInWithPublishAndAccessTokenCreatesReauthRequest() {
AccessToken accessToken = createAccessToken();
stub(method(AccessToken.class, "getCurrentAccessToken")).toReturn(accessToken);
LoginManager loginManager = new LoginManager();
loginManager.logInWithPublishPermissions(mockActivity,
Arrays.asList("publish_actions", "publish_stream"));
int loginRequestCode = CallbackManagerImpl.RequestCodeOffset.Login.toRequestCode();
verify(mockActivity, times(1)).startActivityForResult(any(Intent.class),
eq(loginRequestCode));
}
代码示例来源:origin: crazycodeboy/TakePhoto
/**
* @param contextWrap
* @param intentWap
*/
public static void startActivityForResult(TContextWrap contextWrap, TIntentWap intentWap) {
if (contextWrap.getFragment() != null) {
contextWrap.getFragment().startActivityForResult(intentWap.getIntent(), intentWap.getRequestCode());
} else {
contextWrap.getActivity().startActivityForResult(intentWap.getIntent(), intentWap.getRequestCode());
}
}
代码示例来源:origin: facebook/facebook-android-sdk
@Test
public void testLogInThrowsIfCannotStartFacebookActivity() {
doThrow(new ActivityNotFoundException()).when(mockActivity)
.startActivityForResult(any(Intent.class), anyInt());
LoginManager loginManager = new LoginManager();
try {
loginManager.logInWithReadPermissions(mockActivity,
Arrays.asList("public_profile", "user_friends"));
fail();
} catch(FacebookException exception) {
}
}
内容来源于网络,如有侵权,请联系作者删除!