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

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardLuo0 committed May 1, 2019
1 parent 88f64bc commit 14da0a8
Show file tree
Hide file tree
Showing 14 changed files with 151 additions and 39 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android {
applicationId "com.RichardLuo.notificationpush"
minSdkVersion 22
targetSdkVersion 28
versionCode 12
versionCode 13
versionName "1.1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
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":12,"versionName":"1.1.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":13,"versionName":"1.1.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
11 changes: 11 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service
android:name=".ForegroundMonitor"
android:label="@string/access_name"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
<meta-data
android:name="android.accessibilityservice"
android:resource="@xml/accessibility" />
</service>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void onNothingSelected(AdapterView<?> parent) {

}
};
packageView.add(new info(name, packageManager.getApplicationIcon(applicationInfo), onItemSelectedListener,preferences.getInt(applicationInfo.packageName, 0)));
packageView.add(new info(name, packageManager.getApplicationIcon(applicationInfo), onItemSelectedListener, preferences.getInt(applicationInfo.packageName, 0)));
}

handler.post(new Runnable() {
Expand Down Expand Up @@ -132,5 +132,9 @@ class info {
}.start();
}


@Override
public boolean onSupportNavigateUp() {
finish();
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public void onMessageReceived(RemoteMessage remoteMessage) {
senderName = data.get("senderName");
String packageName = remoteMessage.getData().get("package");
PendingIntent intent;
if (getSharedPreferences("MainActivity", MODE_PRIVATE).getBoolean("hide", false) && ForegroundMonitor.packageName.equals(packageName))
return;

setChannel(packageName);

Expand All @@ -56,6 +58,9 @@ public void onMessageReceived(RemoteMessage remoteMessage) {
case "com.tencent.tim":
case "com.tencent.mobileqq":
case "com.jinhaihan.qqnotfandshare":
String className = ForegroundMonitor.packageName;
if (getSharedPreferences("MainActivity", MODE_PRIVATE).getBoolean("hide", false) && (className.contains("com.tencent.") && (className.contains("qq") || className.contains("tim"))))
return;
String QQpackageName = getSharedPreferences("MainActivity", MODE_PRIVATE).getString("installedQQ", null);
intent = getIntent(QQpackageName);
if (senderName == null)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.RichardLuo.notificationpush;

import android.accessibilityservice.AccessibilityService;
import android.view.accessibility.AccessibilityEvent;

public class ForegroundMonitor extends AccessibilityService {
static String packageName = "";

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
if (event.getPackageName() == null)
return;
packageName = event.getPackageName().toString();
}
}

@Override
public void onInterrupt() {

}
}
91 changes: 74 additions & 17 deletions app/src/main/java/com/RichardLuo/notificationpush/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
Expand All @@ -19,7 +20,6 @@
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
Expand All @@ -31,12 +31,12 @@

import java.util.List;

//TODO 增加应用前台判断
public class MainActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener {
public class MainActivity extends AppCompatActivity implements Switch.OnCheckedChangeListener {
static SharedPreferences preferences;
static Intent service;
boolean isEnabled;
boolean isNotiListenerEnabled;
boolean isAccessEnabled;
Switch swh;
Switch hide;
EditText input;
TextView DeviceID;
Button priority;
Expand All @@ -53,12 +53,27 @@ protected void onCreate(Bundle savedInstanceState) {
setTheme(preferences.getInt("style", R.style.base_AppTheme_teal));
setContentView(R.layout.activity_main);
swh = findViewById(R.id.switch1);
swh.setOnCheckedChangeListener(this);

priority = findViewById(R.id.priority);
priority.setOnClickListener(new Button.OnClickListener() {
hide = findViewById(R.id.switch2);
hide.setOnCheckedChangeListener(new Switch.OnCheckedChangeListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getApplicationContext(), Application.class));
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (isChecked) {
if (isAccessEnabled) {
preferences.edit().putBoolean("hide", true).apply();
} else {
startActivity(intent);
preferences.edit().putBoolean("hide", false).apply();
hide.setChecked(false);
}
} else {
if (isAccessEnabled)
startActivity(intent);
preferences.edit().putBoolean("hide", false).apply();
}
}
});

Expand All @@ -77,6 +92,14 @@ public void onClick(View v) {
}
});

priority = findViewById(R.id.priority);
priority.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getApplicationContext(), Application.class));
}
});

colors = findViewById(R.id.colors);
colors.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down Expand Up @@ -146,7 +169,7 @@ public void onClick(DialogInterface dialog, int which) {
normalDialog.show();
}
});
swh.setOnCheckedChangeListener(this);

FirebaseInstanceId.getInstance().getInstanceId()
.addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
@Override
Expand All @@ -158,7 +181,6 @@ public void onComplete(@NonNull Task<InstanceIdResult> task) {
DeviceID.setText(task.getResult().getToken());
}
});
startService(new Intent(this, FCMReceiver.class));
input.setText(preferences.getString("ID", ""));

List<ApplicationInfo> packageInfo = this.getPackageManager().getInstalledApplications(0);
Expand All @@ -181,12 +203,19 @@ public void onComplete(@NonNull Task<InstanceIdResult> task) {
protected void onStart() {
super.onStart();
if (isNotificationListenersEnabled()) {
isEnabled = true;
isNotiListenerEnabled = true;
swh.setChecked(true);
} else {
isEnabled = false;
isNotiListenerEnabled = false;
swh.setChecked(false);
}
if (isAccessibilitySettingsOn(this)) {
isAccessEnabled = true;
hide.setChecked(true);
} else {
isAccessEnabled = false;
hide.setChecked(false);
}
preferences.edit().putString("ID", input.getText().toString()).apply();
}

Expand All @@ -196,10 +225,9 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (isChecked) {
if (!input.getText().toString().trim().isEmpty()) {
if (isEnabled) {
if (isNotiListenerEnabled) {
preferences.edit().putString("ID", input.getText().toString()).apply();
input.setEnabled(false);
startService(service = new Intent(this, GetNotification.class));
} else {
startActivity(intent);
input.setEnabled(true);
Expand All @@ -212,10 +240,9 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
swh.setChecked(false);
}
} else {
if (isEnabled)
if (isNotiListenerEnabled)
startActivity(intent);
input.setEnabled(true);
stopService(service);
}
}

Expand All @@ -235,4 +262,34 @@ public boolean isNotificationListenersEnabled() {
}
return false;
}


private boolean isAccessibilitySettingsOn(Context mContext) {
int accessibilityEnabled;
final String service = getPackageName() + "/" + ForegroundMonitor.class.getCanonicalName();
try {
accessibilityEnabled = Settings.Secure.getInt(
mContext.getApplicationContext().getContentResolver(),
android.provider.Settings.Secure.ACCESSIBILITY_ENABLED);
} catch (Settings.SettingNotFoundException e) {
return false;
}
TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');

if (accessibilityEnabled == 1) {
String settingValue = Settings.Secure.getString(
mContext.getApplicationContext().getContentResolver(),
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
if (settingValue != null) {
mStringColonSplitter.setString(settingValue);
while (mStringColonSplitter.hasNext()) {
String accessibilityService = mStringColonSplitter.next();
if (accessibilityService.equalsIgnoreCase(service)) {
return true;
}
}
}
}
return false;
}
}
10 changes: 5 additions & 5 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:text="@string/start"
android:text="@string/hide"
android:textSize="18sp"
tools:checked="true" />

Expand All @@ -49,18 +49,18 @@
android:textIsSelectable="true" />

<Button
android:id="@+id/priority"
android:id="@+id/clear"
style="@style/Base.Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/priority" />
android:text="@string/clear" />

<Button
android:id="@+id/clear"
android:id="@+id/priority"
style="@style/Base.Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/clear" />
android:text="@string/priority" />

<Button
android:id="@+id/colors"
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/layout/app_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
android:id="@+id/imageView"
android:layout_width="25dp"
android:layout_height="25dp"
tools:srcCompat="@tools:sample/avatars"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"/>
android:layout_marginEnd="10dp"
tools:srcCompat="@tools:sample/avatars" />

<TextView
android:id="@+id/appName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/priority"
android:textColor="@color/black"
android:textSize="18sp"
android:text="@string/priority"/>
android:textSize="18sp" />

<Spinner
android:id="@+id/spinner"
Expand Down
12 changes: 7 additions & 5 deletions app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<resources>
<string name="app_name">NotificationPush</string>
<string name="app_name">fcm通知转发</string>
<string name="service_name">GetNotification</string>
<string name="access_name">ForegroundMonitor</string>
<string name="descript_access">应用前台时隐藏通知</string>
<string name="start">开始转发</string>
<string name="priority">通知优先级</string>
<string name="hide">前台应用隐藏通知</string>
<string name="DeviceID">设备ID</string>
<string name="wait">等待token中</string>
<array name="priorityContent">
<item>普通优先级</item>
<item>高优先级</item>
<item>关闭通知</item>
</array>
<string name="DeviceID">设备ID</string>
<string name="wait">等待token中</string>
<string name="clear">删除所有通知渠道</string>
<string name="priority">更改通知优先级</string>
<string name="colors">更换颜色</string>
<string name="about">关于</string>

<string name="HowToUse">
此应用可以通过fcm通道从一台手机向另一台手机转发通知\n如果显示fail,请检查Google框架并尝试翻墙重启应用\n你只需要将token(就是那堆乱码)复制到服务端的输入框,点击start即可开始推送\n注意优先级设定只在服务端生效\n服务端必须24小时翻墙
</string>
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<resources>
<string name="app_name">NotificationPush</string>
<string name="service_name">GetNotification</string>
<string name="access_name">ForegroundMonitor</string>
<string name="descript_access">Hide notification when app is foreground</string>
<string name="start">start</string>
<string name="priority">change priority</string>
<string name="hide">hide when foreground</string>
<string name="DeviceID">DeviceID</string>
<string name="wait">waiting for token</string>
<array name="priorityContent">
<item>Normal</item>
<item>High</item>
<item>off</item>
</array>
<string name="DeviceID">DeviceID</string>
<string name="wait">waiting for token</string>
<string name="clear">remove all channels</string>
<string name="priority">change priority</string>
<string name="colors">change color</string>
<string name="about">about</string>

<string name="HowToUse">
此应用可以通过fcm通道从一台手机向另一台手机转发通知\n如果显示fail,请检查Google框架并尝试翻墙重启应用\n你只需要将token(就是那堆乱码)复制到服务端的输入框,点击start即可开始推送\n注意优先级设定只在服务端生效\n服务端必须24小时翻墙
</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<style name="base" parent="Base.Theme.AppCompat.Light">
<item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:windowLightStatusBar" tools:targetApi="23">true</item>
<item name="android:windowLightNavigationBar">true</item>
<item name="android:navigationBarColor">@color/colorPrimaryDark</item>
</style>

<!-- Base application theme. -->
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/xml/accessibility.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes="typeWindowStateChanged"
android:accessibilityFeedbackType="feedbackGeneric"
android:canRetrieveWindowContent="false"
android:description="@string/descript_access"
android:notificationTimeout="100" />

0 comments on commit 14da0a8

Please sign in to comment.