How do I mail TextView data on button click in Android app? - java

First of all, I am pretty new to Android and NFC both, although I am quiet accustomed with Java. I am making an NFC android application as my Major Project in which I would like to mail a certain list(displaying the results) on the click of a button.
Can someone help me with the code or direct me to some step-by-step tutorials for this...
Thanks in anticipation..!!!

Use an Intent to launch an application capable of sending mail and pass your data with it:
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto","abc#gmail.com", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "EXTRA_SUBJECT");
startActivity(Intent.createChooser(emailIntent, "Send email..."));

In above code just add this line:
emailIntent.putExtra(Intent.EXTRA_TEXT, "Content of the email");

if you want to get body of email from another activity then pass edittext text in intent from activity where your edittext is and receive it to another activity where your intent is
for example
Activity A
EditText bodyText=(EditText)findViewById(R.id.body_text);
EditText subjectText=(EditText)findViewById(R.id.subject_text);
String emailBody=bodyText.getText().toString().trim();
String emailSubject=subjectText.getText().toString().trim();
Intent inte=new Intent(A.this,B.class);
inte.putExtra("body",bodyText);
inte.purExtra("subject",emailSubject);
startActivity(inte);
and in Activity B receive the intent like this,
Intent intent=getIntent();
String bodyText=intent.getExtras().getString("body");
String subjectText=intent.getExtras().getString("subject");
Intent emailInte=new Intent(Intent.ACTION_SENDTO,Uri.fromParts("mailto","xyz#gmail.com",null));
emailInte.putExtra(Intent.EXTRA_SUBJECT,subjectText);
emailInte.putExtra(Intent.EXTRA_TEXT, bodyText);
startActivity(Intent.createChooser(emailInte,"Send email using"));

Related

Android Studio java incorrect display TextView

I understand that my question is probably not difficult, but I could not find an answer to it. In a nutshell: I transfer text between activities through an intent. In the second activity, instead of text, I get the following. I have used intent more than once to transfer data between activities and there have never been such problems.enter image description here
from sender activity
String textToSend = someTextView.getText().toString();
Intent intent = Intent(this, ReceiverActivity.java);
intent.putExtra("text", textToSend);
startActivity(intent);
you're currently sending textview as string instead of text from the textview
Make sure you are passing data as string and also when you retrieve in second activity, use "getStringExtra()" method and define a string variable and use
val stringdata = intent.getStringExtra("your_intent_name")

Send string by an intent to any other apps

I'm trying to send and intent which contains a String. I want to share this intent implicitly, so I don't want to specify the app who will receive this Intent.
Let me explain, the string I want to send will be send thank's to the Intent, and in the same app put in the clipboard, and then I paste the clipboard thank's to AccessibilityService in another app.
The intent will serve to be catches first by the clipboard, and then by another app (with a script code to this intent, because the app is too already created but can't be edited.
So I started to do this :
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
intent.setType("text/plain");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
from the developer.android site, but it open a menu in which I must chose an app to share the intent, that's what I won't.
Could you help be?
NOTE: I'm French, sorry for my poor English

Sending parameter in Firebase dynamic link

when creating a firebase dynamic link manually i want the link to contain a variable as a parameter to deal with it when the link is clicked, i tried to do this:
StringBuilder link= new StringBuilder("https://qn937.app.goo.gl/?link=https://www.teblya.com/&apn=com.example.abdo.foodproject");
link.append("/?token="+itemٍ.getId()+"/");
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, link.toString());
shareIntent.setType("text/plain");
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.app_name)));
but the problem is that it opens the deep link in the browser instead of my app.
does anyone know any approach i can sent this item.getId() parameter with the link? thanks in advance.

Android: How can I take a screenshot of the current activity and share it?

I should be able to press a button that takes a screenshot of the current activity (without showing the Toast message on the display) and then opens the dialog to share it on social networks or various apps. I hope you got what I need to do and you can help me.
How to take a screenshot programatically
After that, you can send a share intent with the screen shot image uri attached.
Like so:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
shareIntent.setType("image/jpeg");
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));

Debugging Intents

I asked a question previously about what shows up in the IntentChooser when I send an Intent with ACTION_SEND and MIME type "image/png". The problem is that some phones come with a default messaging app that is not showing up in the list, mine included (myTouch 4G) as well as a user that I speak with over email (using an HTC EVO). If I choose a Send or Share option from the built in gallery app or another application on the same image I'm saving and attempting to send directly from my app, Messages shows up in the list. From my app it does not. Other phones don't have this problem, so it's clearly a platform specific thing. But that doesn't mean I should just ignore the problem.
So, I go to troubleshooting the issue. I register one of the activities in my app to receive the the same type of intent, and then hit a breakpoint to analyze the Intent object being sent from the two different ways of sending it.
The problem is, the intent I'm sending and the intent being sent from Gallery or AndroZip (where Messages does show up in the chooser) seem to be the same. They both have the same action, same categories, same flags, same mime type. What else can I inspect on the Intent from Gallery or AndroZip to tell if there's some more information I can add to my Intent to get the default messaging app to show up in the chooser in cases where it is not?
The problem is specific to HTC Sense phones, and it arises because their Gallery and Messaging apps are different to the stock ones.
Specifically the Intent sent from Gallery to Messaging has the action android.intent.action.SEND_MSG which is different to android.intent.action.SEND. The Sense messaging app doesn't handle SEND, unlike the stock messaging app.
So the question becomes, how is the Sense Gallery app creating an activity chooser dialog which combines both SEND and SEND_MSG ?
I've done some research and got mostway there... the code below works, but the "Messages" entry in the dialog appears at the top rather than in alphabetical order as per Gallery. Doubtless some more research into intents would correct that, but at least this works:
// Create a chooser for things that can ACTION_SEND images
Intent intent = new Intent(Intent.ACTION_SEND);
Uri data = Uri.parse("content://media/external/images/media/98");
intent.putExtra(Intent.EXTRA_STREAM, data);
intent.setType("image/jpeg");
Intent chooser = Intent.createChooser(intent, "Blah");
// Add the stupid HTC-Sense-specific secondary intent
Intent htcIntent = new Intent("android.intent.action.SEND_MSG");
htcIntent.putExtra(Intent.EXTRA_STREAM, data);
htcIntent.setType("image/jpeg");
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { htcIntent });
// Show the chooser
startActivity(chooser);
First of all, +1 to Reuben, he is the genius, not me. But I had to modify his code a bit to get it to work. Basically I had to putExtra() on the htcIntent or the image never got stuck to the Intent.
Tested and validated on a Droid X and HTC Incredible (which had the same problem until now thanks to Reuben).
Uri uri = Uri.fromFile(new File(mFile));
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType("image/png");
Intent htcIntent = new Intent("android.intent.action.SEND_MSG");
htcIntent.setType("image/png");
htcIntent.putExtra(Intent.EXTRA_STREAM, uri);
Intent chooser = Intent.createChooser(intent, "Send Method");
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { htcIntent });
startActivity(chooser);
Edit: I realize I'm putting the image on two Intents now, but I couldn't get it to work any other way.
Instead of debugging the intents, why not try to compare how your starting the chooser with how the gallery is doing it. It is open source after all, so instead of trying to guess at the issue with the result, you can debug from the cause.
https://android.googlesource.com/platform/packages/apps/Gallery3D

Categories

Resources