I'm not getting the FCM with buttons when app in background, I'm getting FCM in background but without buttons, in foreground it's working.
This is the code I use:
builder = new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.app_icon)
.setContentTitle(title)
// .setPriority(NotificationCompat.PRIORITY_MAX)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setContentText(body)
.setAutoCancel(true)
.setSound(defaultSoundUri)
// .setVibrate(new long[]{500})
.setFullScreenIntent(pendingIntent,true)
.setDefaults(NotificationCompat.DEFAULT_VIBRATE)
.addAction(R.drawable.ic_launcher_foreground, "Accept", pendingIntent)
.addAction(R.drawable.ic_launcher_foreground, "Reject", pendingIntent)
.setContentIntent(pendingIntent);
NotificationManager manager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId,
"Default channel",
NotificationManager.IMPORTANCE_HIGH);
channel.setShowBadge(true);
channel.setLockscreenVisibility(VISIBILITY_PUBLIC);
// channel.setVibrationPattern(new long[]{500});
// channel.enableVibration(true);
manager.createNotificationChannel(channel);
// manager.notify(0,builder.build());
}
manager.notify(0, builder.build());
Related
I have an old app developed with Appcelerator - Titanium SDK using FCM Push notifications.
The device token that I get on the device is:
"baf48325219887fdb5929ac5d9495d8897a48f0b77a1c9c23131097e51dc1234"
Because Appcelerator is deprecated, I want to know how to get the FCM token so I can still notify the devices even if Appcelerator has been deprecated.
** UPDATE **
This is the code for getting the deviceToken:
exports.requestDeviceToken = function() {
if (Ti.Platform.model.indexOf('Simulator') !== -1 || Ti.Platform.model.indexOf('Emulator') !== -1) {
return;
}
var params = {
callback:pushNotificationCallback,
success:deviceTokenSuccess,
error: deviceTokenError,
};
var types = [
Ti.Network.NOTIFICATION_TYPE_BADGE,
Ti.Network.NOTIFICATION_TYPE_ALERT,
Ti.Network.NOTIFICATION_TYPE_SOUND
];
if (Ti.Platform.name == 'android') {
var CloudPush = require('ti.cloudpush');
// Initialize the module
CloudPush.retrieveDeviceToken({
success: deviceTokenSuccess,
error: deviceTokenError,
});
CloudPush.addEventListener('callback', pushNotificationCallback);
}
else {
if (Ti.Platform.name != "android" && parseInt(Ti.Platform.version.split(".")[0]) >= 8) {
Ti.API.info('registering push notifications iOS > 8');
Ti.Network.registerForPushNotifications(params);
Ti.App.iOS.registerUserNotificationSettings({types:types});
}
else {
params.types = types;
Ti.Network.registerForPushNotifications(params);
}
}
};
Any clue?
There is https://github.com/hansemannn/titanium-firebase-cloud-messaging available since 2017 that you can use to connect your app to FCM. Using it for years and it's working without any issue.
Transfering an existing app takes around 30mins.
...
if (OS_IOS) {
const FirebaseCore = require('firebase.core');
fc.configure();
}
const FirebaseCloudMessaging = require('firebase.cloudmessaging');
if (OS_ANDROID) {
FirebaseCloudMessaging.registerForPushNotifications();
}
...
as a short example. A fulll example with connection to the Android channels, how to get the token (iOS and Android) is available in the repo at https://github.com/hansemannn/titanium-firebase-cloud-messaging#example
I met with difficulties.
var onaddstream = function(event){
var video = $("#chat_dialogForOne video[name='remote']")[0];
var remoteStream = event.stream;
video.srcObject = remoteStream;
video.onloadedmetadata = function(e) {
video.play();
};
}
$("#chat_dialogForOne button[name='openVideo']").on("click",function(){
$(this).toggleClass("active");
$(this).data("use",$(this).data("use") ? false : true);
if($(this).data("use")){//开启视频语音聊天
rtc.openVideoAudioLocal(function(localStream){//创建本地视频流,绑定到控件上
var video = $("#chat_dialogForOne video[name='video']")[0]; //获取到展现视频的标签
video.srcObject=localStream;
video.onloadedmetadata = function(e) {
video.play();
};
rtc.openVideoAudioLocal(function(remoteStream){
rtc.sendAddStream(remoteStream);
},true,true);
},true,false);//为了防止自己能听到自己发出的声音,只启动视频,不启动音频
$(this).find(" > span").html("结束视频");
$("#chat_dialogForOne button[name='openAudio']").hide();
}else{//关闭视频语音聊天
// closeRemoteChannelStream([oneWebRtc]);
// closeLocalStream();
// resetVideoButton();
}
});
images 2,Successful display of local
images 1,Failure Display Remote
onaddstream,Received the remote stream, it does not show.to video
I need your help.
Sorry, it was a mistake of mine. I made a very slight mistake, which resulted in a new PC object being recreated after receiving the offer. Although the remote received the video stream object, the channel had been replaced.
I'm writing a Hangouts Chat bot in C# that uses pub/sub so I can host the bot on our side of a firewall. Everything seems to work well except interactive buttons within cards. If I create a button with a specific action method name, the bot does receive the CARD_CLICKED message with the appropriate action method name. However, it doesn't seem like the card in the Hangouts Chat app knows a response was sent because the bot ends up getting the CARD_CLICKED message three times before the Hangouts Chat app finally says "Unable to contact Bot. Try again later". I've been using the Google.Apis.HangoutsChat.v1 and Google.Cloud.PubSub.V1 packages from NuGet for the bot.
This is speculation, but it seems like the issue might be that interactive buttons don't work properly through pub/sub. Any help would be appreciated.
Here is a snippet of the code I have:
SubscriptionName subscriptionName = new SubscriptionName(PROJECT_ID, SUBSCRIPTION_ID);
SubscriberServiceApiClient client = SubscriberServiceApiClient.Create();
GoogleCredential credential = GoogleCredential.FromFile(CREDENTIALS_PATH_ENV_PROPERTY).CreateScoped(HANGOUTS_CHAT_API_SCOPE);
HangoutsChatService chatService = new HangoutsChatService(new BaseClientService.Initializer
{
ApplicationName = "My Bot",
HttpClientInitializer = credential
});
while (true)
{
PullResponse response = client.Pull(subscriptionName, false, 3, CallSettings.FromCallTiming(CallTiming.FromExpiration(Expiration.FromTimeout(TimeSpan.FromSeconds(90)))));
if ((response.ReceivedMessages == null) || (response.ReceivedMessages.Count == 0))
Console.WriteLine("Pulled no messages.");
else
{
foreach (ReceivedMessage message in response.ReceivedMessages)
{
try
{
byte[] jsonBytes = message.Message.Data.ToByteArray();
JObject json = JObject.Parse(Encoding.UTF8.GetString(jsonBytes));
string messageType = (string)json["type"];
switch (messageType)
{
case "MESSAGE":
{
// Get text
string messageText = (string)json["message"]["text"];
Console.WriteLine($"[{messageType}] {messageText}");
// Send response
string spaceName = (string)json["space"]["name"];
SpacesResource.MessagesResource.CreateRequest request = chatService.Spaces.Messages.Create(new Message
{
Cards = new[]
{
new Card
{
Header = new CardHeader
{
Title = "Message Received!"
},
Sections = new[]
{
new Section
{
Widgets = new[]
{
new WidgetMarkup
{
Buttons = new[]
{
new Button
{
TextButton = new TextButton
{
Text = "Click Me!",
OnClick = new OnClick
{
Action = new FormAction
{
ActionMethodName = "ClickedAction"
}
}
}
}
}
}
}
}
}
}
},
Thread = new Thread
{
Name = (string)json["message"]["thread"]["name"]
}
}, spaceName);
Message responseMsg = request.Execute();
break;
}
case "CARD_CLICKED":
{
string actionMethodName = (string)json["action"]["actionMethodName"];
Console.WriteLine($"[{messageType}] {actionMethodName} at {((DateTime)json["message"]["createTime"]).ToString()}");
// Send response
string spaceName = (string)json["space"]["name"];
SpacesResource.MessagesResource.CreateRequest request = chatService.Spaces.Messages.Create(new Message
{
ActionResponse = new ActionResponse
{
Type = "UPDATE_MESSAGE"
},
Text = $"You clicked on '{actionMethodName}'.",
Thread = new Thread
{
Name = (string)json["message"]["thread"]["name"]
}
}, spaceName);
Message responseMsg = request.Execute();
break;
}
default:
{
Console.WriteLine($"[{messageType}]");
break;
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Error parsing message: {ex}");
}
}
// Acknowledge the message so we don't see it again.
string[] ackIds = new string[response.ReceivedMessages.Count];
for (int i = 0; i < response.ReceivedMessages.Count; ++i)
ackIds[i] = response.ReceivedMessages[i].AckId;
client.Acknowledge(subscriptionName, ackIds);
}
}
Using buttons with Hangouts Chat API requires a custom answer including:
{
'thread': {
'name': thread_id
},
'actionResponse': {
'type': 'UPDATE_MESSAGE'
}
}
I'd recommend using Hangouts Chat API with a bot URL.
Im developing an "share on facebook" button.
But there is a problem, the facebook dialog is not prompted to the user.
I have tried the sample that titanium provide:
function facebook(){
var fb = require('facebook');
var data = {
link : "http://www.appcelerator.com",
name : "Appcelerator Titanium Mobile",
message : "Checkout this cool open source project for creating apps",
caption : "Appcelerator Titanium Mobile",
picture : "http://developer.appcelerator.com/assets/img/DEV_titmobile_image.png",
description : "You've got the ideas, now you've got the power."
};
fb.dialog("feed", data, function(e) {
var toast = Ti.UI.createNotification({
message:"Default",
duration: Ti.UI.NOTIFICATION_DURATION_LONG
});
if(e.success && e.result)
toast.message = "Success! New Post ID: " + e.result;
else {
if(e.error)
toast.message = e.error;
else
toast.message = "User canceled dialog.";
}
toast.show();
});
}
The function is called correctly, but nothing appear.
Someone knows why? Maybe permissions? But i have read that for the dialog aren't required permissions!
thanks to all
try this:
var fb = require('facebook');
fb.appid = FACEBOOK_APP_ID;
fb.permissions = ['publish_stream']; // Permissions your app needs
fb.forceDialogAuth = true;
fb.addEventListener('login', function(e) {
if (e.success) {
alert('Logged In');
} else if (e.error) {
alert(e.error);
} else if (e.cancelled) {
alert("Canceled");
}
});
fb.authorize();
I solved by myself!
Even if the Facebook Dialog not Require the Auth(), it require the init with an AppID.
var fb = require('facebook');
fb.appid = your_app_id_number;
With this worked very well.
I can't set the video size with video.js
i made a video node:
videoNode = $('<video>');
videoNode.attr('id', 'simulationVideo');
$('#' + _config.videoTargetId).append(videoNode);
i set up the player:
//create new player
myPlayer = _V_("simulationVideo", {
'id': _config.id,
'preload': "auto",
'controls': false,
'autoplay': _config.autoplay
}, function () {
//set listeners for our controlbar
//if (_config.controls) {
controls = new Doczero.VideoPlayer.Controlbar();
//$('#' + _config.controlbarTargetId).append(controls.html());
//put listeners in place
this.addEvent('timeupdate', controls.onTimeUpdate);
this.addEvent('progress', controls.onBufferUpdate);
this.addEvent('play', controls.onPlay);
this.addEvent('pause', controls.onPause);
//listen to controlls
controls.CustomEvents.AddListener('onPressPlay', _self);
//}
});
i play a track:
//set sources to play
this.play = function (srcArray, newCallback) {
//set source
myPlayer.src(srcArray);
myPlayer.play();
//remove old callback
if (callback != null) {
myPlayer.removeEvent('ended', callback);
}
//add new ended callback
myPlayer.removeEvent('ended', newCallback);
}
everything seems to work nice, untill the video pops up 3 times bigger (it stays the orinigal size)