1153
This commit is contained in:
parent
2e9b6ae263
commit
d26de8f2f7
@ -1,8 +1,8 @@
|
|||||||
#Created by .winboll/winboll_app_build.gradle
|
#Created by .winboll/winboll_app_build.gradle
|
||||||
#Mon May 05 03:29:39 GMT 2025
|
#Mon May 05 03:50:53 GMT 2025
|
||||||
stageCount=0
|
stageCount=0
|
||||||
libraryProject=
|
libraryProject=
|
||||||
baseVersion=15.0
|
baseVersion=15.0
|
||||||
publishVersion=15.0.0
|
publishVersion=15.0.0
|
||||||
buildCount=15
|
buildCount=24
|
||||||
baseBetaVersion=15.0.1
|
baseBetaVersion=15.0.1
|
||||||
|
@ -39,6 +39,12 @@
|
|||||||
|
|
||||||
<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>
|
||||||
|
@ -6,6 +6,7 @@ package cc.winboll.studio.timestamp;
|
|||||||
* @Describe 主要服务
|
* @Describe 主要服务
|
||||||
*/
|
*/
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
|
import android.app.PendingIntent;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -20,6 +21,7 @@ import cc.winboll.studio.libappbase.LogUtils;
|
|||||||
import cc.winboll.studio.timestamp.AssistantService;
|
import cc.winboll.studio.timestamp.AssistantService;
|
||||||
import cc.winboll.studio.timestamp.MainService;
|
import cc.winboll.studio.timestamp.MainService;
|
||||||
import cc.winboll.studio.timestamp.models.AppConfigs;
|
import cc.winboll.studio.timestamp.models.AppConfigs;
|
||||||
|
import cc.winboll.studio.timestamp.receivers.ButtonClickReceiver;
|
||||||
import cc.winboll.studio.timestamp.utils.NotificationHelper;
|
import cc.winboll.studio.timestamp.utils.NotificationHelper;
|
||||||
import cc.winboll.studio.timestamp.utils.ServiceUtil;
|
import cc.winboll.studio.timestamp.utils.ServiceUtil;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
@ -37,6 +39,8 @@ public class MainService extends Service {
|
|||||||
public static final int MSG_UPDATE_TIMESTAMP = 0;
|
public static final int MSG_UPDATE_TIMESTAMP = 0;
|
||||||
|
|
||||||
Intent intentMainService;
|
Intent intentMainService;
|
||||||
|
Intent mButtonBroadcastIntent;
|
||||||
|
PendingIntent mButtonPendingIntent;
|
||||||
NotificationHelper mNotificationHelper;
|
NotificationHelper mNotificationHelper;
|
||||||
Notification notification;
|
Notification notification;
|
||||||
RemoteViews mRemoteViews;
|
RemoteViews mRemoteViews;
|
||||||
@ -61,6 +65,15 @@ public class MainService extends Service {
|
|||||||
mRemoteViews = new RemoteViews(getPackageName(), R.layout.remoteviews_timestamp);
|
mRemoteViews = new RemoteViews(getPackageName(), R.layout.remoteviews_timestamp);
|
||||||
intentMainService = new Intent(this, MainActivity.class);
|
intentMainService = new Intent(this, MainActivity.class);
|
||||||
|
|
||||||
|
// 创建点击按钮后要发送的广播 Intent
|
||||||
|
mButtonBroadcastIntent = new Intent(ButtonClickReceiver.BUTTON_COPYTIMESTAMP_ACTION);
|
||||||
|
mButtonPendingIntent = PendingIntent.getBroadcast(
|
||||||
|
this, // 上下文
|
||||||
|
0, // 请求码,用于区分不同的 PendingIntent
|
||||||
|
mButtonBroadcastIntent, // Intent
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT // 标志位,用于更新已存在的 PendingIntent
|
||||||
|
);
|
||||||
|
|
||||||
LogUtils.d(TAG, "onCreate()");
|
LogUtils.d(TAG, "onCreate()");
|
||||||
_mIsServiceAlive = false;
|
_mIsServiceAlive = false;
|
||||||
mMyHandler = new MyHandler(MainService.this);
|
mMyHandler = new MyHandler(MainService.this);
|
||||||
@ -176,6 +189,8 @@ 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);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
package cc.winboll.studio.timestamp.receivers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author ZhanGSKen
|
||||||
|
* @Date 2025/05/05 11:35
|
||||||
|
* @Describe ButtonClickReceiver
|
||||||
|
*/
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.widget.Toast;
|
||||||
|
import cc.winboll.studio.libappbase.LogUtils;
|
||||||
|
|
||||||
|
public class ButtonClickReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
|
public static final String TAG = "ButtonClickReceiver";
|
||||||
|
|
||||||
|
public static final String BUTTON_COPYTIMESTAMP_ACTION = "com.example.BUTTON_CLICK_ACTION";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
LogUtils.d(TAG, "onReceive");
|
||||||
|
//if (intent.getAction().equals(BUTTON_COPYTIMESTAMP_ACTION)) {
|
||||||
|
// 在这里编写按钮点击后要执行的代码
|
||||||
|
// 比如显示一个Toast
|
||||||
|
Toast.makeText(context, "按钮被点击了", Toast.LENGTH_SHORT).show();
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,15 +2,23 @@
|
|||||||
<LinearLayout
|
<LinearLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:orientation="vertical"
|
android:orientation="horizontal"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center_vertical">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Text"
|
android:text="Text"
|
||||||
android:id="@+id/tv_timestamp"/>
|
android:id="@+id/tv_timestamp"
|
||||||
|
android:layout_weight="1.0"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btn_copytimestamp"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="复制时间戳"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user