android.content.Intent.getFlags()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(10.1k)|赞(0)|评价(0)|浏览(585)

本文整理了Java中android.content.Intent.getFlags()方法的一些代码示例,展示了Intent.getFlags()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Intent.getFlags()方法的具体详情如下:
包路径:android.content.Intent
类名称:Intent
方法名:getFlags

Intent.getFlags介绍

暂无

代码示例

代码示例来源:origin: android-hacker/VirtualXposed

private static boolean containFlags(Intent intent, int flags) {
  return (intent.getFlags() & flags) != 0;
}

代码示例来源:origin: stackoverflow.com

@Override
 protected void onResume() {
   super.onResume();
   //check if this intent should run your code
   //for example, check the Intent action
   boolean shouldThisIntentTriggerMyCode = [...];
   Intent intent = getIntent();
   boolean launchedFromHistory = intent != null ? (intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0 : false;
   if( !launchedFromHistory && shouldThisIntentTriggerMyCode && !consumedIntent ) {
     consumedIntent = true;
     //execute the code that should be executed if the activity was not launched from history
   }
 }

代码示例来源:origin: android-hacker/VirtualXposed

private static void removeFlags(Intent intent, int flags) {
  intent.setFlags(intent.getFlags() & ~flags);
}

代码示例来源:origin: stackoverflow.com

Intent i = new Intent(...); // Your list's Intent
i.setFlags(i.getFlags() | Intent.FLAG_ACTIVITY_NO_HISTORY); // Adds the FLAG_ACTIVITY_NO_HISTORY flag
startActivity(i);

代码示例来源:origin: oasisfeng/condom

@SuppressLint("WrongConstant") private int adjustIntentFlags(final OutboundType type, final Intent intent) {
  final int original_flags = intent.getFlags();
  if (mDryRun) return original_flags;
  if (mExcludeBackgroundReceivers && (type == OutboundType.BROADCAST || type == OutboundType.QUERY_RECEIVERS))
    intent.addFlags(SDK_INT >= N ? FLAG_RECEIVER_EXCLUDE_BACKGROUND : Intent.FLAG_RECEIVER_REGISTERED_ONLY);
  if (SDK_INT >= HONEYCOMB_MR1 && mExcludeStoppedPackages)
    intent.setFlags((intent.getFlags() & ~ Intent.FLAG_INCLUDE_STOPPED_PACKAGES) | Intent.FLAG_EXCLUDE_STOPPED_PACKAGES);
  return original_flags;
}

代码示例来源:origin: stackoverflow.com

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public final void onActivityResult(final int requestCode, final int resultCode, final Intent resultData) {
  if (requestCode == SettingsFragment.REQUEST_CODE_STORAGE_ACCESS) {
    Uri treeUri = null;
    if (resultCode == Activity.RESULT_OK) {
      // Get Uri from Storage Access Framework.
      treeUri = resultData.getData();

      // Persist URI in shared preference so that you can use it later.
      // Use your own framework here instead of PreferenceUtil.
      PreferenceUtil.setSharedPreferenceUri(R.string.key_internal_uri_extsdcard, treeUri);

      // Persist access permissions.
      final int takeFlags = resultData.getFlags()
        & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
      getActivity().getContentResolver().takePersistableUriPermission(treeUri, takeFlags);
    }
  }
}

代码示例来源:origin: android-hacker/VirtualXposed

private Intent makeMyIntent() {
  Intent intent = new Intent(getIntent());
  intent.setComponent(null);
  intent.setFlags(intent.getFlags() & ~Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
  return intent;
}

代码示例来源:origin: stackoverflow.com

} else if (requestCode == GALLERY_KITKAT_INTENT_CALLED) {
  originalUri = data.getData();
  final int takeFlags = data.getFlags()
      & (Intent.FLAG_GRANT_READ_URI_PERMISSION
      | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);

代码示例来源:origin: oasisfeng/condom

@Override public List<ResolveInfo> queryIntentServices(final Intent intent, final int flags) {
  final int original_intent_flags = intent.getFlags();
  return mCondom.proceedQuery(OutboundType.QUERY_SERVICES, intent, new CondomCore.WrappedValueProcedure<List<ResolveInfo>>() {
    @Override public List<ResolveInfo> proceed() {
      final List<ResolveInfo> result = CondomPackageManager.super.queryIntentServices(intent, flags);
      mCondom.filterCandidates(OutboundType.QUERY_SERVICES, intent.setFlags(original_intent_flags), result, TAG, true);
      return result;
    }
  }, CondomCore.SERVICE_PACKAGE_GETTER);
}

代码示例来源:origin: igreenwood/SimpleCropView

@SuppressWarnings("ResourceType") @TargetApi(Build.VERSION_CODES.KITKAT)
public static Uri ensureUriPermission(Context context, Intent intent) {
 Uri uri = intent.getData();
 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  final int takeFlags = intent.getFlags() & Intent.FLAG_GRANT_READ_URI_PERMISSION;
  context.getContentResolver().takePersistableUriPermission(uri, takeFlags);
 }
 return uri;
}

代码示例来源:origin: oasisfeng/condom

@Override public ResolveInfo resolveService(final Intent intent, final int flags) {
  final int original_intent_flags = intent.getFlags();
  // Intent flags could only filter background receivers, we have to deal with services by ourselves.
  return mCondom.proceed(OutboundType.QUERY_SERVICES, intent, null, new CondomCore.WrappedValueProcedure<ResolveInfo>() {
    @Override public ResolveInfo proceed() {
      if (! mCondom.mExcludeBackgroundServices && mCondom.mOutboundJudge == null)
        return CondomPackageManager.super.resolveService(intent, flags);    // Shortcut for pass-through
      final List<ResolveInfo> candidates = CondomPackageManager.super.queryIntentServices(intent, flags);
      final Intent original_intent = intent.setFlags(original_intent_flags);    // Restore the intent flags early before getFirstMatch().
      return mCondom.filterCandidates(OutboundType.QUERY_SERVICES, original_intent, candidates, TAG, false);
    }
  });
}

代码示例来源:origin: stackoverflow.com

public class OutgoingCallReceiverTest extends AndroidTestCase
{
  private OutgoingCallReceiver mReceiver;
  private TestContext mContext;

  @Override
  protected void setUp() throws Exception
  {
    super.setUp();

    mReceiver = new OutgoingCallReceiver();
    mContext = new TestContext();
  }

  public void testStartActivity()
  {
    Intent intent = new Intent(Intent.ACTION_NEW_OUTGOING_CALL);
    intent.putExtra(Intent.EXTRA_PHONE_NUMBER, "01234567890");

    mReceiver.onReceive(mContext, intent);        
    assertEquals(1, mContext.getReceivedIntents().size());
    assertNull(mReceiver.getResultData());

    Intent receivedIntent = mContext.getReceivedIntents().get(0);
    assertNull(receivedIntent.getAction());
    assertEquals("01234567890", receivedIntent.getStringExtra("phoneNum"));
    assertTrue((receivedIntent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) != 0);
  }
}

代码示例来源:origin: square/assertj-android

public IntentAssert hasFlags(@IntentFlags int flags) {
 isNotNull();
 int actualFlags = actual.getFlags();
 //noinspection ResourceType
 assertThat(actualFlags).overridingErrorMessage("Expected <%s> but was <%s>.",
   flagsToString(flags), flagsToString(actualFlags)).isEqualTo(flags);
 return this;
}

代码示例来源:origin: android-hacker/VirtualXposed

@Override
protected void onStop() {
  super.onStop();
  if (mRegistered) {
    mRegistered = false;
  }
  if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
    // This resolver is in the unusual situation where it has been
    // launched at the top of a new task.  We don't let it be added
    // to the recent tasks shown to the user, and we need to make sure
    // that each time we are launched we get the correct launching
    // uid (not re-using the same resolver from an old launching uid),
    // so we will now finish ourself since being no longer visible,
    // the user probably can't get back to us.
    if (!isChangingConfigurations()) {
      finish();
    }
  }
}

代码示例来源:origin: android-hacker/VirtualXposed

@Override
public void run(final AccountManagerFuture<Bundle> accountManagerFuture) {
  try {
    final Bundle accountManagerResult = accountManagerFuture.getResult();
    final Intent intent = accountManagerResult.getParcelable(
        AccountManager.KEY_INTENT);
    if (intent != null) {
      mPendingRequest = REQUEST_ADD_ACCOUNT;
      mExistingAccounts = VAccountManager.get().getAccounts(mCallingUserId, null);
      intent.setFlags(intent.getFlags() & ~Intent.FLAG_ACTIVITY_NEW_TASK);
      startActivityForResult(intent, REQUEST_ADD_ACCOUNT);
      return;
    }
  } catch (OperationCanceledException e) {
    setResult(Activity.RESULT_CANCELED);
    finish();
    return;
  } catch (IOException e) {
  } catch (AuthenticatorException e) {
  }
  Bundle bundle = new Bundle();
  bundle.putString(AccountManager.KEY_ERROR_MESSAGE, "error communicating with server");
  setResult(Activity.RESULT_OK, new Intent().putExtras(bundle));
  finish();
}

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldAddFlags() throws Exception {
 Intent intent = new Intent();
 Intent self = intent.addFlags(4);
 self.addFlags(8);
 assertEquals(12, intent.getFlags());
 assertSame(self, intent);
}

代码示例来源:origin: android-hacker/VirtualXposed

@Override
  public void onReceive(Context context, Intent intent) {
    if (mApp.isBooting()) {
      return;
    }
    if ((intent.getFlags() & FLAG_RECEIVER_REGISTERED_ONLY) != 0 || isInitialStickyBroadcast()) {
      return;
    }
    String privilegePkg = intent.getStringExtra("_VA_|_privilege_pkg_");
    if (privilegePkg != null && !info.packageName.equals(privilegePkg)) {
      return;
    }
    PendingResult result = goAsync();
    if (!mAMS.handleStaticBroadcast(appId, info, intent, new PendingResultData(result))) {
      result.finish();
    }
  }
}

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldSetFlags() throws Exception {
 Intent intent = new Intent();
 Intent self = intent.setFlags(1234);
 assertEquals(1234, intent.getFlags());
 assertSame(self, intent);
}

代码示例来源:origin: oasisfeng/condom

@CallSuper void check(final Intent intent) {
  assertBaseNotCalled();
  mBaseCalled = true;
  mIntentFlags = intent.getFlags();
}

代码示例来源:origin: facebook/facebook-android-sdk

@Test
public void testShareToMessengerWith20150314Protocol() throws Exception {
 setupPackageManagerForMessenger(true);
 setupContentResolverForProtocolVersions(20150314);
 Uri uri = Uri.parse("file:///foo.jpeg");
 Uri externalUri = Uri.parse("http://example.com/foo.jpeg");
 ShareToMessengerParams params = ShareToMessengerParams
   .newBuilder(uri, "image/jpeg")
   .setMetaData("{}")
   .setExternalUri(externalUri)
   .build();
 MessengerUtils.shareToMessenger(mMockActivity, 1, params);
 // Expect it to have launched messenger with the right intent.
 ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class);
 verify(mMockActivity).startActivityForResult(
   intentArgumentCaptor.capture(),
   eq(1));
 Intent intent = intentArgumentCaptor.getValue();
 assertEquals(Intent.ACTION_SEND, intent.getAction());
 assertEquals(Intent.FLAG_GRANT_READ_URI_PERMISSION, intent.getFlags());
 assertEquals("com.facebook.orca", intent.getPackage());
 assertEquals(uri, intent.getParcelableExtra(Intent.EXTRA_STREAM));
 assertEquals("image/jpeg", intent.getType());
 assertEquals("200", intent.getStringExtra("com.facebook.orca.extra.APPLICATION_ID"));
 assertEquals(20150314, intent.getIntExtra("com.facebook.orca.extra.PROTOCOL_VERSION", -1));
 assertEquals("{}", intent.getStringExtra("com.facebook.orca.extra.METADATA"));
 assertEquals(externalUri, intent.getParcelableExtra("com.facebook.orca.extra.EXTERNAL_URI"));
}

相关文章

Intent类方法