Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.

Commit 862c172

Browse files
committed
fix bugs on android 8 and below
1 parent f67d8d1 commit 862c172

5 files changed

Lines changed: 35 additions & 20 deletions

File tree

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ android {
66
applicationId "com.RichardLuo.notificationpush"
77
minSdkVersion 22
88
targetSdkVersion 28
9-
versionCode 20
10-
versionName "1.1.3(1)"
9+
versionCode 23
10+
versionName "1.1.3(3)"
1111
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1212
}
1313
buildTypes {

app/release/app-release.apk

118 Bytes
Binary file not shown.

app/release/output.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":20,"versionName":"1.1.3(1)","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
1+
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":23,"versionName":"1.1.3(3)","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]

app/src/main/java/com/RichardLuo/notificationpush/FCMReceiver.java

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,54 +89,63 @@ public void onMessageReceived(RemoteMessage remoteMessage) {
8989
senderName = " ";
9090
IconCompat icon = null;
9191
Bitmap largeIcon = null;
92-
out:
9392
if (getDefaultSharedPreferences(this).getBoolean("sendQQ", false) && this.getDatabasePath("friends.db").exists()) {
93+
boolean isfriend = senderName.equals(title);
9494
String encodeSendername = senderName.replace(" ", "%20").replace("/", "%2f");
9595
File file = new File(this.getCacheDir().getPath() + "/" + encodeSendername);
96+
out:
9697
try {
9798
if (!file.exists()) {
9899
SQLiteDatabase db;
99100
Cursor cursor;
100-
String groupNumber = null;
101-
if (senderName.equals(title)) {
101+
if (isfriend) {
102102
db = SQLiteDatabase.openOrCreateDatabase(this.getDatabasePath("friends.db"), null);
103-
cursor = db.query("friends", new String[]{"uin"}, "name ='" + encodeSendername + "'", null, null, null, null);
103+
if (getSharedPreferences("groups", MODE_PRIVATE).contains("sync_friends"))
104+
cursor = db.query("friends", new String[]{"uin"}, "name ='" + encodeSendername + "'", null, null, null, null);
105+
else
106+
break out;
104107
} else if (getSharedPreferences("groups", MODE_PRIVATE).contains(title)) {
105108
db = SQLiteDatabase.openOrCreateDatabase(this.getDatabasePath("friends.db"), null);
106109
Cursor cursorTemp = db.query("'" + title + "'", new String[]{"uin"}, "name ='" + encodeSendername + "'", null, null, null, null);
107110
if (cursorTemp.getCount() == 0) {
108111
cursorTemp.close();
109112
cursor = db.query("friends", new String[]{"uin"}, "name ='" + encodeSendername + "'", null, null, null, null);
110113
} else cursor = cursorTemp;
111-
groupNumber = getSharedPreferences("groupsNumber", MODE_PRIVATE).getString(title, null);
112-
} else {
113-
groupNumber = getSharedPreferences("groupsNumber", MODE_PRIVATE).getString(title, null);
114-
largeIcon = downloadIcon("https://p.qlogo.cn/gh/" + groupNumber + "/" + groupNumber + "/100", title);
114+
} else
115115
break out;
116-
}
117116
if (cursor.getCount() != 0) {
118117
if (cursor.moveToFirst()) {
119118
String QQnumber = cursor.getString(0);
120119
cursor.close();
121120
db.close();
122-
Bitmap bitmap = downloadIcon("https://q4.qlogo.cn/g?b=qq&s=140&nk=" + QQnumber, encodeSendername);
123-
if (groupNumber == null)
124-
largeIcon = bitmap;
125-
else
126-
largeIcon = downloadIcon("https://p.qlogo.cn/gh/" + groupNumber + "/" + groupNumber + "/100", title);
121+
downloadIcon("https://q4.qlogo.cn/g?b=qq&s=140&nk=" + QQnumber, encodeSendername);
127122
}
128123
} else {
129124
cursor.close();
130125
db.close();
131126
break out;
132127
}
133-
} else {
134-
largeIcon = BitmapFactory.decodeFile(this.getCacheDir().getPath() + "/" + encodeSendername);
135128
}
136129
icon = IconCompat.createWithBitmap(BitmapFactory.decodeFile(this.getCacheDir().getPath() + "/" + encodeSendername));
137130
} catch (IOException e) {
138131
e.printStackTrace();
139132
}
133+
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.P)
134+
if (isfriend) {
135+
if (icon != null)
136+
largeIcon = BitmapFactory.decodeFile(this.getCacheDir().getPath() + "/" + encodeSendername);
137+
} else if (new File(this.getCacheDir().getPath() + "/" + title).exists())
138+
largeIcon = BitmapFactory.decodeFile(this.getCacheDir().getPath() + "/" + title);
139+
else {
140+
String groupNumber = getSharedPreferences("groupsNumber", MODE_PRIVATE).getString(title, null);
141+
if (groupNumber != null) {
142+
try {
143+
largeIcon = downloadIcon("https://p.qlogo.cn/gh/" + groupNumber + "/" + groupNumber + "/100", title);
144+
} catch (IOException e) {
145+
e.printStackTrace();
146+
}
147+
}
148+
}
140149
}
141150
setSummary(packageName, AppName, intent);
142151
MessagingStyle(packageName, AppName, title, senderName, body, intent, id, icon, largeIcon);
@@ -288,7 +297,7 @@ private void MessagingStyle(String packageName, String AppName, String title, St
288297
.setColor(color)
289298
.setContentTitle(packageName)
290299
.setStyle(style);
291-
if (largeIcon != null)
300+
if (largeIcon != null && android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.P)
292301
notification.setLargeIcon(largeIcon);
293302
notification.setGroup(packageName)
294303
.setContentIntent(intent)

app/src/main/java/com/RichardLuo/notificationpush/Preferences.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ public void run() {
232232
if (getActivity() != null)
233233
getActivity().runOnUiThread(new Runnable() {
234234
public void run() {
235+
getActivity().getSharedPreferences("groups", MODE_PRIVATE).edit().putBoolean("sync_friends", true).apply();
235236
Toast.makeText(getContext(), "同步成功", Toast.LENGTH_SHORT).show();
236237
}
237238
});
@@ -294,7 +295,12 @@ public void onClick(DialogInterface dialog, int which) {
294295
new Thread() {
295296
@Override
296297
public void run() {
298+
boolean isSyncfriends = false;
299+
if (getActivity().getSharedPreferences("groups", MODE_PRIVATE).contains("sync_friends"))
300+
isSyncfriends = true;
297301
getActivity().getSharedPreferences("groups", MODE_PRIVATE).edit().clear().apply();
302+
if (isSyncfriends)
303+
getActivity().getSharedPreferences("groups", MODE_PRIVATE).edit().putBoolean("sync_friends", true).apply();
298304
for (final Integer choice : choices) {
299305
if (getActivity() != null)
300306
getActivity().runOnUiThread(new Runnable() {

0 commit comments

Comments
 (0)