Sending a Notification to Pebble - java

I'm trying to send a notification to my pebble watch. I'm using this code, which is basically the example from the website:
public void sendPebble(String title, String body) {
final Intent i = new Intent("com.getpebble.action.SEND_NOTIFICATION");
final Map<String, String> data = new HashMap<String, String>();
data.put("title", title);
data.put("body", body);
final JSONObject jsonData = new JSONObject(data);
final String notificationData = new JSONArray().put(jsonData).toString();
i.putExtra("messageType", "PEBBLE_ALERT");
i.putExtra("sender", "Test");
i.putExtra("notificationData", notificationData);
Log.d("Test", "Sending to Pebble: " + notificationData);
sendBroadcast(i);
}
I'm getting the message in LogCat, but no notification on the watch. The procedure seems simple enough, is there something too obvious I missed? Or is the documentation just incomplete?
Edit: The obvious questions:
Yes, the watch is connected
Yes, I have third party notifications enabled

Okay, this was my problem:
By default the Pebble app only sends notifications to the watch while the screen of the phone is off. For development I always have the screen active while the phone is connected via USB. So, the solution was: Enable the "Always send Notifications" option in the Pebble app.
Maybe this spares someone else a headache.

Related

Getting Empty SMS body

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.

Telegram API methods - 404 error | java

Created a bot and group. Added bot to the group(as admin) and starting trying posts. Through Url, it's smooth and successful. Started off exploring Telegram API(JAVA). Tests were on getUpdate and sendMessage methods.
I have generated TOKEN from telegram webapp(https://web.telegram.org).
Code snippet to getUpdates: yes, I have included bot ahead of the token.
TelegramBot bot = new TelegramBot("BOT_TOKEN");
GetUpdates getUpdates = new GetUpdates().limit(100).offset(0).timeout(0);
GetUpdatesResponse gur = bot.execute(getUpdates);
List<Update> list = gur.updates();
for(Update update : list) {
System.out.println(update.message());
}
Resonse is null.
code for sendMessage:
SendMessage request = new SendMessage(chatId, text)
.parseMode(ParseMode.HTML)
.disableWebPagePreview(true)
.disableNotification(true)
.replyToMessageId(1)
.replyMarkup(new ForceReply());
// sync
SendResponse sendResponse = bot.execute(request);
boolean ok = sendResponse.isOk();
Message message = sendResponse.message();
System.out.println(ok);
System.out.println(message);
Response is false and null.
I'm referring https://github.com/pengrad/java-telegram-bot-api#send-message
Help me understand the mistake. Thanks.
You need 109780439:AAJqs_w-4 format token, for instance:
TelegramBot bot = new TelegramBot("109780439:AAJqs_w-4");
This token can be obtained from #BotFather.

How to fill Sms data in notification

I'm trying twilio services and sending notification works fine but I can't set up the sms fallback properly as this is not really documented.
HashMap<String, Object> smsNumbers = new HashMap<>();
smsNumbers.put("?", "?");
LOGGER.debug("Adding SMS fallback to: {}", smsNumbers);
LOGGER.debug("Calling sendNotification to {}", identity);
Notification notification = Notification
.creator(twilioServiceSid)
.setBody(message)
.setData(data)
.setIdentity(identity)
.setSms(smsNumbers)
.create(restClient);
I'm getting the following error :
com.twilio.exception.ApiException: Parameter 'Sms' contains unrecognized property.
at com.twilio.rest.notify.v1.service.NotificationCreator.create(NotificationCreator.java:316) [twilio-7.15.1.jar:]
How to fill the HashMap ?
Twilio developer evangelist here.
When setting data that will be sent over SMS channels from a notification, you can set any of the following keys to override the general notification: body, media_urls, status_callback, and max_price.
So, if you wanted to send an alternative body over SMS, you would use the following code:
HashMap<String, Object> smsNumbers = new HashMap<>();
smsNumbers.put("body", "This is just for the SMS notifications");
LOGGER.debug("Adding SMS fallback to: {}", smsNumbers);
LOGGER.debug("Calling sendNotification to {}", identity);
Notification notification = Notification
.creator(twilioServiceSid)
.setBody(message)
.setData(data)
.setIdentity(identity)
.setSms(smsNumbers)
.create(restClient);
Let me know if that helps.

How to know if app/game was launched via notification on Android?

I'm making a game in Unity for Android. I have implemented a notification system. Notifications show and clicking on them opens the game. The thing I'm stuck on is how to know if the game/app is launched by tapping the notification?
Here is the java code for the notification plugin I'm using https://github.com/GoShikhar/unity-android-notifications/blob/master/PluginSrc/app/src/main/java/net/agasper/unitynotification/UnityNotificationManager.java
This is my manifest https://github.com/GoShikhar/unity-android-notifications/blob/master/UnityProject/Assets/Plugins/Android/AndroidManifest.xml
In my unity start scene I use this to check for intent messages.
void Start(){
AndroidJavaClass unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
var activityObject = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject intent = activityObject.Call<AndroidJavaObject>("getIntent");
int NotificationID = intent.Call<int>("getIntExtra", "id", -1);
print("NOTIFDICATION ID " + NotificationID);
bool hasExtra = intent.Call<bool>("hasExtra", "arguments");
string arguments = null;
if (hasExtra)
{
AndroidJavaObject extras = intent.Call<AndroidJavaObject>("getExtras");
arguments = extras.Call<string>("getString", "title");
print("title : " + arguments);
arguments = extras.Call<string>("getString", "message");
print("message: " + arguments);
}
if (arguments != null)
{
print("App opened via notification");
}
}
This not working. The default notification ID is being printed i.e. -1. Also title and message are null. Even though the notification has the title and message parameter.
I have seen lots of examples for Android Studio but not for Unity. So any help will be appreciated.
Thanks in advance.
Do you mean deep linking? Perhaps this Github project would be helpful: https://github.com/TROPHiT/UnityDeeplinks.

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

Categories