77import android .content .pm .ApplicationInfo ;
88import android .database .Cursor ;
99import android .database .sqlite .SQLiteDatabase ;
10- import android .graphics .*;
10+ import android .graphics .Bitmap ;
11+ import android .graphics .BitmapFactory ;
12+ import android .graphics .Canvas ;
13+ import android .graphics .Paint ;
14+ import android .graphics .PorterDuff ;
15+ import android .graphics .PorterDuffXfermode ;
16+ import android .graphics .Rect ;
1117import android .os .Build ;
1218import android .service .notification .StatusBarNotification ;
19+
1320import androidx .core .app .NotificationCompat ;
1421import androidx .core .app .NotificationManagerCompat ;
1522import androidx .core .app .Person ;
1623import androidx .core .graphics .drawable .IconCompat ;
24+
1725import com .google .firebase .messaging .FirebaseMessagingService ;
1826import com .google .firebase .messaging .RemoteMessage ;
1927
@@ -90,18 +98,23 @@ public void onMessageReceived(RemoteMessage remoteMessage) {
9098 Cursor cursor ;
9199 if (senderName .equals (title )) {
92100 db = SQLiteDatabase .openOrCreateDatabase (this .getDatabasePath ("friends.db" ), null );
93- cursor = db .query ("friends" , new String []{"uin" }, "name ='" + senderName + "'" , null , null , null , null );
101+ cursor = db .query ("friends" , new String []{"uin" }, "name ='" + encodeSendername + "'" , null , null , null , null );
94102 } else if (getSharedPreferences ("groups" , MODE_PRIVATE ).contains (title )) {
95103 db = SQLiteDatabase .openOrCreateDatabase (this .getDatabasePath ("friends.db" ), null );
96- cursor = db .query ("'" + title + "'" , new String []{"uin" }, "name ='" + senderName + "'" , null , null , null , null );
104+ Cursor cursorTemp = db .query ("'" + title + "'" , new String []{"uin" }, "name ='" + encodeSendername + "'" , null , null , null , null );
105+ if (cursorTemp .getCount () == 0 ) {
106+ cursorTemp .close ();
107+ cursor = db .query ("friends" , new String []{"uin" }, "name ='" + encodeSendername + "'" , null , null , null , null );
108+ } else cursor = cursorTemp ;
97109 } else
98110 break out ;
99111 if (cursor .getCount () != 0 ) {
100112 if (cursor .moveToFirst ()) {
101113 String QQnumber = cursor .getString (0 );
102114 cursor .close ();
103115 db .close ();
104- HttpURLConnection connection = (HttpURLConnection ) new URL ("https://qlogo3.store.qq.com/qzone/" + QQnumber + "/" + QQnumber + "/50.png" ).openConnection ();
116+ HttpURLConnection connection = (HttpURLConnection ) new URL ("https://q4.qlogo.cn/g?b=qq&s=140&nk=" + QQnumber ).openConnection ();
117+ connection .setRequestMethod ("GET" );
105118 connection .setDoInput (true );
106119 connection .setConnectTimeout (1000 );
107120 connection .setReadTimeout (1000 );
@@ -244,10 +257,13 @@ private void MessagingStyle(String packageName, String AppName, String title, St
244257 style = NotificationCompat .MessagingStyle .extractMessagingStyleFromNotification (current );
245258 style .addMessage (message , new Date ().getTime (), sender );
246259 } else {
247- style = new NotificationCompat .MessagingStyle (sender )
248- .setConversationTitle (title )
249- .setGroupConversation (true )
250- .addMessage (message , new Date ().getTime (), sender );
260+ style = new NotificationCompat .MessagingStyle (sender );
261+ if (title .equals (senderName ))
262+ style .setGroupConversation (false );
263+ else {
264+ style .setConversationTitle (title ).setGroupConversation (true );
265+ }
266+ style .addMessage (message , new Date ().getTime (), sender );
251267 }
252268
253269 Notification notification = new NotificationCompat .Builder (this , AppName )
@@ -262,59 +278,4 @@ private void MessagingStyle(String packageName, String AppName, String title, St
262278 .build ();
263279 notificationManagerCompat .notify (packageName , ID , notification );
264280 }
265-
266- /*private void forQQ(String packageName, String title, String body, PendingIntent intent, NotificationManagerCompat notificationManagerCompat) {
267- setChannel(packageName);
268- Notification notification;
269- if (!(body.contains("联系人给你") || title.contains("QQ空间") || body.contains("你收到了"))) {
270- int TitleID = StringToA(title.split("\\s\\(")[0]);
271- String[] bodySplit = body.split(":");
272- Person sender;
273- String message;
274- if (bodySplit.length == 1 || body.split("\\s")[0].equals("")) {
275- sender = new Person.Builder()
276- .setName(title.split("\\s\\(")[0])
277- .build();
278- message = body;
279- } else {
280- sender = new Person.Builder()
281- .setName(bodySplit[0])
282- .build();
283- message = bodySplit[1];
284- }
285- NotificationCompat.MessagingStyle style;
286- Notification current;
287- if (!((current = getCurrentNotification(packageName, TitleID)) == null)) {
288- style = NotificationCompat.MessagingStyle.extractMessagingStyleFromNotification(current);
289- style.addMessage(message, new Date().getTime(), sender);
290- } else {
291- style = new NotificationCompat.MessagingStyle(sender)
292- .setConversationTitle(title)
293- .addMessage(message, new Date().getTime(), sender);
294- }
295- notification = new NotificationCompat.Builder(this, packageName)
296- .setSmallIcon(R.drawable.ic_notification)
297- .setColor(color)
298- .setContentTitle(packageName)
299- .setStyle(style)
300- .setGroup(packageName)
301- .setContentIntent(intent)
302- .setAutoCancel(true)
303- .setOnlyAlertOnce(true)
304- .build();
305- notificationManagerCompat.notify(packageName, TitleID, notification);
306- } else {
307- notification = new NotificationCompat.Builder(this, packageName)
308- .setSmallIcon(R.drawable.ic_notification)
309- .setColor(color)
310- .setContentTitle(title)
311- .setContentText(body)
312- .setGroup(packageName)
313- .setContentIntent(intent)
314- .setAutoCancel(true)
315- .setOnlyAlertOnce(true)
316- .build();
317- notificationManagerCompat.notify(packageName, 0, notification);
318- }
319- }*/
320281}
0 commit comments