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

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

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

Intent.getStringExtra介绍

暂无

代码示例

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

@Override
public void onCreate(Bundle savedInstanceState) {

 ...

 // Register to receive messages.
 // We are registering an observer (mMessageReceiver) to receive Intents
 // with actions named "custom-event-name".
 LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
   new IntentFilter("custom-event-name"));
}

// Our handler for received Intents. This will be called whenever an Intent
// with an action named "custom-event-name" is broadcasted.
private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
 @Override
 public void onReceive(Context context, Intent intent) {
  // Get extra data included in the Intent
  String message = intent.getStringExtra("message");
  Log.d("receiver", "Got message: " + message);
 }
};

@Override
protected void onDestroy() {
 // Unregister since the activity is about to be closed.
 LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);
 super.onDestroy();
}

代码示例来源:origin: CarGuo/GSYVideoPlayer

@Override
public void onReceive(Context context, Intent intent) {
  String action = intent.getAction();
  if (action != null && action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {
    String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
    if (SYSTEM_DIALOG_REASON_HOME_KEY.equals(reason)) {
      //mLifecycleListener.onHide();
    }
  }
}

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

private static final int REQUEST_CODE_EMAIL = 1;
 private TextView email = (TextView) findViewById(R.id.email);
 // ...
 try {
   Intent intent = AccountPicker.newChooseAccountIntent(null, null,
       new String[] { GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE }, false, null, null, null, null);
   startActivityForResult(intent, REQUEST_CODE_EMAIL);
 } catch (ActivityNotFoundException e) {
   // TODO
 }
 // ...
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   if (requestCode == REQUEST_CODE_EMAIL && resultCode == RESULT_OK) {
     String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
     email.setText(accountName);
   }
 }

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

@Override
  public void onReceive(Context context, Intent intent) {
    // Remove the custom tab on top of this activity.
    Intent newIntent =
        new Intent(CustomTabMainActivity.this, CustomTabMainActivity.class);
    newIntent.setAction(REFRESH_ACTION);
    newIntent.putExtra(EXTRA_URL, intent.getStringExtra(EXTRA_URL));
    newIntent.addFlags(
        Intent.FLAG_ACTIVITY_CLEAR_TOP |
        Intent.FLAG_ACTIVITY_SINGLE_TOP);
    startActivity(newIntent);
  }
};

代码示例来源:origin: commonsguy/cw-omnibus

@Override
 public void onQuestion(Item question) {
  if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.M &&
   Intent.ACTION_PROCESS_TEXT.equals(getIntent().getAction()) &&
   getIntent().getStringExtra(Intent.EXTRA_PROCESS_TEXT)!=null) {
   setResult(Activity.RESULT_OK,
    new Intent().putExtra(Intent.EXTRA_PROCESS_TEXT, question.link));
   finish();
  }
  else {
   startActivity(new Intent(Intent.ACTION_VIEW,
    Uri.parse(question.link)));
  }
 }
}

代码示例来源:origin: novoda/android-demos

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
      case STEP1:
        this.step1result.setText(data.getStringExtra("STEP1RESULT"));
        startActivityForResult(new Intent(Wizard.INTENT_STEP2), STEP2);    
        break;
      case STEP2:
        this.step2result.setText(data.getStringExtra("STEP2RESULT"));
        startActivityForResult(new Intent(Wizard.INTENT_STEP3), STEP3);    
        break;
      case STEP3:
        this.step3result.setText(data.getStringExtra("STEP3RESULT"));
        break;
    }
  }
}

代码示例来源:origin: TeamNewPipe/NewPipe

String action = intent.getAction();
if (action != null) {
  if (action.equals(Intent.ACTION_RUN)) {
    String[] urls = intent.getStringArrayExtra(EXTRA_URLS);
    String name = intent.getStringExtra(EXTRA_NAME);
    String location = intent.getStringExtra(EXTRA_LOCATION);
    int threads = intent.getIntExtra(EXTRA_THREADS, 1);
    char kind = intent.getCharExtra(EXTRA_KIND, '?');
    String psName = intent.getStringExtra(EXTRA_POSTPROCESSING_NAME);
    String[] psArgs = intent.getStringArrayExtra(EXTRA_POSTPROCESSING_ARGS);
    String source = intent.getStringExtra(EXTRA_SOURCE);
    long nearLength = intent.getLongExtra(EXTRA_NEAR_LENGTH, 0);
      startActivity(new Intent(this, DownloadActivity.class)
          .setAction(Intent.ACTION_MAIN)
          .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

代码示例来源:origin: TommyLemon/APIJSON

sendBroadcast(new Intent(ACTION_EXIT_APP));
  break;
case REQUEST_TO_BOTTOM_MUNU:
case REQUEST_TO_REGISTER:
  if (data != null) {
    String phone = data.getStringExtra(PasswordActivity.RESULT_PHONE);
    String password = data.getStringExtra(requestCode == REQUEST_TO_VERIFY
        ? PasswordActivity.RESULT_VERIFY : PasswordActivity.RESULT_PASSWORD);
    if (StringUtil.isPhone(phone)) {

代码示例来源:origin: k9mail/k-9

@Override
  public void onReceive(Context context, final Intent intent) {
    String action = intent.getAction();
    if (DatabaseUpgradeService.ACTION_UPGRADE_PROGRESS.equals(action)) {
      /*
       * Information on the current upgrade progress
       */
      String accountUuid = intent.getStringExtra(
          DatabaseUpgradeService.EXTRA_ACCOUNT_UUID);
      Account account = mPreferences.getAccount(accountUuid);
      if (account != null) {
        String formatString = getString(R.string.upgrade_database_format);
        String upgradeStatus = String.format(formatString, account.getDescription());
        mUpgradeText.setText(upgradeStatus);
      }
    } else if (DatabaseUpgradeService.ACTION_UPGRADE_COMPLETE.equals(action)) {
      /*
       * Upgrade complete
       */
      launchOriginalActivity();
    }
  }
}

代码示例来源:origin: curtis2/SuperVideoPlayer

public void handleMessage(Message msg) {
  InitActivity ctx = (InitActivity) mContext.get();
  switch (msg.what) {
   case 0:
    ctx.mPD.dismiss();
    Intent src = ctx.getIntent();
    Intent i = new Intent();
    i.setClassName(src.getStringExtra("package"), src.getStringExtra("className"));
    i.setData(src.getData());
    i.putExtras(src);
    i.putExtra(FROM_ME, true);
    ctx.startActivity(i);
    ctx.finish();
    break;
  }
 }
}

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

String registrationId = intent.getStringExtra(EXTRA_REGISTRATION_ID);
String error = intent.getStringExtra(EXTRA_ERROR);
String unregistered = intent.getStringExtra(EXTRA_UNREGISTERED);
Log.d(TAG, "handleRegistration: registrationId = " + registrationId +
    ", error = " + error + ", unregistered = " + unregistered);
    Intent retryIntent =
        new Intent(INTENT_FROM_GCM_LIBRARY_RETRY);
    retryIntent.putExtra(EXTRA_TOKEN, TOKEN);
    PendingIntent retryPendingIntent = PendingIntent
        .getBroadcast(context, 0, retryIntent, 0);

代码示例来源: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: android-hacker/VirtualXposed

String splashUri = intent.getStringExtra("_VA_|_splash_");
String targetUri = intent.getStringExtra("_VA_|_uri_");
Intent splashIntent = null;
Intent targetIntent = null;
  splashIntent.putExtra(Constants.PASS_KEY_INTENT, targetIntent);
  splashIntent.putExtra(Constants.PASS_KEY_USER, userId);
  String pkg = targetIntent.getPackage();
  if (pkg == null) {
  splashIntent.putExtra(Constants.PASS_PKG_NAME_ARGUMENT, pkg);
  startActivity(splashIntent);

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

//Your activity will respond to this action String
public static final String RECEIVE_JSON = "com.your.package.RECEIVE_JSON";

private BroadcastReceiver bReceiver = new BroadcastReceiver() {
  @Override
  public void onReceive(Context context, Intent intent) {
    if(intent.getAction().equals(RECEIVE_JSON)) {
      String serviceJsonString = intent.getStringExtra("json");
      //Do something with the string
    }
  }
};
LocalBroadcastManager bManager;

代码示例来源:origin: ImmortalZ/TransitionHelper

@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == ForResultDetailActivity.REQUEST_CODE && resultCode == ForResultDetailActivity.RESULT_CODE) {
      String str = data.getStringExtra(ForResultDetailActivity.TRANSITION_DATA);
      tv.setText(str);
    }
  }
}

代码示例来源:origin: TommyLemon/APIJSON

@Override
protected void setResult() {
  intent = new Intent();
  intent.putExtra(RESULT_TYPE, getIntent().getIntExtra(INTENT_TYPE, -1));
  intent.putExtra(RESULT_KEY, getIntent().getStringExtra(INTENT_KEY));
  intent.putExtra(RESULT_VALUE, editedValue);
  setResult(RESULT_OK, intent);
}

代码示例来源:origin: termux/termux-app

final String contentTypeExtra = intent.getStringExtra("content-type");
final boolean useChooser = intent.getBooleanExtra("chooser", false);
final String intentAction = intent.getAction() == null ? Intent.ACTION_VIEW : intent.getAction();
switch (intentAction) {
  case Intent.ACTION_SEND:
  Intent urlIntent = new Intent(intentAction, data);
  if (intentAction.equals(Intent.ACTION_SEND)) {
    urlIntent.putExtra(Intent.EXTRA_TEXT, data.toString());
    urlIntent.setData(null);
  } else if (contentTypeExtra != null) {
Intent sendIntent = new Intent();
sendIntent.setAction(intentAction);
sendIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION);
  sendIntent.putExtra(Intent.EXTRA_STREAM, uriToShare);
  sendIntent.setType(contentTypeToUse);
} else {

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

case R.id.start_file_picker_button:
  Intent intent = new Intent(this, FilePickerActivity.class);
    if(data.hasExtra(FilePickerActivity.EXTRA_FILE_PATH)) {
      selectedFile = new File(data.getStringExtra(FilePickerActivity.EXTRA_FILE_PATH));
      mFilePathTextView.setText(selectedFile.getPath());

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

@Test
public void createChooser_shouldWrapIntent() throws Exception {
 Intent originalIntent = new Intent(Intent.ACTION_BATTERY_CHANGED, Uri.parse("foo://blah"));
 Intent chooserIntent = Intent.createChooser(originalIntent, "The title");
 assertThat(chooserIntent.getAction()).isEqualTo(Intent.ACTION_CHOOSER);
 assertThat(chooserIntent.getStringExtra(Intent.EXTRA_TITLE)).isEqualTo("The title");
 assertThat((Intent) chooserIntent.getParcelableExtra(Intent.EXTRA_INTENT))
   .isSameAs(originalIntent);
}

代码示例来源:origin: k9mail/k-9

boolean needsReschedule = false;
boolean needsPushRestart = false;
String uuid = intent.getStringExtra(K9_ACCOUNT_UUID);
boolean allAccounts = intent.getBooleanExtra(K9_ALL_ACCOUNTS, false);
        account.getDescription());
    String notificationEnabled = intent.getStringExtra(K9_NOTIFICATION_ENABLED);
    String ringEnabled = intent.getStringExtra(K9_RING_ENABLED);
    String vibrateEnabled = intent.getStringExtra(K9_VIBRATE_ENABLED);
    String pushClasses = intent.getStringExtra(K9_PUSH_CLASSES);
    String pollClasses = intent.getStringExtra(K9_POLL_CLASSES);
    String pollFrequency = intent.getStringExtra(K9_POLL_FREQUENCY);
String backgroundOps = intent.getStringExtra(K9_BACKGROUND_OPERATIONS);
if (K9RemoteControl.K9_BACKGROUND_OPERATIONS_ALWAYS.equals(backgroundOps)
    || K9RemoteControl.K9_BACKGROUND_OPERATIONS_NEVER.equals(backgroundOps)
String theme = intent.getStringExtra(K9_THEME);
if (theme != null) {
  K9.setK9Theme(K9RemoteControl.K9_THEME_DARK.equals(theme) ? K9.Theme.DARK : K9.Theme.LIGHT);
  Intent i = new Intent(RemoteControlService.this, RemoteControlService.class);
  i.setAction(RESCHEDULE_ACTION);
  long nextTime = System.currentTimeMillis() + 10000;

相关文章

Intent类方法