This question already has answers here:
send data to email in background
(3 answers)
Closed 6 years ago.
i was creating Android Intent Mail. i am getting all the subject, to , mail body in email. is there is any possibility to send the mail without pressing send button .
My code is :
public void Sendmail(HashMap s) {
HashMap<String, String> sss = s;
String[] toppings = new String[sss.size()];
int size1 = 0;
for (String key : sss.keySet()) {
toppings[size1] = key + "\n" + sss.get(key) + "\n";
System.out.println("key: " + key + " value: " + sss.get(key));
size1++;
}
StringBuilder builder = new StringBuilder();
for (String s3 : toppings) {
builder.append(s3);
}
String mbody = builder.toString();
Intent i = new Intent(android.content.Intent.ACTION_SEND);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setType("plain/text");
i.putExtra(android.content.Intent.EXTRA_SUBJECT, "Task Activity");
i.putExtra(android.content.Intent.EXTRA_TEXT, mbody);
i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {"hari.andoidsaiss#gmail.com"});
try {
startActivity(i);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(Main2Activity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
}
You can't do it. A user should know what he is sending. Also a user should be aware about his actions.
You can do it using API and sending Email from server.
You can't do it with Share Intent of Android as it will populate installed app from your device which can process your data.
You can achieve this by following ways:
Implement mail client to send emails from your server side. ex: mailgun.
Integrate API's like Javamail or Gmail to your android app to get your work done.
Related
How can I send individual SMS to multiple recipients using an Intent only? (no SMSManager!) Is this even possible? I have tried the following solution but it creates a group message (MMS):
private void sendSMS(String[] phoneNumbers, String message){
StringBuilder sb = new StringBuilder();
for (String s :
phoneNumbers) {
sb.append(s);
sb.append(";");
}
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setData(Uri.parse("smsto:" + sb.toString())); // This ensures only SMS apps respond
intent.putExtra("sms_body", message);
if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivity(intent);
}
}
Again, the goal is to send a text to each recipient individually, not as a group message. I cannot use SMSManager because as of 2019 the Google Play Store prohibits sending SMS unless your app is the default messaging app (with some exceptions).
I am building an android application where user will login using linkedin.
When user click on the button the default linkedin login page appear after entering the Email ID and password when I click accepted I an disable to get user details.
Below is my login code -
public void onClick(View v) {
if (v.getId() == R.id.btnLinkedin) {
oAuthService = LinkedInOAuthServiceFactory.getInstance()
.createLinkedInOAuthService(Constants.CONSUMER_KEY,
Constants.CONSUMER_SECRET);
System.out.println("oAuthService : " + oAuthService);
factory = LinkedInApiClientFactory.newInstance(
Constants.CONSUMER_KEY, Constants.CONSUMER_SECRET);
liToken = oAuthService
.getOAuthRequestToken(Constants.OAUTH_CALLBACK_URL);
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(liToken
.getAuthorizationUrl()));
Toast.makeText(getApplicationContext(), "3", Toast.LENGTH_LONG).show();
startActivity(i);
}
}
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Toast.makeText(getApplicationContext(), "", Toast.LENGTH_LONG).show();
try {
linkedInImport(intent);
} catch (NullPointerException e) {
e.printStackTrace();
}
}
private void linkedInImport(Intent intent) {
String verifier = intent.getData().getQueryParameter("oauth_verifier");
System.out.println("liToken " + liToken);
System.out.println("verifier " + verifier);
LinkedInAccessToken accessToken = oAuthService.getOAuthAccessToken(
liToken, verifier);
client = factory.createLinkedInApiClient(accessToken);
// client.postNetworkUpdate("LinkedIn Android app test");
Person profile = client.getProfileForCurrentUser(EnumSet.of(
ProfileField.ID, ProfileField.FIRST_NAME,
ProfileField.LAST_NAME, ProfileField.HEADLINE));
System.out.println("First Name :: " + profile.getFirstName());
System.out.println("Last Name :: " + profile.getLastName());
System.out.println("Head Line :: " + profile.getHeadline());
}
LinkedIn now provides an Android development SDK to handle these situations for you more easily, that you might want to look into:
https://developer.linkedin.com/docs/android-sdk
I know this is an old thread, but just in case anyone came here looking for answers...
LinkedIn has deprecated and stopped supporting their old mobile SDKs as per this link, so I've created a lightweight "unofficial" SDK for Android, you can use it from this GitHub repo.
We also use it in our production apps, so it should be working fine. :)
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Facebook post on Friends wall in Android
I have made an app in which i am fetching list of my all FACEBOOK friends, now i want while i do click on any of the friend row then i will be able to post on his/her wall.
So what are the permissions i need to give and what type of code i need to write to do that,
Like: still i have given below permission and written below code onListItemClick
permissions :
mFacebook.authorize(main, new String[] { "publish_stream",
"friends_birthday", "friends_photos" }, new MyAuthorizeListener());
Code:
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
MyFriend friend = (MyFriend) this.getListAdapter().getItem(position);
}
I am fetching FbId, name, bday and picture
public class MyFriend {
private String fbID = " ";
private String name = " ";
private String bday = " ";
private String pic = " ";
}
Now on-wards you can not post to our friend's wall.
Because Facebook has removed the feature from its Graph Api, so that we cannot Post on Friend's Wall
thats why we can only post on our facebook wall only.
Feature of posting on friend's wall has been removed from the Facebook sdk.
Previously it could have been done by the following code as claimed by this post,
try{
Bundle parameters = new Bundle();
JSONObject attachment = new JSONObject();
try {
attachment.put("message", "Messages");
attachment.put("name", "Get utellit to send messages like this!");
attachment.put("href", link);
} catch (JSONException e) {
}
parameters.putString("attachment", attachment.toString());
parameters.putString("message", "Text is lame. Listen up:");
parameters.putString("target_id", "XXXXX"); // target Id in which you need to Post
parameters.putString("method", "stream.publish");
String response = authenticatedFacebook.request(parameters);
Log.v("response", response);
}
catch(Exception e){}
I have created my android code wherein I fetch all the data from facebook and then displays it in a textView and it works just fine on my account. But after I tried to connect with my dummy account, no details is fetched and I don't know the cause of this problem. Well here's my code to review:
private void getFbName() {
mProgress.setMessage("Finalizing ...");
mProgress.show();
new Thread() {
#Override
public void run() {
String name = "";
int what = 1;
try {
String me = mFacebook.request("me");
JSONObject jsonObj = (JSONObject) new JSONTokener(me).nextValue();
name = jsonObj.getString("first_name") + "|" + jsonObj.getString("last_name") + "|" + jsonObj.getString("email") + "|" + jsonObj.getString("id");
what = 0;
}
catch (Exception ex) {
ex.printStackTrace();
}
mFbHandler.sendMessage(mFbHandler.obtainMessage(what, name));
}
}.start();
}
private Handler mFbHandler = new Handler() {
#Override
public void handleMessage(Message msg) {
mProgress.dismiss();
if (msg.what == 0) {
String username = (String) msg.obj;
username = (username.equals("")) ? "No Name" : username;
//SPLITTER
String tokens[] = username.split("\\|");
TextView fname = (TextView) findViewById(R.id.textView1);
fname.setText(tokens[0]);
TextView lname = (TextView) findViewById(R.id.textView2);
lname.setText(tokens[1]);
TextView eadd = (TextView) findViewById(R.id.textView3);
eadd.setText(tokens[2]);
TextView fbid = (TextView) findViewById(R.id.textView4);
fbid.setText(tokens[3]);
SessionStore.saveName(username, Main.this);
//mFacebookBtn.setText(" Facebook (" + username + ")");
Toast.makeText(Main.this, "Connected to Facebook as " + username, Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(Main.this, "Connected to Facebook", Toast.LENGTH_SHORT).show();
}
}
};
Well I only followed this tutorial for my code with some modification in the design wherein I use 1 button for login and another for logout and then displays the result in 4 textViews.
Edit
Here's my logout code:
private void fbLogout() {
mProgress.setMessage("Disconnecting from Facebook");
mProgress.show();
new Thread() {
#Override public void run() {
SessionStore.clear(Main.this);
int what = 1;
try {
mFacebook.logout(Main.this);
what = 0;
}
catch (Exception ex) {
ex.printStackTrace();
}
mHandler.sendMessage(mHandler.obtainMessage(what));
}
}.start();
}
When using the facebook android SDK, you two have two types of authentication:
Using the SDK auth dialog which will ask the user for his email/password.
Using Single Sign-On (SSO) which will only work if the device has the facebook application (katana) installed. If that's the case, that app will be responsible for the authentication which creates a better user experience since the user is already signed in and does not need to reenter his credentials.
If you are following the tutorial then you are using SSO (if the app is installed of course), and because of that when ever you are using the facebook.authorize method you are asking the fb app to authorize your app for the current logged in user.
If you want another user to use your app you'll need the user to log out of the main facebook app.
You can use the sdk authentication and bypass the SSO as suggested here: How to disable Facebook single sign on for android - Facebook-android-sdk, but as I said before, I think it results in a bad user experience.
Another thing is that you keep implementing things using threads, but the facebook android SDK already gives you a helper class for that, it's the AsyncFacebookRunner which makes api requests asynchronously, read Async API Requests.
I am new to android programming.
I got my app with Gmail account sends emails.
What I need now is how to receive new emails from G mail?
Or at least how to get a notification that there is a new mail in my inbox?
I don't want to use Gmail app from market or embedded email android app or so...I'm making my own app that manages Gmail accounts (like some kind of widget in my own app).
In order to implement this functionality ,first you need to establish the connection with the gmail server,then you need to check the inbox folder for new messages. If find then send the notification to the user using NotificationManager. please follow this links http://www.jondev.net/articles/Sending_Emails_without_User_Intervention_%28no_Intents%29_in_Android and another link is
Sending Email in Android using JavaMail API without using the default/built-in app
Try this:
Properties props = new Properties();
//IMAPS protocol
props.setProperty(“mail.store.protocol”, “imaps”);
//Set host address
props.setProperty(“mail.imaps.host”, imaps.gmail.com);
//Set specified port
props.setProperty(“mail.imaps.port”, “993″);
//Using SSL
props.setProperty(“mail.imaps.socketFactory.class”, “javax.net.ssl.SSLSocketFactory”);
props.setProperty(“mail.imaps.socketFactory.fallback”, “false”);
//Setting IMAP session
Session imapSession = Session.getInstance(props);
Store store = imapSession.getStore(“imaps”);
//Connect to server by sending username and password.
//Example mailServer = imap.gmail.com, username = abc, password = abc
store.connect(mailServer, account.username, account.password);
//Get all mails in Inbox Forlder
inbox = store.getFolder(“Inbox”);
inbox.open(Folder.READ_ONLY);
//Return result to array of message
Message[] result = inbox.getMessages();
You need to first grant permission to "Notification accept " so your app can receive any notifications from device apps.
You need to follow the steps below to enable the "Notification accept" permission:
Setting => Apps => Special access => Notification accept
You need to give your application permission in AndroidManifest.xml:
<service android:name="com.secondclone.UINotificationService"
android:label="#string/app_name_notification"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService"
/>
</intent-filter>
</service>
Then, you write down the conditions to only receive notifications for new email notifications
/* This is the class that helps you receive notifications when there are new emails */
public class UINotificationService extends NotificationListenerService {
#Override
public void onCreate()
{
super.onCreate();
}
#Override
public void onNotificationPosted(StatusBarNotification sbn)
{
// Get notification of new messages of the Gmail app com.google.android.gm
if (sbn.getPackageName().equals("com.google.android.gm"))
{
/* What you need to handle when a new email is here */
Bundle extras = sbn.getNotification().extras;
if (!contentGmail.equals(extras.getCharSequence("android.bigText").toString()))
{
contentGmail = Objects.requireNonNull(extras.getCharSequence("android.bigText")).toString();
// This is the recipient's Gmail name information.
String mreceiver = extras.getString("android.subText");
// This is the sender's name.
String mSender = extras.getString("android.title");
// This is the Email subject.
String mSubject = Objects.requireNonNull(extras.getCharSequence("android.text")).toString();
// This is the text of this new mail.
String mContent = Objects.requireNonNull(extras.getCharSequence("android.bigText")).toString();
//Notification.EXTRA_TEXT
time = sbn.getPostTime() / 1000;
Log.i("tsMail", "Sender = " + mSender + " Receiver= " + receiver + " Content Gmail= " + mContent );
}
}
}
}
#Override
public void onNotificationRemoved(StatusBarNotification sbn) {
Log.i("Msg","Notification Removed");
}
}