本文整理了Java中android.content.Intent.hasExtra()
方法的一些代码示例,展示了Intent.hasExtra()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Intent.hasExtra()
方法的具体详情如下:
包路径:android.content.Intent
类名称:Intent
方法名:hasExtra
暂无
代码示例来源:origin: stackoverflow.com
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK && requestCode == REQUEST_CODE) {
if (data.hasExtra("myData1")) {
Toast.makeText(this, data.getExtras().getString("myData1"),
Toast.LENGTH_SHORT).show();
}
}
}
代码示例来源:origin: googlesamples/android-testing
@Override
public IBinder onBind(Intent intent) {
// If the Intent comes with a seed for the number generator, apply it.
if (intent.hasExtra(SEED_KEY)) {
mSeed = intent.getLongExtra(SEED_KEY, 0);
mGenerator.setSeed(mSeed);
}
return mBinder;
}
代码示例来源:origin: android-hacker/VirtualXposed
@Override
public Object afterCall(Object who, Method method, Object[] args, Object result) throws Throwable {
Intent intent = (Intent) super.afterCall(who, method, args, result);
if (intent != null && intent.hasExtra("_VA_|_intent_")) {
return intent.getParcelableExtra("_VA_|_intent_");
}
return intent;
}
}
代码示例来源:origin: facebook/facebook-android-sdk
public static boolean isErrorResult(Intent resultIntent) {
Bundle bridgeArgs = getBridgeArgumentsFromIntent(resultIntent);
if (bridgeArgs != null) {
return bridgeArgs.containsKey(BRIDGE_ARG_ERROR_BUNDLE);
} else {
return resultIntent.hasExtra(STATUS_ERROR_TYPE);
}
}
代码示例来源:origin: nickbutcher/plaid
/**
* Create a {@link FabTransform} from the supplied {@code activity} extras and set as its
* shared element enter/return transition.
*/
public static boolean setup(@NonNull Activity activity, @Nullable View target) {
final Intent intent = activity.getIntent();
if (!intent.hasExtra(EXTRA_FAB_COLOR) || !intent.hasExtra(EXTRA_FAB_ICON_RES_ID)) {
return false;
}
final int color = intent.getIntExtra(EXTRA_FAB_COLOR, Color.TRANSPARENT);
final int icon = intent.getIntExtra(EXTRA_FAB_ICON_RES_ID, -1);
final FabTransform sharedEnter = new FabTransform(color, icon);
if (target != null) {
sharedEnter.addTarget(target);
}
activity.getWindow().setSharedElementEnterTransition(sharedEnter);
return true;
}
代码示例来源:origin: TommyLemon/Android-ZBLibrary
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null && intent.hasExtra(STATE)){
Log.i(TAG, "demoBroadcastReceiver.onReceive intent.getIntExtra(STATE, 0) = "
+ intent.getIntExtra(STATE, 0));
showShortToast("demoBroadcastReceiver\n" + (intent.getIntExtra(STATE, 0) == 1
? "已插入耳机" : "请插入耳机"));
}
}
}
代码示例来源:origin: TommyLemon/Android-ZBLibrary
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null && intent.hasExtra(STATE)){
Log.i(TAG, "baseBroadcastReceiver.onReceive intent.getIntExtra(STATE, 0) = "
+ intent.getIntExtra(STATE, 0));
showShortToast("baseBroadcastReceiver\n" + (intent.getIntExtra(STATE, 0) == 1
? "已插入耳机" : "请插入耳机"));
}
}
}.register();
代码示例来源:origin: TeamNewPipe/NewPipe
@Override
public void handleIntent(final Intent intent) {
if (intent == null) return;
if (intent.hasExtra(PLAYBACK_QUALITY)) {
setPlaybackQuality(intent.getStringExtra(PLAYBACK_QUALITY));
}
super.handleIntent(intent);
}
代码示例来源:origin: evernote/android-job
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null && intent.hasExtra(EXTRA_JOB_ID) && intent.hasExtra(EXTRA_JOB_EXACT)) {
int jobId = intent.getIntExtra(EXTRA_JOB_ID, -1);
Bundle transientExtras = intent.getBundleExtra(EXTRA_TRANSIENT_EXTRAS);
if (intent.getBooleanExtra(EXTRA_JOB_EXACT, false)) {
Intent serviceIntent = PlatformAlarmServiceExact.createIntent(context, jobId, transientExtras);
JobProxy.Common.startWakefulService(context, serviceIntent);
} else {
PlatformAlarmService.start(context, jobId, transientExtras);
}
}
}
}
代码示例来源:origin: ACRA/acra
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent.hasExtra(EXTRA_ACRA_CONFIG)) {
final boolean onlySendSilentReports = intent.getBooleanExtra(EXTRA_ONLY_SEND_SILENT_REPORTS, false);
final CoreConfiguration config = (CoreConfiguration) intent.getSerializableExtra(EXTRA_ACRA_CONFIG);
new SendingConductor(this, config).sendReports(onlySendSilentReports);
} else {
if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "SenderService was started but no valid intent was delivered, will now quit");
}
return START_REDELIVER_INTENT;
}
代码示例来源:origin: square/leakcanary
@Override protected final void onHandleIntentInForeground(@Nullable Intent intent) {
if (intent == null) {
CanaryLog.d("AbstractAnalysisResultService received a null intent, ignoring.");
return;
}
if (!intent.hasExtra(ANALYZED_HEAP_PATH_EXTRA)) {
onAnalysisResultFailure(getString(R.string.leak_canary_result_failure_no_disk_space));
return;
}
File analyzedHeapFile = new File(intent.getStringExtra(ANALYZED_HEAP_PATH_EXTRA));
AnalyzedHeap analyzedHeap = AnalyzedHeap.load(analyzedHeapFile);
if (analyzedHeap == null) {
onAnalysisResultFailure(getString(R.string.leak_canary_result_failure_no_file));
return;
}
try {
onHeapAnalyzed(analyzedHeap);
} finally {
//noinspection ResultOfMethodCallIgnored
analyzedHeap.heapDump.heapDumpFile.delete();
//noinspection ResultOfMethodCallIgnored
analyzedHeap.selfFile.delete();
}
}
代码示例来源:origin: square/leakcanary
@SuppressWarnings("unchecked")
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
visibleLeakRefKey = savedInstanceState.getString("visibleLeakRefKey");
} else {
Intent intent = getIntent();
if (intent.hasExtra(SHOW_LEAK_EXTRA)) {
visibleLeakRefKey = intent.getStringExtra(SHOW_LEAK_EXTRA);
}
}
leaks = (List<AnalyzedHeap>) getLastNonConfigurationInstance();
setContentView(R.layout.leak_canary_display_leak);
listView = findViewById(R.id.leak_canary_display_leak_list);
failureView = findViewById(R.id.leak_canary_display_leak_failure);
actionButton = findViewById(R.id.leak_canary_action);
updateUi();
}
代码示例来源:origin: facebook/facebook-android-sdk
@Override
public boolean onActivityResult(int resultCode, Intent data) {
if (data.hasExtra("error")) {
FacebookRequestError error = data.getParcelableExtra("error");
callback.onError(error.getException());
return true;
}
callback.onSuccess(new Result());
return true;
}
});
代码示例来源:origin: android-hacker/VirtualXposed
public void performReceive(Intent intent, int resultCode, String data, Bundle extras, boolean ordered,
boolean sticky, int sendingUser) throws RemoteException {
if (!accept(intent)) {
return;
}
if (intent.hasExtra("_VA_|_intent_")) {
intent = intent.getParcelableExtra("_VA_|_intent_");
}
SpecialComponentList.unprotectIntent(intent);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
IIntentReceiverJB.performReceive.call(mOld, intent, resultCode, data, extras, ordered, sticky, sendingUser);
} else {
mirror.android.content.IIntentReceiver.performReceive.call(mOld, intent, resultCode, data, extras, ordered, sticky);
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testHasExtra() throws Exception {
Intent intent = new Intent();
assertSame(intent, intent.putExtra("foo", ""));
assertTrue(intent.hasExtra("foo"));
assertFalse(intent.hasExtra("bar"));
}
代码示例来源:origin: MatthiasRobbers/shortbread
@Test
public void intentDoesNotHaveExtra_doesNotCallMethodShortcut() {
when(intent.hasExtra("shortbread_method")).thenReturn(false);
ShortbreadGenerated.activityThatWasPassedToCallMethodShortcut = null;
Shortbread.create(activity);
assertNull(ShortbreadGenerated.activityThatWasPassedToCallMethodShortcut);
}
代码示例来源:origin: TeamNewPipe/NewPipe
private void initFragments() {
if (DEBUG) Log.d(TAG, "initFragments() called");
StateSaver.clearStateFiles();
if (getIntent() != null && getIntent().hasExtra(Constants.KEY_LINK_TYPE)) {
handleIntent(getIntent());
} else NavigationHelper.gotoMainFragment(getSupportFragmentManager());
}
代码示例来源:origin: robolectric/robolectric
@Test
public void send_shouldNotFillIn_whenPendingIntentIsImmutable() throws Exception {
Intent intent = new Intent();
Context context = Robolectric.setupActivity(Activity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, FLAG_IMMUTABLE);
Activity otherContext = Robolectric.setupActivity(Activity.class);
Intent fillIntent = new Intent().putExtra("TEST", 23);
pendingIntent.send(otherContext, 0, fillIntent);
Intent i = shadowOf(otherContext).getNextStartedActivity();
assertThat(i).isNotNull();
assertThat(i).isSameAs(intent);
assertThat(i.hasExtra("TEST")).isFalse();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void send_shouldNotReusePreviouslyFilledInIntentData() throws Exception {
Intent intent = new Intent("action");
Context context = Robolectric.setupActivity(Activity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 99, intent, 100);
Activity otherContext = Robolectric.setupActivity(Activity.class);
Intent firstFillIntent = new Intent().putExtra("KEY1", 23).putExtra("KEY2", 24);
pendingIntent.send(otherContext, 0, firstFillIntent);
ShadowActivity shadowActivity = shadowOf(otherContext);
shadowActivity.clearNextStartedActivities();
Intent secondFillIntent = new Intent().putExtra("KEY1", 50);
pendingIntent.send(otherContext, 0, secondFillIntent);
Intent i = shadowActivity.getNextStartedActivity();
assertThat(i).isNotNull();
assertThat(i.filterEquals(intent)).isTrue(); // Ignore extras.
assertThat(i.getIntExtra("KEY1", -1)).isEqualTo(50);
assertThat(i.hasExtra("KEY2")).isFalse();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void send_shouldFillInLastIntentData() throws Exception {
Intent[] intents = {new Intent("first"), new Intent("second")};
Context context = Robolectric.setupActivity(Activity.class);
PendingIntent pendingIntent = PendingIntent.getActivities(context, 99, intents, 100);
Activity otherContext = Robolectric.setupActivity(Activity.class);
Intent fillIntent = new Intent();
fillIntent.putExtra("TEST", 23);
pendingIntent.send(otherContext, 0, fillIntent);
ShadowActivity shadowActivity = shadowOf(otherContext);
Intent second = shadowActivity.getNextStartedActivity();
assertThat(second).isNotNull();
assertThat(second.filterEquals(intents[1])).isTrue(); // Ignore extras.
assertThat(second.getIntExtra("TEST", -1)).isEqualTo(23);
Intent first = shadowActivity.getNextStartedActivity();
assertThat(first).isNotNull();
assertThat(first).isSameAs(intents[0]);
assertThat(first.hasExtra("TEST")).isFalse();
}
内容来源于网络,如有侵权,请联系作者删除!