Getting Empty SMS body - java

Hi trying to send SMS with android using below code.
public static void sendsmsstd(String number, String message, Context context) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setType("vnd.android-dir/mms-sms");
intent.putExtra("address", number);
intent.putExtra("sms-body", message);
context.startActivity(intent);
}
Many sites have suggested it , but when code runs and SMS app opens, it choose right contact to send message but message body is always empty.
What else can be done to fix it. I m missing some code.

You're using sms-body. Change that to sms_body and that should fix it.

Related

Android - Java - Intent to send facebook chat message (facebook disabled xmpp)

***Facebook deprecated xmpp api.
Is there a way to open an intent (or pass data to fb) to send chat message on android device?
Facebook & Messenger apps installed on the device.
Thanks :-)
You need to pass uri to the intent
Here 100005727832736 is the user id of the person who you want to
message to
Uri uri = Uri.parse("fb-messenger://user/100005727832736");
Here is my sample code
Uri uri = Uri.parse("fb-messenger://user/100005727832736");
Intent toMessenger= new Intent(Intent.ACTION_VIEW, uri);
try {
startActivity(toMessenger);
}
catch (android.content.ActivityNotFoundException ex)
{
Toast.makeText(context, "Please Install Facebook Messenger", Toast.LENGTH_LONG).show();
}
}
This is what worked for me and i haven not tested this for some time now.
To launch facebook app let urlString = "fb://page/your_fb_page_id"
To launch facebook messenger let urlString = "fb-messenger://user/your_fb_page_id"
FB page id is usually numeric. To get it, goto Find My FB ID input your profile url, something like www.facebook.com/edgedevstudio then click "Find Numberic ID".
Voila, you now have your fb numeric id. replace "your_fb_page_id" with the generated Numeric ID
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(urlString))
if (intent.resolveActivity(packageManager) != null) //check if app is available to handle the implicit intent
startActivity(intent)

How to send app invites from my application (via whatsapp,hike,message)

I am new for Android. I created a simple food app. I want to send invitation to my friends from my app via Whatsapp, message etc. while clicking the invite button. I don't have any idea about that. Can you anyone guide me (Show some examples means more helpful to me).
Thanks in advance!
Refer this link
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);
private void onShareClicked() {
String link = "https://play.google.com/store/apps/details?id=com.recharge2mePlay.recharge2me";
Uri uri = Uri.parse(link);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, link.toString());
intent.putExtra(Intent.EXTRA_TITLE, "Recharge2me");
startActivity(Intent.createChooser(intent, "Share Link"));
}
And simply call this function in onClickListner.
btn_tellAFreind.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
onShareClicked();
}
});
try this tutorial from google using Firebase, maybe this can help you:
https://codelabs.developers.google.com/codelabs/firebase-android/#10
You can generate short link by using the following codes:
DynamicLink dynamicLink = FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse("https://play.google.com/store/apps/details?id=com.example"))
.setDynamicLinkDomain("abc.app.goo.gl")
.setAndroidParameters(new DynamicLink.AndroidParameters.Builder().build())
.buildDynamicLink();
Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLongLink(dynamicLink.getUri())
.buildShortDynamicLink()
.addOnCompleteListener(ReferrerActivity.this, new OnCompleteListener<ShortDynamicLink>() {
#Override
public void onComplete(#NonNull Task<ShortDynamicLink> task) {
if (task.isSuccessful()) {
Uri shortLink = task.getResult().getShortLink();
Uri flowchartLink = task.getResult().getPreviewLink();
Log.i(TAG, "onComplete: SHORTLINK " + shortLink.toString());
Log.i(TAG, "onComplete: FLOW LINK " + flowchartLink.toString());
} else {
Log.i(TAG, "onComplete: ERROR " + task.isSuccessful() + " " + task.isComplete());
}
}
});
Once you received the short link in onComplete method, share it using intent.
Firebase Invites are an out-of-the-box solution for app referrals and sharing via email or SMS.
Connect your app to your Firebase project from Firebase console
Enabled Firebase Dynamic Links from the Firebase console by opening the Dynamic Links section and accepting the terms of service if prompted.
Add Firebase to your Android project
Add the dependency for Firebase Invites to your app-level build.gradle file:
compile 'com.google.firebase:firebase-invites:10.0.1'
Send invitations:
Start by building an Intent using the AppInviteInvitation.IntentBuilder class:
Intent intent = new AppInviteInvitation.IntentBuilder(getString(R.string.invitation_title))
.setMessage(getString(R.string.invitation_message))
.setDeepLink(Uri.parse(getString(R.string.invitation_deep_link)))
.setCustomImage(Uri.parse(getString(R.string.invitation_custom_image)))
.setCallToActionText(getString(R.string.invitation_cta))
.build();
startActivityForResult(intent, REQUEST_INVITE);
Launching the AppInviteInvitation intent opens the contact chooser where the user selects the contacts to invite. Invites are sent via email or SMS. After the user chooses contacts and sends the invite, your app receives a callback to onActivityResult:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "onActivityResult: requestCode=" + requestCode + ", resultCode=" + resultCode);
if (requestCode == REQUEST_INVITE) {
if (resultCode == RESULT_OK) {
// Get the invitation IDs of all sent messages
String[] ids = AppInviteInvitation.getInvitationIds(resultCode, data);
for (String id : ids) {
Log.d(TAG, "onActivityResult: sent invitation " + id);
}
} else {
// Sending failed or it was canceled, show failure message to the user
// ...
}
}
}
Check out here for more details about Send and Receive Firebase Invites from Your Android App
Update:
Use Branch sdk to support invite feature on another platform like WhatsApp, Facebook and other social media apps.
Check out here to know How branch link works?
Checkout here for Install guide & code example
If I understand the question correctly, you want to make the share differentiate when the user clicks share and if he selects to invite via WhatsApp, for example, it will show only Whatsapp as a medium option to share the invite through.
If that is what you want, you should to set the package in the intent you will use for sharing, so if we add to #Vishal answer above
sendIntent.setPackage("com.whatsapp");
You should do the same for any needed social media
You need to add Firebase Dynamic link. Earlier it was Firebase Invites but it is depreciated now. Firebase Dymanic Link is build over Firebase Invites So you can see the invites dependency on gradle file.
You can follow this tutorial for complete example about "How to Create Refer a friend Link"
There is Two ways to create "Refer a Friend Link"
Using Firebase base Dynamic Object
Manually Create Refer a Link
1) Option :-
DynamicLink dynamicLink = FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse("https://www.example.com/"))
//.setDomainUriPrefix("https://example.page.link") // no longer in user please
.setDynamicLinkDomain("example.page.link") // use this code and don't use https:// here
// Open links with this app on Android
.setAndroidParameters(new DynamicLink.AndroidParameters.Builder().build())
// Open links with com.example.ios on iOS
.setIosParameters(new DynamicLink.IosParameters.Builder("com.example.ios").build())
.buildDynamicLink();
Uri dynamicLinkUri = dynamicLink.getUri();
2) Option:-
String sharelinktext = "https://referearnpro.page.link/?"+
"link=https://www.blueappsoftware.com/"+
"&apn="+ getPackageName()+
"&st="+"My Refer Link"+
"&sd="+"Reward Coins 20"+
"&si="+"https://www.blueappsoftware.com/logo-1.png";
Then Call ShortDynamicLink Object
Refer Link will be look like this :
https://referearnpro.page.link?apn=blueappsoftware.referearnpro&link=https%3A%2F%2Fwww.blueappsoftware.com%2F
You can check complete example here
a custom method to send invites, also according to the best practice in Android Developers
fun inviteToDownloadApp(context: Context) {
val intent = Intent(Intent.ACTION_SEND)
intent.type = "text/plain"
intent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.app_name))
intent.putExtra(Intent.EXTRA_TEXT, context.getString(R.string.invite_to_download_app))
context.startActivity(Intent.createChooser(intent, context.getString(R.string.invite_to_download_app)))
}

Android - Send Telegram message to a specific number

I'm trying to send a Telegram message to a specific number from within my Android app. Right now my code launches Telegram app, and then the user has to select the destinatary. What I want to do is to send the message to the specified number, without having the user select the contact. My code is as follows:
/**
* Intent to send a telegram message
* #param msg
*/
void intentMessageTelegram(String msg)
{
final String appName = "org.telegram.messenger";
final boolean isAppInstalled = isAppAvailable(mUIActivity.getApplicationContext(), appName);
if (isAppInstalled)
{
Intent myIntent = new Intent(Intent.ACTION_SEND);
myIntent.setType("text/plain");
myIntent.setPackage(appName);
myIntent.putExtra(Intent.EXTRA_TEXT, msg);//
mUIActivity.startActivity(Intent.createChooser(myIntent, "Share with"));
}
else
{
Toast.makeText(mUIActivity, "Telegram not Installed", Toast.LENGTH_SHORT).show();
}
}
You can't send to special number, But You can do this by USERID
try {
Intent telegramIntent = new Intent(Intent.ACTION_VIEW);
telegramIntent.setData(Uri.parse("http://telegram.me/USERID"));
startActivity(telegramIntent);
} catch (Exception e) {
// show error message
}
This code will show user an alert for choosing applications that support telegram uri's like Telegram itself and Mobogram!
Tip: don't set package name. some people install telegram alternatives like mobogram.
The Telegram Android App does not have a way to send messages directly to telegram users, so if you use the share intent, you'll get what telegram / any other app wants to do with the message shared. In this case, open the contact list to send this message to him.
If you want to send messages directly to Telegram users you should use the Telegram API
https://core.telegram.org/api#getting-started
once you have configured your API key in your app, you could send messages, read them or even get the telegram contacts with these methods
https://core.telegram.org/methods
This one worked for me:
try {
Intent telegram = new Intent(Intent.ACTION_VIEW, Uri.parse("https://t.me/USER_NAME"));
telegram.setPackage("org.telegram.messenger");
startActivity(telegram);
}catch (Exception e)
{
Toast.makeText(getContext(), "Telegram app is not installed", Toast.LENGTH_LONG).show();
}
Tip: You can get USER_NAME by click on you telegram profile option you will get option of username in Account session --> if username is none create unique username and put here its work for me.
This one worked for me:
//check if application is installed first before running this code.
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("http://telegram.me/+UT_USER_ID_HERE"));
final String appName = "org.telegram.messenger";
i.setPackage(appName);
this.startActivity(i);
try the intent like this
tg://resolve?domain=YOUR_USER_ID
it's more direct then https://t.me
I'm using this for send message on background :
this cod is api telegram for use send message by url token bot
1 - use WebView on xml like this :
<WebView
android:id="#+id/webView_sendToTelegram"
android:layout_width="0dp"
android:layout_height="0dp"/>
2 - on java use this cod:
public static void SendMessageToBotTelegram(String chatID, String text, String botToken,WebView webView) {
webView.loadUrl(MessageFormat.format("https://api.telegram.org/bot{0}/sendMessage?chat_id={1}&text={2}", botToken, chatID, text));
}
chatID : your telegram id #RawDataBot for get id
text : text your message
botToken : your bot for get message if you don't have bot using #BotFather for crate bot
webView : your id WebView on xml

Android: can you use an AlertDialog to clear data so it isn't corrupted after starting an email activity?

I have an Android app that emails some data. I also have button that fires an AlertDialog confirmation box that clears the same data.
The normal flow of the app is: fill data into pdf file->send email with pdf attachment->clear data on button press and repeat.
My question is this: is it humanly possible for a user to clear their data before the email is sent (so the data would all be blank)? I don't want my users sending blank emails because of a bug. The reason I'm asking this question is because I first had the data being cleared after the email activity was fired (this is a no-no) and was sending blank data. I've tried looking for a way to use StartActivityForResult() on the email activity so I can just destroy the data when the activity finished, but it doesn't look like this is possible. I think doing it with a confirm box is safe because the email activity should be finished, but I just want to be absolutely sure this is safe.
Android devices can behave very different, one from another. You could have slowness in your mail activity, or you could have your device to suddenly decide to clean up memory and make every thing slow slow slow for a moment. If you are relying on timing in hoping that some other process or thread is completed before you delete something, you are playing with fire.
I think a better approach would be to start your e-mail activity for result, like CapDroid did in this answer:
Send Mail:
int EMAIL = 101;
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{});
emailIntent.putExtra(android.content.Intent.EXTRA_BCC,new String[]{});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_STREAM, pngUri);
startActivityForResult(emailIntent,EMAIL);
Sending Result:
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
// TODO Auto-generated method stub
if(requestCode==EMAIL)
{
if(requestCode==EMAIL && resultCode==Activity.RESULT_OK)
{
if(myFile.exists())
myFile.delete();
Toast.makeText(mActivity, "Mail sent.", Toast.LENGTH_SHORT).show();
}
else if (requestCode==EMAIL && resultCode==Activity.RESULT_CANCELED)
{
Toast.makeText(mActivity, "Mail canceled.", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(mActivity, "Please try again.", Toast.LENGTH_SHORT).show();
}
}
}

How to start a Skype call from an Android app?

I'm trying to start a Skype intent from my Android App, passing a phone number. So far, thanks to other people who ad similiar needs here on stackoverflow, I've managed to start skype, but still I can't pass the phone number. This is the code I'm using:
Intent sky = new Intent("android.intent.action.CALL_PRIVILEGED");
sky.setClassName("com.skype.raider",
"com.skype.raider.Main");
sky.setData(Uri.parse("tel:" + number));
Log.d("UTILS", "tel:" + number);
ctx.startActivity(sky);
What's happening is that skype starts, but gives me a toast saying that the number is not valid, and suggests me to add the international prefix.
The Log.d gives me tel:+39........ (the number works, I'm using it also for
public static void call(String number, Context ctx) {
try {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + number));
ctx.startActivity(callIntent);
} catch (ActivityNotFoundException e) {
Log.e("helloandroid dialing example", "Call failed", e);
}
}
In fact, when I go to the Skype's view for calling, I see it's been composed +0
So what it seems to me is that I'm passing the phone number in the wrong way, or to the wrong Activity....any help would be very appreciated!
In the meantime, I just want to say that StackOverflow simply rocks.
See this answer: https://stackoverflow.com/a/8844526/819355
Jeff suggests using a skype:<user name> instead of tel:<phone number>
After some studing of the skype apk with apktool, as suggested in that answer, I came up with this code, for me it's working:
public static void skype(String number, Context ctx) {
try {
//Intent sky = new Intent("android.intent.action.CALL_PRIVILEGED");
//the above line tries to create an intent for which the skype app doesn't supply public api
Intent sky = new Intent("android.intent.action.VIEW");
sky.setData(Uri.parse("skype:" + number));
Log.d("UTILS", "tel:" + number);
ctx.startActivity(sky);
} catch (ActivityNotFoundException e) {
Log.e("SKYPE CALL", "Skype failed", e);
}
}
Refer to Skype developer: Skype URI tutorial: Android apps
Also remember to add "?call" in your url. E.g
intent.setData(Uri.parse("skype:" + phoneNumber + "?call"));
Without it, Skype may not dial the number.
You should not include a specific class when calling an external app. Let the user decide of the application he/she wants to use. That's the way android has been designed and it's a better solution than obliging people to use a soft (moreover quite a slow, closed and inconvenient app to my mind).
In other words, just use the Uri, that's the job of skype of declaring its ability to capture such intents.
Refer this skype doc link Skype URI tutorial: Android apps
First need to check skype is installed or not using
/**
* Determine whether the Skype for Android client is installed on this device.
*/
public boolean isSkypeClientInstalled(Context myContext) {
PackageManager myPackageMgr = myContext.getPackageManager();
try {
myPackageMgr.getPackageInfo("com.skype.raider", PackageManager.GET_ACTIVITIES);
}
catch (PackageManager.NameNotFoundException e) {
return (false);
}
return (true);
}
initiate skype uri using
/**
* Initiate the actions encoded in the specified URI.
*/
public void initiateSkypeUri(Context myContext, String mySkypeUri) {
// Make sure the Skype for Android client is installed.
if (!isSkypeClientInstalled(myContext)) {
goToMarket(myContext);
return;
}
// Create the Intent from our Skype URI.
Uri skypeUri = Uri.parse(mySkypeUri);
Intent myIntent = new Intent(Intent.ACTION_VIEW, skypeUri);
// Restrict the Intent to being handled by the Skype for Android client only.
myIntent.setComponent(new ComponentName("com.skype.raider", "com.skype.raider.Main"));
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Initiate the Intent. It should never fail because you've already established the
// presence of its handler (although there is an extremely minute window where that
// handler can go away).
myContext.startActivity(myIntent);
return;
}
if Skype is not installed then redirect to market place using
/**
* Install the Skype client through the market: URI scheme.
*/
public void goToMarket(Context myContext) {
Uri marketUri = Uri.parse("market://details?id=com.skype.raider");
Intent myIntent = new Intent(Intent.ACTION_VIEW, marketUri);
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
myContext.startActivity(myIntent);
return;
}

Categories