修复时间戳复制按钮响应

This commit is contained in:
ZhanGSKen 2025-05-05 12:39:45 +08:00
parent d26de8f2f7
commit 2f2512cd76
3 changed files with 15 additions and 10 deletions

View File

@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle #Created by .winboll/winboll_app_build.gradle
#Mon May 05 03:50:53 GMT 2025 #Mon May 05 04:37:03 GMT 2025
stageCount=0 stageCount=0
libraryProject= libraryProject=
baseVersion=15.0 baseVersion=15.0
publishVersion=15.0.0 publishVersion=15.0.0
buildCount=24 buildCount=26
baseBetaVersion=15.0.1 baseBetaVersion=15.0.1

View File

@ -39,12 +39,6 @@
<service android:name=".AssistantService"/> <service android:name=".AssistantService"/>
<receiver android:name=".receivers.ButtonClickReceiver">
<intent-filter>
<action android:name="com.example.BUTTON_CLICK_ACTION" />
</intent-filter>
</receiver>
</application> </application>
</manifest> </manifest>

View File

@ -31,6 +31,7 @@ import java.time.ZoneId;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import android.content.IntentFilter;
public class MainService extends Service { public class MainService extends Service {
@ -38,6 +39,7 @@ public class MainService extends Service {
public static final int MSG_UPDATE_TIMESTAMP = 0; public static final int MSG_UPDATE_TIMESTAMP = 0;
ButtonClickReceiver mButtonClickReceiver;
Intent intentMainService; Intent intentMainService;
Intent mButtonBroadcastIntent; Intent mButtonBroadcastIntent;
PendingIntent mButtonPendingIntent; PendingIntent mButtonPendingIntent;
@ -73,6 +75,17 @@ public class MainService extends Service {
mButtonBroadcastIntent, // Intent mButtonBroadcastIntent, // Intent
PendingIntent.FLAG_UPDATE_CURRENT // 标志位用于更新已存在的 PendingIntent PendingIntent.FLAG_UPDATE_CURRENT // 标志位用于更新已存在的 PendingIntent
); );
// 为按钮设置点击事件
mRemoteViews.setOnClickPendingIntent(R.id.btn_copytimestamp, mButtonPendingIntent);
// 创建广播接收器实例
mButtonClickReceiver = new ButtonClickReceiver();
// 创建 IntentFilter 并设置要接收的广播动作
IntentFilter filter = new IntentFilter(ButtonClickReceiver.BUTTON_COPYTIMESTAMP_ACTION);
// 注册广播接收器
registerReceiver(mButtonClickReceiver, filter);
LogUtils.d(TAG, "onCreate()"); LogUtils.d(TAG, "onCreate()");
_mIsServiceAlive = false; _mIsServiceAlive = false;
@ -189,8 +202,6 @@ public class MainService extends Service {
String formattedDateTime = ldt.format(formatter); String formattedDateTime = ldt.format(formatter);
//System.out.println(formattedDateTime); //System.out.println(formattedDateTime);
mRemoteViews.setTextViewText(R.id.tv_timestamp, formattedDateTime); mRemoteViews.setTextViewText(R.id.tv_timestamp, formattedDateTime);
// 为按钮设置点击事件
mRemoteViews.setOnClickPendingIntent(R.id.btn_copytimestamp, mButtonPendingIntent);
notification = mNotificationHelper.showCustomForegroundNotification(intentMainService, mRemoteViews, mRemoteViews); notification = mNotificationHelper.showCustomForegroundNotification(intentMainService, mRemoteViews, mRemoteViews);
//startForeground(NotificationHelper.FOREGROUND_NOTIFICATION_ID, notification); //startForeground(NotificationHelper.FOREGROUND_NOTIFICATION_ID, notification);
} }