本文整理了Java中android.content.Intent.getExtras()
方法的一些代码示例,展示了Intent.getExtras()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Intent.getExtras()
方法的具体详情如下:
包路径:android.content.Intent
类名称:Intent
方法名:getExtras
暂无
代码示例来源:origin: stackoverflow.com
Intent mIntent = new Intent(this, Example.class);
Bundle extras = mIntent.getExtras();
extras.putString(key, value);
代码示例来源:origin: stackoverflow.com
public class MessageReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Bundle pudsBundle = intent.getExtras();
Object[] pdus = (Object[]) pudsBundle.get("pdus");
SmsMessage messages =SmsMessage.createFromPdu((byte[]) pdus[0]);
Log.i(TAG, messages.getMessageBody());
if(messages.getMessageBody().contains("Hi")) {
abortBroadcast();
}
}
代码示例来源:origin: stackoverflow.com
// intent come in in your onReceive method of your BroadcastReceiver:
public onReceive(Context context, Intent intent) {
// check to see if it is a message
if (intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE")) {
String id = intent.getExtras().getString("id");
String other_key = intent.getExtras().getString("other_key");
// if your key/value is a JSON string, just extract it and parse it using JSONObject
String json_info = intent.getExtras().getString("json_info");
JSONObject jsonObj = new JSONObject(json_info);
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testStringExtra() throws Exception {
Intent intent = new Intent();
assertSame(intent, intent.putExtra("foo", "bar"));
assertEquals("bar", intent.getExtras().get("foo"));
}
代码示例来源:origin: robolectric/robolectric
@Test
public void withIntent() {
final LoginFragment fragment = new LoginFragment();
Intent intent = new Intent("test_action");
intent.putExtra("test_key", "test_value");
SupportFragmentController<LoginFragment> controller =
SupportFragmentController.of(fragment, LoginActivity.class, intent).create();
Intent intentInFragment = controller.get().getActivity().getIntent();
assertThat(intentInFragment.getAction()).isEqualTo("test_action");
assertThat(intentInFragment.getExtras().getString("test_key")).isEqualTo("test_value");
}
代码示例来源:origin: robolectric/robolectric
@Test public void launchActivity_intentExtras() {
Intent intent = new Intent();
intent.putExtra("Key", "Value");
TranscriptActivity activity = rule.launchActivity(intent);
Intent activityIntent = activity.getIntent();
assertThat(activityIntent.getExtras()).isNotNull();
assertThat(activityIntent.getStringExtra("Key")).isEqualTo("Value");
}
代码示例来源:origin: stackoverflow.com
Bundle extras = data.getExtras();
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("aspectX", 2);
cropIntent.putExtra("aspectY", 1);
cropIntent.putExtra("outputX", 256);
代码示例来源:origin: airbnb/DeepLinkDispatch
if (sourceIntent.getExtras() != null) {
parameters = new Bundle(sourceIntent.getExtras());
} else {
parameters = new Bundle();
TaskStackBuilder taskStackBuilder = null;
if (entry.getType() == DeepLinkEntry.Type.CLASS) {
newIntent = new Intent(activity, c);
} else {
Method method;
if (newIntent.getAction() == null) {
newIntent.setAction(sourceIntent.getAction());
newIntent.putExtra(DeepLink.IS_DEEP_LINK, true);
newIntent.putExtra(DeepLink.REFERRER_URI, uri);
if (activity.getCallingActivity() != null) {
newIntent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
代码示例来源:origin: stackoverflow.com
/* Start Activity */
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.thinoo.ActivityTest", "com.thinoo.ActivityTest.NewActivity");
startActivityForResult(intent,90);
}
/* Called when the second activity's finished */
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch(requestCode) {
case 90:
if (resultCode == RESULT_OK) {
Bundle res = data.getExtras();
String result = res.getString("param_result");
Log.d("FIRST", "result:"+result);
}
break;
}
}
private void finishWithResult()
{
Bundle conData = new Bundle();
conData.putString("param_result", "Thanks Thanks");
Intent intent = new Intent();
intent.putExtras(conData);
setResult(RESULT_OK, intent);
finish();
}
代码示例来源:origin: cSploit/android
Bundle extras = getIntent().getExtras();
dir = Environment.getExternalStorageDirectory();
preferredStartDir = extras.getString(START_DIR);
showHidden = extras.getBoolean(SHOW_HIDDEN, false);
onlyDirs = extras.getBoolean(ONLY_DIRS, true);
mAffectedPref = extras.getString(AFFECTED_PREF);
return;
String path = files.get(position).getAbsolutePath();
Intent intent = new Intent(DirectoryPicker.this,
DirectoryPicker.class);
intent.putExtra(DirectoryPicker.START_DIR, path);
代码示例来源:origin: stackoverflow.com
Intent serviceIntent = new Intent(this,ListenLocationService.class);
serviceIntent.putExtra("From", "Main");
startService(serviceIntent);
//and get the parameter in onStart method of your service class
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
Bundle extras = intent.getExtras();
if(extras == null) {
Log.d("Service","null");
} else {
Log.d("Service","not null");
String from = (String) extras.get("From");
if(from.equalsIgnoreCase("Main"))
StartListenLocation();
}
}
代码示例来源:origin: wangdan/AisenWeiBo
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null && "org.aisen.weibo.sina.FAV_DESTORY".equalsIgnoreCase(intent.getAction())
&& intent.getExtras() != null) {
String statusId = intent.getExtras().getString("statusId");
destoryFav(statusId);
}
}
代码示例来源:origin: stackoverflow.com
final Bundle extras = data.getExtras();
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setClassName("com.android.camera", "com.android.camera.CropImage");
代码示例来源:origin: googlesamples/android-testing
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_PICK) {
if (resultCode == RESULT_OK) {
mCallerNumber.setText(data.getExtras()
.getString(ContactsActivity.KEY_PHONE_NUMBER));
}
}
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void putStringArrayListExtra_addsListToExtras() {
Intent intent = new Intent();
final ArrayList<String> strings = new ArrayList<>(Arrays.asList("hi", "there"));
intent.putStringArrayListExtra("KEY", strings);
assertThat(intent.getStringArrayListExtra("KEY")).isEqualTo(strings);
assertThat(intent.getExtras().getStringArrayList("KEY")).isEqualTo(strings);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void putIntegerArrayListExtra_addsListToExtras() {
Intent intent = new Intent();
final ArrayList<Integer> integers = new ArrayList<>(Arrays.asList(100, 200, 300));
intent.putIntegerArrayListExtra("KEY", integers);
assertThat(intent.getIntegerArrayListExtra("KEY")).isEqualTo(integers);
assertThat(intent.getExtras().getIntegerArrayList("KEY")).isEqualTo(integers);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testParcelableArrayListExtra() {
Intent intent = new Intent();
Parcelable parcel1 = new TestParcelable(22);
Parcelable parcel2 = new TestParcelable(23);
ArrayList<Parcelable> parcels = new ArrayList<>();
parcels.add(parcel1);
parcels.add(parcel2);
assertSame(intent, intent.putParcelableArrayListExtra("foo", parcels));
assertSame(parcels, intent.getParcelableArrayListExtra("foo"));
assertSame(parcel1, intent.getParcelableArrayListExtra("foo").get(0));
assertSame(parcel2, intent.getParcelableArrayListExtra("foo").get(1));
assertSame(parcels, intent.getExtras().getParcelableArrayList("foo"));
}
代码示例来源:origin: stackoverflow.com
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case DATEPICKER_FRAGMENT:
if (resultCode == Activity.RESULT_OK) {
Bundle bundle = data.getExtras();
String mMonth = bundle.getString("month", Month);
int mYear = bundle.getInt("year");
Log.i("PICKER", "Got year=" + year + " and month=" + month + ", yay!");
} else if (resultCode == Activity.RESULT_CANCELED) {
...
}
break;
}
}
代码示例来源:origin: stackoverflow.com
intent.putExtra("crop", "true");
intent.putExtra("aspectX", aspectX);
intent.putExtra("aspectY", aspectY);
intent.putExtra("outputX", outputX);
intent.putExtra("outputY", outputY);
final Bundle extras = data.getExtras();
if (extras != null) {
File tempFile = getTempFile();
if (data.getAction() != null) {
processPhotoUpdate(tempFile);
代码示例来源:origin: naman14/Timber
private void setAlbumart() {
playlistname.setText(getIntent().getExtras().getString(Constants.PLAYLIST_NAME));
foreground.setBackgroundColor(getIntent().getExtras().getInt(Constants.PLAYLIST_FOREGROUND_COLOR));
loadBitmap(TimberUtils.getAlbumArtUri(getIntent().getExtras().getLong(Constants.ALBUM_ID)).toString());
}
内容来源于网络,如有侵权,请联系作者删除!