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

Commit

Permalink
Support multi-message
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardLuo0 committed Apr 18, 2019
1 parent 1c0acc3 commit cf19ade
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "com.RichardLuo.notificationpush"
minSdkVersion 22
targetSdkVersion 28
versionCode 9
versionName "1.0.7"
versionCode 10
versionName "1.0.8"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion app/release/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":9,"versionName":"1.0.7","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":10,"versionName":"1.0.8","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ public void onMessageReceived(RemoteMessage remoteMessage) {
if (data.containsKey("senderName"))
senderName = data.get("senderName");
String packageName = remoteMessage.getData().get("package");
PendingIntent intent = null;
PendingIntent intent;

setChannel(packageName);
setSummary(packageName);

switch (packageName) {
case "com.tencent.minihd.qq":
Expand All @@ -62,14 +61,15 @@ public void onMessageReceived(RemoteMessage remoteMessage) {
if (senderName == null)
break;
if (senderName.equals(""))
senderName = "无名氏";
senderName = " ";
setSummary(packageName, intent);
MessagingStyle(packageName, title, senderName, body, intent, notificationManagerCompat, id);
return;
default:
intent = getIntent(packageName);
setSummary(packageName, intent);
}


Notification notification = new NotificationCompat.Builder(this, packageName)
.setSmallIcon(R.drawable.ic_notification)
.setColor(color)
Expand Down Expand Up @@ -150,13 +150,14 @@ private Notification getCurrentNotification(String packageName, int id) {
return null;
}

public void setSummary(String packageName) {
public void setSummary(String packageName, PendingIntent intent) {
Notification summary = new NotificationCompat.Builder(this, packageName)
.setSmallIcon(R.drawable.ic_notification)
.setColor(color)
.setStyle(new NotificationCompat.BigTextStyle()
.setSummaryText(packageName))
.setGroup(packageName)
.setContentIntent(intent)
.setGroupSummary(true)
.setAutoCancel(true)
.setOnlyAlertOnce(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,24 @@ public void onNotificationPosted(StatusBarNotification sbn) {
case "com.RichardLuo.notificationpush":
return;
case "com.tencent.minihd.qq":
if (getSharedPreferences("MainActivity", MODE_PRIVATE).getString("isNotfInstalled", "").equals("true"))
return;
case "com.tencent.mobileqqi":
case "com.tencent.qqlite":
case "com.tencent.tim":
case "com.tencent.mobileqq":
case "com.jinhaihan.qqnotfandshare":
if (!(body.contains("联系人给你") || title.contains("QQ空间") || body.contains("你收到了"))) {
ID = StringToA(title.split("\\s\\(")[0]);
String[] bodySplit = body.split(":");
if (bodySplit.length == 1 || body.split("\\s")[0].equals(""))
senderName = title.split("\\s\\(")[0];
else {
senderName = bodySplit[0];
body = bodySplit[1];
if (!(title.contains("QQ空间") || title.contains("条新消息)"))) {
if (oneNotification.tickerText != null) {
String[] tickerText = oneNotification.tickerText.toString().replaceAll("\n", " ").split(":", 2);
if (tickerText[0].charAt(tickerText[0].length() - 1) == ')') {
String[] name_group = tickerText[0].split("\\(", 2);
senderName = name_group[0];
title = name_group[1].replaceFirst("\\)", "");
} else {
senderName = tickerText[0];
title = tickerText[0];
}
body = tickerText[1];
}
ID = StringToA(title);
}
}

Expand Down
25 changes: 11 additions & 14 deletions app/src/main/java/com/RichardLuo/notificationpush/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,19 @@ public void onComplete(@NonNull Task<InstanceIdResult> task) {
input.setText(preferences.getString("ID", ""));

List<ApplicationInfo> packageInfo = this.getPackageManager().getInstalledApplications(0);
boolean isNotfInstalled = false;
String installedQQ = "";
String installedQQ = preferences.getString("installedQQ", "");
String current = null;
for (ApplicationInfo info : packageInfo) {
if (info.packageName.equals("com.jinhaihan.qqnotfandshare")) {
isNotfInstalled = true;
}
if (installedQQ.equals("")) {
for (String QQName : QQNames) {
if (QQName.equals(info.packageName) && info.enabled) {
installedQQ = QQName;
break;
}
if (info.packageName.equals(installedQQ)) break;
for (String QQName : QQNames) {
if (QQName.equals(info.packageName) && info.enabled) {
current = info.packageName;
preferences.edit().putString("installedQQ", current).apply();
break;
}
}
if (current != null) break;
}
preferences.edit().putString("isNotfInstalled", isNotfInstalled ? "true" : "false").apply();
preferences.edit().putString("installedQQ",installedQQ).apply();
}

@Override
Expand All @@ -176,7 +172,7 @@ protected void onStart() {
} else {
isEnabled = false;
}
preferences.edit().putString("ID", inputID).apply();
preferences.edit().putString("ID", input.getText().toString()).apply();
}

@Override
Expand All @@ -196,6 +192,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
}
} else {
Toast.makeText(this, "请填写设备ID", Toast.LENGTH_SHORT).show();
preferences.edit().putString("ID", input.getText().toString()).apply();
Swh.setChecked(false);
}
} else {
Expand Down

0 comments on commit cf19ade

Please sign in to comment.