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

Commit 9a3dc4d

Browse files
committed
support 5.0 and bug fix
1 parent 862c172 commit 9a3dc4d

22 files changed

Lines changed: 249 additions & 81 deletions

File tree

.idea/codeStyles/Project.xml

Lines changed: 116 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ android {
44
compileSdkVersion 28
55
defaultConfig {
66
applicationId "com.RichardLuo.notificationpush"
7-
minSdkVersion 22
7+
minSdkVersion 21
88
targetSdkVersion 28
9-
versionCode 23
10-
versionName "1.1.3(3)"
9+
versionCode 24
10+
versionName "1.1.3(4)"
1111
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1212
}
1313
buildTypes {
@@ -19,13 +19,13 @@ android {
1919

2020
dependencies {
2121
implementation fileTree(include: ['*.jar'], dir: 'libs')
22-
implementation 'androidx.appcompat:appcompat:1.0.2'
23-
implementation 'androidx.preference:preference:1.0.0'
24-
implementation 'androidx.media:media:1.0.1'
22+
implementation 'androidx.appcompat:appcompat:1.1.0'
23+
implementation 'androidx.preference:preference:1.1.0'
24+
implementation 'androidx.media:media:1.1.0'
2525
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
2626
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
27-
implementation 'com.google.firebase:firebase-core:17.0.1'
28-
implementation 'com.google.firebase:firebase-messaging:19.0.1'
27+
implementation 'com.google.firebase:firebase-core:17.2.0'
28+
implementation 'com.google.firebase:firebase-messaging:20.0.0'
2929
testImplementation 'junit:junit:4.12'
3030
androidTestImplementation 'androidx.test:runner:1.2.0'
3131
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

app/release/app-release.apk

55.5 KB
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":23,"versionName":"1.1.3(3)","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
1+
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":24,"versionName":"1.1.3(4)","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.os.Bundle;
88
import android.os.Handler;
99
import android.view.LayoutInflater;
10+
import android.view.Menu;
1011
import android.view.MenuItem;
1112
import android.view.View;
1213
import android.view.ViewGroup;
@@ -28,7 +29,9 @@ public class Application extends AppCompatActivity {
2829
ListView listView;
2930
SharedPreferences preferences;
3031
ProgressBar progressBar;
32+
Runnable update;
3133
Handler handler = new Handler();
34+
boolean filterSystemApp = true;
3235

3336
@Override
3437
protected void onCreate(Bundle savedInstanceState) {
@@ -42,12 +45,13 @@ protected void onCreate(Bundle savedInstanceState) {
4245
final PackageManager packageManager = getPackageManager();
4346
final List<ApplicationInfo> packageInfo = packageManager.getInstalledApplications(0);
4447

45-
new Thread() {
48+
update = new Runnable() {
4649
@Override
4750
public void run() {
48-
super.run();
4951
final List<info> packageView = new ArrayList<>();
5052
for (final ApplicationInfo applicationInfo : packageInfo) {
53+
if (filterSystemApp && !((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0))
54+
continue;
5155
final String name = packageManager.getApplicationLabel(applicationInfo).toString();
5256
Spinner.OnItemSelectedListener onItemSelectedListener = new Spinner.OnItemSelectedListener() {
5357
@Override
@@ -131,13 +135,27 @@ class info {
131135
this.selection = selection;
132136
}
133137
}
134-
}.start();
138+
};
139+
new Thread(update).start();
140+
}
141+
142+
@Override
143+
public boolean onCreateOptionsMenu(Menu menu) {
144+
getMenuInflater().inflate(R.menu.appmenu, menu);
145+
return true;
135146
}
136147

137148
@Override
138149
public boolean onOptionsItemSelected(MenuItem item) {
139-
if (item.getItemId() == android.R.id.home)
140-
finish();
150+
switch (item.getItemId()) {
151+
case android.R.id.home:
152+
finish();
153+
break;
154+
case R.id.filter:
155+
filterSystemApp = !filterSystemApp;
156+
new Thread(update).start();
157+
break;
158+
}
141159
return true;
142160
}
143161
}

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.util.HashMap;
3636
import java.util.List;
3737
import java.util.Map;
38+
import java.util.Objects;
3839

3940
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
4041
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
@@ -60,7 +61,7 @@ public void onMessageReceived(RemoteMessage remoteMessage) {
6061
String body = data.get("body");
6162
String packageName = data.get("package");
6263
String AppName = data.get("name");
63-
int id = Integer.valueOf(data.get("id"));
64+
int id = Integer.valueOf(Objects.requireNonNull(data.get("id")));
6465
String senderName = null;
6566
if (data.containsKey("senderName"))
6667
senderName = data.get("senderName");
@@ -71,7 +72,7 @@ public void onMessageReceived(RemoteMessage remoteMessage) {
7172

7273
setChannel(AppName);
7374

74-
switch (packageName) {
75+
switch (Objects.requireNonNull(packageName)) {
7576
case "com.tencent.minihd.qq":
7677
case "com.tencent.mobileqqi":
7778
case "com.tencent.qqlite":
@@ -155,7 +156,7 @@ public void onMessageReceived(RemoteMessage remoteMessage) {
155156
setSummary(packageName, AppName, intent);
156157
}
157158

158-
Notification notification = new NotificationCompat.Builder(this, AppName)
159+
Notification notification = new NotificationCompat.Builder(this, Objects.requireNonNull(AppName))
159160
.setSmallIcon(R.drawable.ic_notification)
160161
.setColor(color)
161162
.setStyle(new NotificationCompat.BigTextStyle()
@@ -170,12 +171,13 @@ public void onMessageReceived(RemoteMessage remoteMessage) {
170171
notificationManagerCompat.notify(packageName, id, notification);
171172
}
172173

174+
@SuppressWarnings("SuspiciousNameCombination")
173175
private Bitmap downloadIcon(String url, String name) throws IOException {
174176
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
175177
connection.setRequestMethod("GET");
176178
connection.setDoInput(true);
177-
connection.setConnectTimeout(1000);
178-
connection.setReadTimeout(1000);
179+
connection.setConnectTimeout(2000);
180+
connection.setReadTimeout(2000);
179181
connection.connect();
180182
if (connection.getResponseCode() == 200 || connection.getResponseCode() == 304) {
181183
InputStream inputStream = connection.getInputStream();
@@ -223,6 +225,7 @@ public void setChannel(String AppName) {
223225
}
224226
}
225227

228+
@SuppressWarnings("ConstantConditions")
226229
private PendingIntent getIntent(String packageName) {
227230
PendingIntent intent = null;
228231
if (Package_Intent.containsKey(packageName)) {
@@ -282,7 +285,7 @@ private void MessagingStyle(String packageName, String AppName, String title, St
282285
NotificationCompat.MessagingStyle style;
283286
if (!((current = getCurrentNotification(packageName, ID)) == null)) {
284287
style = NotificationCompat.MessagingStyle.extractMessagingStyleFromNotification(current);
285-
style.addMessage(message, new Date().getTime(), sender);
288+
Objects.requireNonNull(style).addMessage(message, new Date().getTime(), sender);
286289
} else {
287290
style = new NotificationCompat.MessagingStyle(sender);
288291
if (title.equals(senderName))

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

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.os.StrictMode;
77
import android.service.notification.NotificationListenerService;
88
import android.service.notification.StatusBarNotification;
9+
import android.util.Log;
910

1011
import org.json.JSONObject;
1112

@@ -94,40 +95,6 @@ public void run() {
9495
ID = StringToA(title);
9596
} else
9697
return;
97-
/*if (body.contains("联系人给你") || body.contains("你收到了")) {
98-
QQcount = true;
99-
String tickerText;
100-
if (oneNotification.tickerText != null)
101-
tickerText = oneNotification.tickerText.toString().replace("\n", "");
102-
else
103-
return;
104-
Matcher matcher = Pattern.compile("^(.*?)\\((((?![()]).)*?)\\):(.*?)$").matcher(tickerText);
105-
if (matcher.find()) {
106-
senderName = matcher.group(1);
107-
title = matcher.group(2);
108-
body = matcher.group(4).trim();
109-
} else {
110-
String[] single = tickerText.split(":", 2);
111-
senderName = single[0];
112-
title = single[0];
113-
body = single[1];
114-
}
115-
} else {
116-
if (QQcount) {
117-
QQcount = false;
118-
return;
119-
}
120-
QQcount = false;
121-
title = title.split("\\s\\(", 2)[0];
122-
String[] bodySplit = body.split(":\\s", 2);
123-
if (bodySplit.length == 1 || body.split("\\s", 2)[0].equals(""))
124-
senderName = title;
125-
else {
126-
senderName = bodySplit[0];
127-
body = bodySplit[1];
128-
}
129-
}
130-
ID = StringToA(title);*/
13198
}
13299
}
133100

@@ -164,7 +131,7 @@ public void run() {
164131
connection.getResponseCode();
165132
connection.disconnect();
166133
} catch (Exception e) {
167-
e.printStackTrace();
134+
Log.e("error:", "Can't send " + packageName + " " + title);
168135
}
169136
super.run();
170137
}

0 commit comments

Comments
 (0)