Retrieve android.intent.extra.EMAIL value from bundle - android

I created one app like email clients app such as Gmail.
When user click on email address in another apps and choose my app from email sending apps in list appear on .
The email content like email address , email subject and .... come to my app by intent .
But the problem is intent.getData(); is null value all of the time and i try to get email data from intent .
I tested bundle in intent and i saw its not null and when i write this code :
bundle = intent.getExtras();
Log.e("Email",bundle.toString());
the bundle.toString() return Bundle[{android.intent.extra.EMAIL=[Ljava.lang.String;#11cda76c}] .
I dont know what is this [Ljava.lang.String;#11cda76c}] and how i can get the email address from here ! ?

Found answer here Passing values through bundle and get its value on another activity
bundle = this.getIntent().getExtras();
String email= bundle.getString("EMAIL");
Edit:
bundle = this.getIntent().getExtras();
String [] emails=bundle.getStringArray(Intent.EXTRA_EMAIL );

Related

get information from 2 table in sqlite from 2 different fragment

I have 2 tables : book and user ,now I need to make another table but it should get some fields from book and some from user ,separately I can ,but when I go to another fragment to get other fields from book table the username ,which I save it to a string, returns null
08-04 10:47:27.319 4004-4004/com.example.pars.amanatdari I/bookName: args : Bundle[{status=null, userName=jack, bookName=null}]
08-04 10:47:30.139 4004-4004/com.example.pars.amanatdari I/bookName: args : Bundle[{status=available, userName=null, bookName=نون والقلم}]
what should I do exactly?I dont know even what to search
send data from fragment :
Bundle args = getArguments();
String username = args.getString("userName");
and get data :
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
String bookName = bundle.getString("bookName");
String bookStatus = bundle.getString("status");
String bookUser = bundle.getString("userName");
borrowFragment borrowFragment = new borrowFragment();
Bundle args2 = new Bundle();
args2.putString("bookName", bookName);
args2.putString("status", bookStatus);
args2.putString("userName", bookUser);
Log.i("bookName", "args : " + args2);
borrowFragment.setArguments(args2);
getSupportFragmentManager().beginTransaction().add(R.id.frg_container, borrowFragment, "tag").commit();
That is bound to happen , since the bundle gets null or overwritten after your visit to the book fragment .So what can be done is you can get the values from user fragment and pass the value to book fragment and then take both the values and go to the next fragment . You have to carry the data with you all the while

how to send a string to listView in another activity ? in android

Good evening guys,
I'm making an app and I want to know how to send a string to "List-View" in another activity ?
You can send data using the following code -
Intent intent = new Intent(this,newActivity);
intent.putExtra(name, value)
name = The name of the extra data
value = The String data value.
startActivity(intent);
In the new activity, you receive string via following (in onCreate)
Intent intent = getIntent();
String str = intent.getString(name)
name = The name of the extra data
Now search the web on how to add a string to list view. You will find it easily

Android Populating a Email Address Using a String

Moving on from my original question below:
Android Sending an email using a list of email addresses
I have tried to populate the email address line by using a string. When writing the email the message section is populated with the answer given by clicking on a spinner, the code for this is shown as "%1$s". So if I have a spinner that has 4 different countries in the string for the main email I put:
Country: %1$s
And it will show in the final email to be sent as:
Country: UK
For example.
When I put this string into the email Address instead of it originally looking like:
home%1$s#gmail.com
And coming out in the final email as:
homeUK#gmail.com
It stays as home%1$s#gmail.com!
Is there a reason for this? Is it something that cannot be added to the address line?
I have attached my code below and would very much appreciate someones help. I have been pulling my hair out with this one. The rest of the app is complete!
Main Activity
public void sendFeedbackMessage(String subject, String message) {
Intent messageIntent = new Intent(android.content.Intent.ACTION_SEND);
String aEmailList[] = { getResources().getString(R.string.emailaddress_format) };
String bEmailList[] = { ("country#gmail.com") };
messageIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
messageIntent.putExtra(Intent.EXTRA_CC, bEmailList);
//email.putExtra(Intent.EXTRA_BCC, new String[]{to});
messageIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
messageIntent.setType("plain/text");
messageIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
startActivity(messageIntent);
}
}
And the relevant String
<string
name="emailaddress_format">country%1$s#gmail.com</string>
If any more code is needed to see what I am trying to do then please let me know and I will add it. I didnt want to overload everyone with the whole code and then try and explain where I am struggling.
Hopefully someone can help me and i'm making sense.
Many Thanks
Not sure on the exact answer to the particular problem you're having, but an easier way to accomplish what it seems like you're trying to accomplish would be:
Spinner yourSpinner = (Spinner)findViewById(R.id.yourSpinner);
String country = yourSpinner.getSelectedItem().toString();
String aEmailList[] = { "country" + country + "#gmail.com" };
This will get the country the person has selected from the spinner and convert it to a String, which you can then place in the EXTRA_EMAIL as you're doing already.

get the value from Intent of android

Thanks in advance.
When I print Log.d("me",getIntent().toString());
I am getting:
Intent { act=android.intent.action.CALL_PRIVILEGED dat=tel:888 flg=0x13800000 cmp=com.ninetology.freecall.two/.CallFinalActivity }
I am trying to fetch the value which is associated with "dat" but I am getting NullPointer exception.
//the code I am using is
getIntent().getStringExtra("dat"); // no use
//i tried
getIntent().getExtras("dat").toString(); // NullPointer exception
I tried with "tel" as key in above code still no use.
it seems you're doing this wrong.
The getExtras() function returns a bundle that you can extract data from and not a function that returns a specific String.
dat is NOT a String value as you can see from the data that was printed. it's a Uri,
try parsing it as you should and I'm sure you'll be able to get the data.
public void onCreate(Bundle b) { //mistyped
super.onCreate(b);
Uri data = getIntent().getData();
// OR USE THIS
String data = getIntent().getDataString();
// DO STUFF
}
try getIntent().getExtras().get("dat");
First of all, Its not necessary the string from Intent your are getting in log have a object with values..
So its better to just check its not a null, like,
Bundle bundle = getIntent().getExtras();
if(bundle ! = null)
{
// Now check you bundle object which has a values or not
}
else
{
// 1. get data in form of Uri
Uri data = getIntent().getData();
// 2. OR get string of Uri
String dataString = getIntent().getDataString();
// 3. Or split the data string
// The logic from this part may be different on your requirement.. I only suggests you to get data from string.. (Actual logic may different on your case)
String data = getIntent().toString();
data = data.subString(data.indexOf(":"), data.indexOf("flg")-1);
Log.e("tel:", data);
}
When you want to pass the data with the intent just add the below code before starting activity
intent.putExtra("dat", value); //value=the value you want to send
And when you want to fetch the same value in another activity just do:
Bundle bundle=getIntent().getExtras();
if(bundle!=null){
String string=bundle.getString("dat");
}
By doing this, you wont get the null pointer exception and will help you.

NullPointerException from getIntent().getExtras().getString("to")

InboxDetailActivity.java:
Intent i = new Intent(InboxDetailActivity.this,Compose.class);
Bundle b = new Bundle();
b.putString("To", ConstantData.inbox_from);
Log.d("From Value", ConstantData.inbox_from);
b.putString("Subject", "RE:" + ConstantData.inbox_subject);
Log.d("Subject Value", ConstantData.inbox_subject);
b.putString("FromId", ConstantData.inbox_fromid);
Log.d("From Id Value",ConstantData.inbox_fromid);
i.putExtras(b);
startActivity(i);
Compose.java:
Intent i = getIntent();
Bundle b = i.getExtras();
to = b.getString("To");
subject = b.getString("Subject");
toId = b.getString("FromId");
I am getting NullPointerException at to = b.getString("To");
Bundle b = i.getExtras();
getExtras() returns null.
Agree with John's answer adding possible solution.
What you are doing is create a bundle , insert values in this and then pass this bundle.
And than you just fetch all the values one by one using its keys.
I am working with bundles but I simply add desired values directly using putExtra method. And I haven't got any problem till date. I recommend you to use put extra and check whether it works or not.
I would like to know what makes you to apply this way for bundles? Have you just read it somewhere and started applying this method ? or you have got some options and after some consideration you found it better to apply this method OR your requirement states that. Because normally me and my peers doesn't use bundles and directly pass the extras. And that works for me every time.
using this instead of bundle
i.putString("To", ConstantData.inbox_from);
Log.d("From Value", ConstantData.inbox_from);
i.putString("Subject", "RE:" + ConstantData.inbox_subject);
Log.d("Subject Value", ConstantData.inbox_subject);
i.putString("FromId", ConstantData.inbox_fromid);
Log.d("From Id Value",ConstantData.inbox_fromid);
and in another class..
to = getIntent().getString("To");

Categories

Resources