I am currently using Beem's source code to do developments. I would like to implement the chat state notifications. I have look through the codes and found that there is a setState() method, but I believe it has not been implemented and I have no clues about how to do it. If I use Adium to type a message to the Beem user, the Beem user is able to see that the Adium user is composing a message. But if both users are using Beem, then it does not display if the user is composing a message. Therefore, I would like to try to implement the chat state notification. How do I go about doing it? Is there any guides out there? Can someone help me? Thanks!
Add this code to setState method in ChatAdapter.java file.
org.jivesoftware.smack.packet.Message message = new org.jivesoftware.smack.packet.Message();
ChatStateExtension extension = null;
switch (state) {
case "composing":
extension = new ChatStateExtension(ChatState.composing);
break;
case "active":
extension = new ChatStateExtension(ChatState.active);
break;
case "inactive":
extension = new ChatStateExtension(ChatState.inactive);
break;
case "gone":
extension = new ChatStateExtension(ChatState.gone);
break;
case "paused":
extension = new ChatStateExtension(ChatState.paused);
break;
}
message.addExtension(extension);
try {
mAdaptee.sendMessage(message);
} catch (XMPPException e) {
e.printStackTrace();
}
Related
I am having a hard time navigating to a screen when a background FCM message receives. Currently, I am sending an FCM message with some data and when it gets received by a device then it calls this package that shows a calling notification, and when the user clicks on accept call option then I want to open my app and navigate to the desired screen. I use GetX for navigation and when I try to go to another screen it gives this exception:
I have tried almost everything to work this out but I am still unable to solve this problem.
my FirebaseMessaging.onBackgroundMessage Background handler which receives the notification also listens to user feedback on whether the call is accepted or rejected:
Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
var incoming = <String, dynamic>{
'id': message.data['callerID'],
'nameCaller': message.data['callerName'],
'appName': 'Callkit',
'avatar': message.data['callerImage'],
'handle': '',
'type': 0,
'duration': 30000,
'extra': <String, dynamic>{'userId': '1a2b3c4d'},
'headers': <String, dynamic>{'apiKey': 'Abc#123!', 'platform': 'flutter'},
'android': <String, dynamic>{
'isCustomNotification': true,
'isShowLogo': false,
'ringtonePath': 'ringtone_default',
'backgroundColor': '#0955fa',
//'backgroundUrl': 'https://i.pravatar.cc/500',
'actionColor': '#4CAF50'
}};
await FlutterCallkitIncoming.showCallkitIncoming(incoming);
try {
FlutterCallkitIncoming.onEvent.listen((event) {
switch (event!.name) {
case CallEvent.ACTION_CALL_INCOMING:
print('INCOMING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
break;
case CallEvent.ACTION_CALL_START:
// TODO: started an outgoing call
// TODO: show screen calling in Flutter
break;
case CallEvent.ACTION_CALL_ACCEPT:
print('accepted');
Get.offAll(()=> Incoming(
userName: null,
userImage: null,
userID: null,
userUsername: null));
break;
case CallEvent.ACTION_CALL_DECLINE:
print('rejected');
break;
case CallEvent.ACTION_CALL_ENDED:
// TODO: ended an incoming/outgoing call
break;
case CallEvent.ACTION_CALL_TIMEOUT:
// TODO: missed an incoming call
break;
case CallEvent.ACTION_CALL_CALLBACK:
// TODO: only Android - click action `Call back` from missed call notification
break;
case CallEvent.ACTION_CALL_TOGGLE_HOLD:
// TODO: only iOS
break;
case CallEvent.ACTION_CALL_TOGGLE_MUTE:
// TODO: only iOS
break;
case CallEvent.ACTION_CALL_TOGGLE_DMTF:
// TODO: only iOS
break;
case CallEvent.ACTION_CALL_TOGGLE_GROUP:
// TODO: only iOS
break;
case CallEvent.ACTION_CALL_TOGGLE_AUDIO_SESSION:
// TODO: only iOS
break;
}
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
});
} on Exception {}
}
Similar to the answer that Peter Koltai gave, your background handler is isolated from your application's context and so it's not possible to route to screens (which require a context) directly from your handler.
One possible solution is to implement an Android service using native code that communicates with Flutter via a MethodChannel and on the event that a call is accepted, you can navigate screens.
You can change your MaterialApp() with GetMaterialApp(), and check if you are using get.to(AnotherPage()), instead use get.to(()=>AnotherPage()).
i never tested it before but i think you should use wakelock to keep your screen awake
enter link description here
Implementing the User's chosen Preferences into my Code is a new conquest for me.
I've successfully implemented a portion of the Preferences to Code, but could use advice.
I have chosen to use the Preferences-API and a PreferenceFragment for my App Settings.
So far I have my SettingsActivity set up, working, and updating new values correctly.
However, some assistance is needed now that I'm implementing Preference values to Code.
There are 2 Preferences which I am struggling to implement into Code.
However, for now, I'll discuss just 1 of them.. The details are as follows :
Preference = Notification Type( key = pref_notificationType ) - ( constant String = PREF_NOTIFICATION_TYPE )
Values :
Sound and Vibration
Sound only
Vibration only
Silent
( NOTE : These are the exact value names for this Preference ).
I want to do something along these lines, except correctly, and efficiently:
public void notificationType() {
SharedPreferences getPrefs = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
final String notifType =
getPrefs.getString(PREF_NOTIFICATION_TYPE, "Sound and Vibration");
switch (notifType) {
case ("Sound and Vibration"):
// Create Notification with SOUND (AND) VIBRATION
break;
case ("Sound only"):
// Create Notification with SOUND (only)
break;
case ("Vibrate only"):
// Create Notification with VIBRATION (only)
break;
case ("Silent"):
// Create Notification SILENTLY
break;
default:
// The default is "Sound and Vibration"
break;
}
}
If anybody could please provide some advice on how to go about this, I would greatly appreciate it!
Thanks in advance!
I think in this case the best way create Enum and compare this in swithc.
enum NotificationType {
SOUND_AND_VIBRATE, SOUND_ONLY, VIBRATE_ONLY, SILENT
}
//and
switch (NotificationType) {
case SOUND_AND_VIBRATE:
case SOUND_ONLY:
case VIBRATE_ONLY:
case SILENT:
}
When user canceled the download request that requires the user confirmation, the request status is supposed to change to CANCELED. However, the state listener doesn't seem to receive that state change. Below is the example code of the listener. Any idea? Thank you in advance!
switch(state.status()) {
case SplitInstallSessionStatus.REQUIRES_USER_CONFIRMATION:
try {
getContext().startIntentSender(
state.resolutionIntent().getIntentSender(),
null,
0,
0,
0);
} catch (Exception e) {
Log.e(TAG, "stats onStateUpdate: ", e);
}
break;
case SplitInstallSessionStatus.CANCELED:
Log.d(TAG, "onStateUpdate: canceled”);
//NEVER GET TO THIS LINE
break;
}
The issue seems to be resolved in the most recent update com.google.android.play:core:1.3.7. We can't replicate the issue after the upgrade. The one we used before is 1.3.6.
I am making a chat application where I want the a user to get a notification when the other user sends a message. I've heard you can do it with a js script and followed the google guidelines but I'm confused where am I actually writing the script? Do I have to do the free trial for the google firebase environment?
You can do like this:-
DatabaseReference ref = FirebaseDatabase.getInstance().getReference(reference)
FirebaseArray snapshots = new FirebaseArray(ref);
snapshots.setOnChangedListener(new FirebaseArray.OnChangedListener() {
#Override
public void onChanged(EventType type, int index, int oldIndex) {
switch (type) {
case Added:
break;
case Changed:
break;
case Removed:
break;
case Moved:
break;
}
}
});
I want to be able to listen (BroadcastReceiver?) for whenever a notification occurs for my app and for the calendar app, even if the user doesn't interact with it and even if the screen is off.
I also want to be able to know when a user swipes away the notification.
I know that AccessibilityEvent can enable doing the first thing (listening for notifications) but it can't do the second one (Cannot listen for notification dismissal). Is there another way?
How would I do this? Can I at least have my app/listener called when my own notifications occur (they're for calendar events) and know that the notification is still in the notification tray?
You can listen all the calendar notification info. How you say, you should use an AccessibilityService and switch the notification type. Then you get the package name an compare if it's from google calendar.
public void onAccessibilityEvent(AccessibilityEvent event) {
try {
switch (event.getEventType()) {
case AccessibilityEvent.TYPE_VIEW_CLICKED:
Log.d(LOG_SERVICE, "Click");
break;
case AccessibilityEvent.TYPE_VIEW_FOCUSED:
Log.d(LOG_SERVICE, "Focused");
break;
case AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED:
Log.d(LOG_SERVICE, "Ihas been received a not" + type);
String pack = (String) event.getPackageName();
if (pack.equalsIgnoreCase("com.google.android.calendar")) {
//The event information.
}
break;
default:
type = "otro";
Log.d(LOG_SERVICE, "otro");
break;
}
AccessibilityNodeInfo notinfo = event.getSource();
if (notinfo != null) {
doSomethingWithNodeInfo(notinfo);
}
} catch (Exception e) {
e.printStackTrace();
}
If the Android device is with ICS or more. You can use AccessibilityNodeInfo if the app developer design their notifications with accessibility.