How to get all extra values from intent
Calling intent place do it like this
Bundle bundle = new Bundle();
bundle.putString("RetailerName", keyword);
bundle.putString("positon", aString);
intent.putExtras(bundle);
receive intent place get the data like this
Bundle bundle = this.getIntent().getExtras();
String RetailerName = bundle.getString("retailerName");
Extract the list of all extras from an Intent in Xamarin.Android and save it in a dictionary
Here what I found after a while and I'm going to share it so that someone else can save time.
//Didactic version
Bundle b = myIntent.Extras; //Where myIntent is of course an Intent
ICollection<string> c = b.KeySet(); //This is the collection of extras
Dictionary<string, string> d = new Dictionary<string, string>();
foreach (var key in c)
{
Object value = b.Get(key);
d.Add(key, value.ToString());
}
//Short version
var b = myIntent.Extras;
var d = new Dictionary<string, string>();
foreach (var key in b.KeySet();)
{
d.Add(key, b.Get(key).ToString());
}
List of all extras applicable to an intent
Generally, the only way to know what extras are supported is to look at the documentation for the action. If the source code is available, that's the only other way to know.
In your particular example, unofficial documentation can be found here. The source code happens to be available here. Look in CropExtras.java for the available keys and dig through CropActivity.java for how they are used. However, note that using com.android.camera.action.CROP
is probably not a good idea, as explained in this blog post and in the answer in this thread.
How do I get extra data from intent on Android?
First, get the intent which has started your activity using the getIntent()
method:
Intent intent = getIntent();
If your extra data is represented as strings, then you can use intent.getStringExtra(String name)
method. In your case:
String id = intent.getStringExtra("id");
String name = intent.getStringExtra("name");
How do I print the contents of an Intent for logging purposes?
The Intent#toString()
method works pretty good, it will print most stuff but it doesn't print the extras unfortunately. The extras are in a Bundle
that can also be printed with Bundle#toString()
but if the Intent just arrived from another process then the contents of the extras Bundle
won't be printed until you trigger it to be unparcelled, also it doesn't properly print lists or arrays. This code below should help print out just about everything:
public static String intentToString(Intent intent) {
if (intent == null) {
return null;
}
return intent.toString() + " " + bundleToString(intent.getExtras());
}
public static String bundleToString(Bundle bundle) {
StringBuilder out = new StringBuilder("Bundle[");
if (bundle == null) {
out.append("null");
} else {
boolean first = true;
for (String key : bundle.keySet()) {
if (!first) {
out.append(", ");
}
out.append(key).append('=');
Object value = bundle.get(key);
if (value instanceof int[]) {
out.append(Arrays.toString((int[]) value));
} else if (value instanceof byte[]) {
out.append(Arrays.toString((byte[]) value));
} else if (value instanceof boolean[]) {
out.append(Arrays.toString((boolean[]) value));
} else if (value instanceof short[]) {
out.append(Arrays.toString((short[]) value));
} else if (value instanceof long[]) {
out.append(Arrays.toString((long[]) value));
} else if (value instanceof float[]) {
out.append(Arrays.toString((float[]) value));
} else if (value instanceof double[]) {
out.append(Arrays.toString((double[]) value));
} else if (value instanceof String[]) {
out.append(Arrays.toString((String[]) value));
} else if (value instanceof CharSequence[]) {
out.append(Arrays.toString((CharSequence[]) value));
} else if (value instanceof Parcelable[]) {
out.append(Arrays.toString((Parcelable[]) value));
} else if (value instanceof Bundle) {
out.append(bundleToString((Bundle) value));
} else {
out.append(value);
}
first = false;
}
}
out.append("]");
return out.toString();
}
Intent extras text
Have a look at this article which describes more details about using Intent
s to send email:
https://medium.com/@cketti/android-sending-email-using-intents-3da63662c58f
You probably want to use ACTION_SEND
instead of ACTION_SENDTO
or you'll need to add your message text and other data as query parameters to the URI instead of putting them in "extras".
How to get extras without a key?
if there is any way to obtain information without a key.
No, there is no way to send data without any key, You need to use some sort of key whether it's Intent.EXTRA
or your defined key
is there any way to check all the keys that have been set into the
bundle?
Yes, you can use getIntent().getExtras().keySet()
this will give you a Set
(of String) containing all keys.
Bundle bundle = getIntent().getExtras();
Set<String> bundleKeySet = bundle.keySet(); // string key set
for(String key : bundleKeySet){ // traverse and print pairs
Log.i(key," : " + bundle.get(key));
}
Retrieving intent extras from widget
I finally found a fix for this, I'm not sure how it really works but I changed:
PendingIntent.FLAG_IMMUTABLE
to
PendingIntent.FLAG_MUTABLE
in the PendingIntent
. Hopefully this helps someone else!
Related Topics
How to Install Android Sdk Build Tools on the Command Line
In Android App Toolbar.Settitle Method Has No Effect - Application Name Is Shown as Title
Mediacodec and Camera: Colorspaces Don't Match
Android ==> Memory Analysing ==> Eclipse Memory Analyzer
Get Path of Image from Action_Image_Capture Intent
Navigation Drawer (Google+ VS. Youtube)
Disable Activity Slide-In Animation When Launching New Activity
Question Mark () in Xml Attributes for Android
Backup and Restore SQLite Database to Sdcard
Method Not Found Using Digestutils in Android
Android Saving Created Bitmap to Directory on Sd Card
Trigger Mediascanner on Specific Path (Folder), How To
How to Rotate the Android Emulator Display