Tweet in android app instead authenticating the user - android

I'm developing an android application and I want to can share in a tweet a picture. I search for tutorials and all of them have to authentificate the user before can post a tweet. Is there any way to use the account that's stored on your phone instead of authenticating the user again?
I don't want to have a share button, I want that like in iPhone can post a tweet.
If anyone know of other toturial that works and it's better please tell me, I don't want a share button, only I want to tweet.
Thanks

Use shareIntent, as described here:
public void shareTwitter() {
String message = "Your message to post";
try {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setClassName("com.twitter.android","com.twitter.android.PostActivity");
sharingIntent.putExtra(Intent.EXTRA_TEXT, message);
startActivity(sharingIntent);
} catch (Exception e) {
Log.e("In Exception", "Comes here");
Intent i = new Intent();
i.putExtra(Intent.EXTRA_TEXT, theObject.getName());
i.setAction(Intent.ACTION_VIEW);
i.setData(Uri.parse("https://mobile.twitter.com/"));
startActivity(i);
}
}

Related

How to send app invite using android studio

I need to send app invitation message from my app to friends via whatsapp,facebook,hike,... with the message and playstore link.I have seen this kind of invitations in other apps like hike,whatscall,... like the
attached image
I want to send exactly the same kind of message with the playstore link and app logo for my app also and it should be shared using all the available sharing option in users mobile.In my application i have included a inform friends menu and on clicking on that this function should work.I have seen firebase app invite examples but it needs google-services.json and i think it will only send text message from users email,I am not sure about that.
Sending text msg or image or both via app can be done using Action_send intent. The following code should work for your requirement.
void shareImageWithText(){
Uri contentUri = Uri.parse("android.resource://" + getPackageName() + "/drawable/" + "ic_launcher");
StringBuilder msg = new StringBuilder();
msg.append("Hey, Download this awesome app!");
msg.append("\n");
msg.append("https://play.google.com/store/apps/details?id=Your_Package_Name"); //example :com.package.name
if (contentUri != null) {
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // temp permission for receiving app to read this file
shareIntent.setType("*/*");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, msg.toString());
shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
try {
startActivity(Intent.createChooser(shareIntent, "Share via"));
} catch (ActivityNotFoundException e) {
Toast.makeText(getApplicationContext(), "No App Available", Toast.LENGTH_SHORT).show();
}
}
}

Send whatsApp message using background Service without opening whatsApp

I am trying to build a background service in which I can send message from my whatsapp to the other user's whatsapp.
I've tried this code
PackageManager packageManager = getApplicationContext().getPackageManager();
Intent i = new Intent(Intent.ACTION_VIEW);
try {
String url = "https://api.whatsapp.com/send?phone=" + "+91 7*********" + "&text=" + URLEncoder.encode("hhellow User", "UTF-8");
i.setPackage("com.whatsapp");
i.setData(Uri.parse(url));
if (i.resolveActivity(packageManager) != null) {
startActivity(i);
}
} catch (Exception e) {
e.printStackTrace();
}
But it is again redirecting me to whatsapp and ask me to send the message. I don't want to open my whatsapp screen, message should directly be send to the user (in background).
I know this question is already asked but I didn't get my answer all are redirecting me to whatsApp.
As per the WhatsApp FAQ there are only two ways to send text
Using Url
Using Intent
In both cases users have to click send button explicitly to send the message.
So as of now it is not possible to send message directly using any background service without clicking send button from WhatsApp itself.

Android Share intent - facebook

i want to share something with my friends. so i preferred android share intent.
i used,
Intent i=new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(android.content.Intent.EXTRA_TEXT, "my share text");
startActivity(Intent.createChooser(i, "share via"));
this showing a list of available apps like Facebook, Twitter, Gmail, Message, Skype.. e.t.c..
If i pressed a Twitter in the sense, the above text "my share text" showing in the tweet text box.
But if i select Facebook, the status message not showing.
i want to set the status message programatically.
how can i achieve this?
Facebook SDK has this bug, it's pretty annoying, I know. But if you set a link (and only a link) as "my share text", it will appear in the facebook share box.
I just built this code and it's working for me:
private void shareAppLinkViaFacebook() {
String urlToShare = "YOUR_URL";
try {
Intent intent1 = new Intent();
intent1.setClassName("com.facebook.katana", "com.facebook.katana.activity.composer.ImplicitShareIntentHandler");
intent1.setAction("android.intent.action.SEND");
intent1.setType("text/plain");
intent1.putExtra("android.intent.extra.TEXT", urlToShare);
startActivity(intent1);
} catch (Exception e) {
// If we failed (not native FB app installed), try share through SEND
Intent intent = new Intent(Intent.ACTION_SEND);
String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + urlToShare;
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
startActivity(intent);
}
}
Facebook does not allow the pre populating of text in the status box like as twitter. But we can pass the text with url to the Facebook. And it appears below the status box. check below code.
NOTE : Use Facebook SDK to share [ Recommended ].
Native share through intent
Intent shareIntent= new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "http://www.google.com");
shareIntent.setType("text/plain");
shareIntent.setPackage("com.facebook.katana");
startActivity(shareIntent);
Share through Facebook SDK
ShareDialog shareDialog;
// Sharing in Facebook using the SDK
FacebookSdk.sdkInitialize(this);
shareDialog = new ShareDialog(this);
String title = "Demo Title";
String URL = "http://www.google.com";
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle(title).setContentDescription(URL)
.setContentUrl(Uri.parse(URL)).build();
shareDialog.show(linkContent);
Check the link below for reference.
Link 1
Let me know for queries or clarification.

How to send a picture via email in Android, previewed but NOT attached..?

I want to send a picture preview in my mail Intent.
I dont want to attach it, i just want it to be shown.
This is my intent:
String textToSend = getString(R.string.mailHi)+"<br><br>"+getString(R.string.mailText)+getTextToSendViaMail();
Uri pngUri = null;
File currentShopImage = new File(Environment.getExternalStorageDirectory().toString()+"/OpenGuide/"+Integer.toString(keyId)+"_1_normal.pn_");
if(currentShopImage.exists()){
File pngFile = new File(currentShopImage.toString());
pngUri = Uri.fromFile(pngFile);
}
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
//i.putExtra(Intent.EXTRA_EMAIL, new String[] { emailCim });
i.putExtra(Intent.EXTRA_SUBJECT, "OpenGuide");
i.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(textToSend));
if(pngUri!= null)
i.putExtra(Intent.EXTRA_STREAM, pngUri);
try {
startActivity(Intent.createChooser(i, getString(R.string.SendMail)));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(ShopActivity.this, getString(R.string.MailClientNotFound), Toast.LENGTH_SHORT).show();
}
How can i achive such a thing ?
As far as I understood your problem, you want to place the image inside the mail with other text. In the words of Email protocol it's called an INLINE Attachment.
You would not be able to do this with intents as none of the email clients installed on the device supports creating html messages.
If it's really a core part of your app, you should consider a third party api to do this. One of the such library is JavaMail. You would be able to send html messages through this library but will take some time in setting up.
Here's a link that may give you some hint, how it's done.
Then you need to send a HTML generated email afaik.

Use ACTION_SEND to send email directly by Gmail, not choose from action-list

I read this question to know how to send email in Android using ACTION_SEND: Sending email from android app
But problem is: I want to send email directly using Gmail, i don't want to show the action-list and choose Gmail again.
Can I do it?
How to open Gmail Compose when a button is clicked in Android App? the second answer of beekeeper. Also duplicate of how to direct open Gmail mail composer in android? which has the same answer.
Try this:
final Intent intent = new Intent (android.content.Intent.ACTION_SEND);
intent.setType ("text/plain");
List<ResolveInfo> resInfo = getPackageManager ().queryIntentActivities (intent, 0);
if (!resInfo.isEmpty ()) {
for (ResolveInfo info : resInfo) {
if (info.activityInfo.packageName.toLowerCase ().contains ("android.gm") || info.activityInfo.name.toLowerCase ().contains ("android.gm")) {
intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{email});
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, TextKonnex);
intent.putExtra(android.content.Intent.EXTRA_TEXT, message);
intent.setPackage (info.activityInfo.packageName);
try {
startActivity (android.content.Intent.createChooser (intent,"Sending..."));
Toast.makeText(Main4Activity.this, "Sending an email to your friend! ", Toast.LENGTH_LONG).show();
} catch (ActivityNotFoundException e) {
Toast.makeText(Main4Activity.this, "Error! Try whith other email address! ", Toast.LENGTH_LONG).show();
}
}
}

Categories

Resources