38 changed files with 253 additions and 1596 deletions
@ -1,201 +0,0 @@
@@ -1,201 +0,0 @@
|
||||
package com.kanglai.push.offline; |
||||
|
||||
import android.content.Intent; |
||||
import android.widget.RemoteViews; |
||||
|
||||
import com.blankj.utilcode.util.LogUtils; |
||||
import com.dolphin.core.util.NotificationUtil; |
||||
import com.huawei.hms.push.HmsMessageService; |
||||
import com.huawei.hms.push.RemoteMessage; |
||||
import com.huawei.hms.push.SendException; |
||||
|
||||
import java.util.Arrays; |
||||
|
||||
/** |
||||
* 华为离线服务 |
||||
* |
||||
* 仅用于接收透传消息、获取Token(可删除) |
||||
* @Author: liusixiang007 |
||||
* @since: 2023/7/24 |
||||
*/ |
||||
public class HuaWeiHmsMessageService extends HmsMessageService { |
||||
private static final String TAG = "HuaWeiHmsMessageServiceLog"; |
||||
private final static String CODELABS_ACTION = "com.dolphin.umeng.service.action"; |
||||
|
||||
@Override |
||||
public void onNewToken(String token) { |
||||
super.onNewToken(token); |
||||
LogUtils.d(TAG, "received refresh token:" + token); |
||||
if (token == null) { |
||||
// 这个方法回调必须在10秒内完成。否则,您需要启动一个新的Job进行回调处理。
|
||||
refreshedTokenToServer(token); |
||||
} |
||||
|
||||
LogUtils.d("huaweiseriver-onNewToken"); |
||||
Intent intent = new Intent(); |
||||
intent.setAction(CODELABS_ACTION); |
||||
intent.putExtra("method", "onNewToken"); |
||||
intent.putExtra("msg", "onNewToken called, token: " + token); |
||||
sendBroadcast(intent); // 进行广播通讯
|
||||
} |
||||
|
||||
private void refreshedTokenToServer(String token) { |
||||
LogUtils.i(TAG, "sending token to server. token:" + token); |
||||
} |
||||
|
||||
/** |
||||
* 接收服务端推送的透传消息 |
||||
* |
||||
* 该方法回调必须在10秒内完成。否则,需要启动一个新的Job进行回调处理。 |
||||
* @param message |
||||
*/ |
||||
@Override |
||||
public void onMessageReceived(RemoteMessage message) { |
||||
super.onMessageReceived(message); |
||||
|
||||
// 判断消息是否为空
|
||||
if (message == null) { |
||||
LogUtils.e(TAG, "接收的华为推送数据为空!"); |
||||
return; |
||||
} |
||||
// 透传的消息数据
|
||||
LogUtils.i(TAG, "get Data: " + message.getData() |
||||
+ "\n getFrom: " + message.getFrom() |
||||
+ "\n getTo: " + message.getTo() |
||||
+ "\n getMessageId: " + message.getMessageId() |
||||
+ "\n getSentTime: " + message.getSentTime() |
||||
+ "\n getDataMap: " + message.getDataOfMap() |
||||
+ "\n getMessageType: " + message.getMessageType() |
||||
+ "\n getTtl: " + message.getTtl() |
||||
+ "\n getToken: " + message.getToken()); |
||||
|
||||
// LogUtils.i(TAG, "getCollapseKey: " + message.getCollapseKey()
|
||||
// + "\n getData: " + message.getData()
|
||||
// + "\n getFrom: " + message.getFrom()
|
||||
// + "\n getTo: " + message.getTo()
|
||||
// + "\n getMessageId: " + message.getMessageId()
|
||||
// + "\n getMessageType: " + message.getMessageType()
|
||||
// + "\n getSendTime: " + message.getSentTime()
|
||||
// + "\n getTtl: " + message.getTtl()
|
||||
// + "\n getSendMode: " + message.getSendMode()
|
||||
// + "\n getReceiptMode: " + message.getReceiptMode()
|
||||
// + "\n getOriginalUrgency: " + message.getOriginalUrgency()
|
||||
// + "\n getUrgency: " + message.getUrgency()
|
||||
// + "\n getToken: " + message.getToken());
|
||||
// getBody()获取消息的显示内容
|
||||
// getTitle()获取消息的标题
|
||||
// getTitleLocalizationKey()获取通知消息显示标题的键。
|
||||
// getTitleLocalizationArgs()获取消息显示标题的可变参数
|
||||
// getBodyLocalizationkey()
|
||||
// 获取消息显示内容的密钥getBodyLocalizationArgs()
|
||||
// 获取消息显示内容的可变参数getIcon()
|
||||
// 从消息中获取图标getSound()
|
||||
// 从消息中获取声音getTag()
|
||||
// 从消息中获取用于消息覆盖的标记
|
||||
// getColor()获取消息中图标的颜色
|
||||
// getClickAction()获取由消息点击触发的操作
|
||||
// getChannelId()获取支持显示消息的通道的
|
||||
// idgetImageUr1()从消息中获取图像
|
||||
// URLgetLink()从消息获取要访问的URL
|
||||
// getNotifyId()获取消息的唯一ID
|
||||
|
||||
RemoteMessage.Notification notification = message.getNotification(); |
||||
if (notification != null) { |
||||
LogUtils.i(TAG, "\n getTitle: " + notification.getTitle() |
||||
+ "\n getTitleLocalizationKey: " + notification.getTitleLocalizationKey() |
||||
+ "\n getTitleLocalizationArgs: " + Arrays.toString(notification.getTitleLocalizationArgs()) |
||||
+ "\n getBody: " + notification.getBody() |
||||
+ "\n getBodyLocalizationKey: " + notification.getBodyLocalizationKey() |
||||
+ "\n getBodyLocalizationArgs: " + Arrays.toString(notification.getBodyLocalizationArgs()) |
||||
+ "\n getIcon: " + notification.getIcon() |
||||
+ "\n getImageUrl: " + notification.getImageUrl() |
||||
+ "\n getSound: " + notification.getSound() |
||||
+ "\n getTag: " + notification.getTag() |
||||
+ "\n getColor: " + notification.getColor() |
||||
+ "\n getClickAction: " + notification.getClickAction() |
||||
+ "\n getIntentUri: " + notification.getIntentUri() |
||||
+ "\n getChannelId: " + notification.getChannelId() |
||||
+ "\n getLink: " + notification.getLink() |
||||
+ "\n getNotifyId: " + notification.getNotifyId() |
||||
+ "\n isDefaultLight: " + notification.isDefaultLight() |
||||
+ "\n isDefaultSound: " + notification.isDefaultSound() |
||||
+ "\n isDefaultVibrate: " + notification.isDefaultVibrate() |
||||
+ "\n getWhen: " + notification.getWhen() |
||||
+ "\n getLightSettings: " + Arrays.toString(notification.getLightSettings()) |
||||
+ "\n isLocalOnly: " + notification.isLocalOnly() |
||||
+ "\n getBadgeNumber: " + notification.getBadgeNumber() |
||||
+ "\n isAutoCancel: " + notification.isAutoCancel() |
||||
+ "\n getImportance: " + notification.getImportance() |
||||
+ "\n getTicker: " + notification.getTicker() |
||||
+ "\n getVibrateConfig: " + Arrays.toString(notification.getVibrateConfig()) |
||||
+ "\n getVisibility: " + notification.getVisibility()); |
||||
} |
||||
|
||||
RemoteViews customNotificationView = new RemoteViews(getApplicationContext().getPackageName(), com.dolphin.umeng.R.layout.layout_notification_view); |
||||
customNotificationView.setTextViewText(com.dolphin.umeng.R.id.notification_title, notification.getTitle()); |
||||
customNotificationView.setTextViewText(com.dolphin.umeng.R.id.notification_text, notification.getBody()); |
||||
// customNotificationView.setImageViewBitmap(com.dolphin.umeng.R.id.notification_large_icon, getLargeIcon(context, msg));
|
||||
// customNotificationView.setImageViewResource(com.dolphin.umeng.R.id.notification_small_icon, getSmallIconId(context, msg));
|
||||
NotificationUtil.defaultNotificationBuilder().setCustomHeadsUpContentView(customNotificationView).build(); |
||||
|
||||
Intent intents = new Intent(); |
||||
intents.setAction(CODELABS_ACTION); |
||||
intents.putExtra("method", "onMessageReceived"); |
||||
intents.putExtra("msg", "onMessageReceived called, message id:" + message.getMessageId() + ", payload data:" + message.getData()); |
||||
|
||||
sendBroadcast(intents); |
||||
|
||||
Boolean judgeWhetherIn10s = false; |
||||
|
||||
// 如果10秒内没有处理完消息,应用程序需要使用WorkManager进行处理。
|
||||
if (judgeWhetherIn10s) { |
||||
startWorkManagerJob(message); |
||||
} else { |
||||
// 10秒内处理消息
|
||||
processWithin10s(message); |
||||
} |
||||
} |
||||
|
||||
private void processWithin10s(RemoteMessage message) { |
||||
LogUtils.d(TAG, "Processing now."); |
||||
} |
||||
|
||||
private void startWorkManagerJob(RemoteMessage message) { |
||||
LogUtils.d(TAG, "Start new Job processing."); |
||||
} |
||||
|
||||
@Override |
||||
public void onMessageSent(String msgId) { |
||||
LogUtils.i(TAG, "onMessageSent called, Message id:" + msgId); |
||||
super.onMessageSent(msgId); |
||||
LogUtils.d("huaweiseriver-onNewToken"); |
||||
Intent intent = new Intent(); |
||||
intent.setAction(CODELABS_ACTION); |
||||
intent.putExtra("method", "onMessageSent"); |
||||
intent.putExtra("msg", "onMessageSent called, Message id:" + msgId); |
||||
sendBroadcast(intent); |
||||
} |
||||
|
||||
@Override |
||||
public void onSendError(String s, Exception e) { |
||||
super.onSendError(s, e); |
||||
LogUtils.i(TAG, "onSendError called, message id:" + s + ", ErrCode:" |
||||
+ ((SendException) e).getErrorCode() + ", description:" + e.getMessage()); |
||||
|
||||
LogUtils.d("huaweiseriver-onNewToken"); |
||||
Intent intent = new Intent(); |
||||
intent.setAction(CODELABS_ACTION); |
||||
intent.putExtra("method", "onSendError"); |
||||
intent.putExtra("msg", "onSendError called, message id:" + s + ", ErrCode:" |
||||
+ ((SendException) e).getErrorCode() + ", description:" + e.getMessage()); |
||||
|
||||
sendBroadcast(intent); |
||||
} |
||||
|
||||
@Override |
||||
public void onTokenError(Exception e) { |
||||
super.onTokenError(e); |
||||
// 获取失败触发
|
||||
LogUtils.d("onTokenError:"+e); |
||||
} |
||||
} |
@ -1,31 +0,0 @@
@@ -1,31 +0,0 @@
|
||||
package com.kanglai.push.ui.activity; |
||||
|
||||
import android.os.Bundle; |
||||
import android.os.PersistableBundle; |
||||
|
||||
import androidx.annotation.Nullable; |
||||
import androidx.databinding.library.baseAdapters.BR; |
||||
|
||||
import com.dolphin.core.base.BaseActivity; |
||||
import com.kanglai.push.R; |
||||
import com.kanglai.push.databinding.ActivityAuroraBinding; |
||||
import com.kanglai.push.ui.vm.AuroraViewModel; |
||||
|
||||
public class AuroraActivity extends BaseActivity<ActivityAuroraBinding, AuroraViewModel> { |
||||
|
||||
|
||||
@Override |
||||
public int setContentView(Bundle savedInstanceState) { |
||||
return R.layout.activity_aurora; |
||||
} |
||||
|
||||
@Override |
||||
public int setVariableId() { |
||||
return BR.viewModel; |
||||
} |
||||
|
||||
@Override |
||||
public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) { |
||||
super.onCreate(savedInstanceState, persistentState); |
||||
} |
||||
} |
@ -1,72 +0,0 @@
@@ -1,72 +0,0 @@
|
||||
package com.kanglai.push.ui.activity; |
||||
|
||||
import android.app.Activity; |
||||
import android.content.Intent; |
||||
import android.os.Bundle; |
||||
import android.text.TextUtils; |
||||
import android.util.Log; |
||||
import android.widget.TextView; |
||||
|
||||
import com.kanglai.push.R; |
||||
import com.kanglai.push.constant.CommonConstant; |
||||
import com.umeng.message.UmengNotifyClick; |
||||
import com.umeng.message.entity.UMessage; |
||||
|
||||
/** |
||||
* 厂商通道配置启动的Activity |
||||
* 点击小米、vivo等厂商渠道的推送通知消息后跳转的activity |
||||
* |
||||
* 必须在AndroidManifest.xml中MfrMessageActivity2标签下配置: |
||||
* 1. 配置 android:exported="true" |
||||
* 2. 新增 intent-filter |
||||
* <intent-filter> |
||||
* <action android:name="android.intent.action.VIEW" /> |
||||
* <category android:name="android.intent.category.DEFAULT" /> |
||||
* <category android:name="android.intent.category.BROWSABLE" /> |
||||
* <data |
||||
* android:host="${applicationId}" |
||||
* android:path="/thirdpush" |
||||
* android:scheme="agoo" /> |
||||
* </intent-filter> |
||||
* |
||||
* @Author: liusixiang007 |
||||
* @since: 2023/7/31 |
||||
*/ |
||||
public class MfrMessageActivity |
||||
extends Activity { |
||||
private static final String TAG = "MfrMessageActivity"; |
||||
|
||||
private final UmengNotifyClick mNotificationClick = new UmengNotifyClick() { |
||||
@Override |
||||
public void onMessage(UMessage msg) { |
||||
final String body = msg.getRaw().toString(); |
||||
Log.d(TAG, "body: " + body); |
||||
if (!TextUtils.isEmpty(body)) { |
||||
runOnUiThread(new Runnable() { |
||||
@Override |
||||
public void run() { |
||||
((TextView) findViewById(R.id.tv_body)).setText(body); |
||||
Intent intent = new Intent(getApplicationContext(), LoginActivity.class); |
||||
intent.putExtra(CommonConstant.USER_LINK_TYPE, 1); |
||||
startActivity(intent); |
||||
} |
||||
}); |
||||
} |
||||
} |
||||
}; |
||||
|
||||
|
||||
@Override |
||||
protected void onCreate(Bundle bundle) { |
||||
super.onCreate(bundle); |
||||
setContentView(R.layout.mfr_message_layout); |
||||
mNotificationClick.onCreate(this, getIntent()); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected void onNewIntent(Intent intent) { |
||||
super.onNewIntent(intent); |
||||
mNotificationClick.onNewIntent(intent); |
||||
} |
||||
} |
@ -1,131 +0,0 @@
@@ -1,131 +0,0 @@
|
||||
package com.kanglai.push.ui.fragment; |
||||
|
||||
import android.content.BroadcastReceiver; |
||||
import android.content.Context; |
||||
import android.content.Intent; |
||||
import android.content.IntentFilter; |
||||
import android.os.Bundle; |
||||
import android.view.LayoutInflater; |
||||
import android.view.View; |
||||
import android.view.ViewGroup; |
||||
|
||||
import androidx.annotation.Nullable; |
||||
import androidx.core.content.ContextCompat; |
||||
import androidx.recyclerview.widget.LinearLayoutManager; |
||||
import androidx.recyclerview.widget.RecyclerView; |
||||
|
||||
import com.blankj.utilcode.util.CollectionUtils; |
||||
import com.blankj.utilcode.util.LogUtils; |
||||
import com.dolphin.core.base.BaseFragment; |
||||
import com.dolphin.core.constant.AppConstant; |
||||
import com.dolphin.core.service.AppKeepActive; |
||||
import com.dolphin.core.util.ToastUtil; |
||||
import com.dolphin.core.widget.DefaultItemDecoration; |
||||
import com.kanglai.push.BR; |
||||
import com.kanglai.push.R; |
||||
import com.kanglai.push.databinding.FragmentDemoBinding; |
||||
import com.kanglai.push.ui.activity.TabBarActivity; |
||||
import com.kanglai.push.ui.adapter.DemoRecyclerAdapter; |
||||
import com.kanglai.push.ui.vm.ToolbarViewModel; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
*<p> |
||||
* 应用后台持续活跃 |
||||
* 支持熄屏,app退入后台,保证后台任务不被杀死 |
||||
*</p> |
||||
* |
||||
* @Author: wangxiang4 |
||||
* @since: 2023/2/7 |
||||
*/ |
||||
public class DemoAppKeepActiveFragment extends BaseFragment<FragmentDemoBinding, ToolbarViewModel> implements DemoRecyclerAdapter.EventListener { |
||||
|
||||
private RecyclerView mRecyclerView; |
||||
private DemoRecyclerAdapter mAdapter; |
||||
private AppKeepActive appKeepActive; |
||||
/** 持续保持活跃任务广播 */ |
||||
private BroadcastReceiver backgroundKeepActiveTask; |
||||
|
||||
@Override |
||||
public int setContentView(LayoutInflater inflater, @Nullable ViewGroup parentContainer, @Nullable Bundle savedInstanceState) { |
||||
return R.layout.fragment_demo; |
||||
} |
||||
|
||||
@Override |
||||
public int setVariableId() { |
||||
return BR.viewModel; |
||||
} |
||||
|
||||
@Override |
||||
public void onCreate(Bundle savedInstanceState) { |
||||
super.onCreate(savedInstanceState); |
||||
appKeepActive = new AppKeepActive(TabBarActivity.class); |
||||
} |
||||
|
||||
@Override |
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { |
||||
super.onViewCreated(view, savedInstanceState); |
||||
mViewModel.setTitleText("应用后台持续活跃"); |
||||
mRecyclerView = getView().findViewById(R.id.demo_recycler_view); |
||||
List<DemoRecyclerAdapter.Entity> list = CollectionUtils.newArrayList( |
||||
new DemoRecyclerAdapter.Entity().setCode("1").setTitle("启动后台免杀持续活跃"), |
||||
new DemoRecyclerAdapter.Entity().setCode("2").setTitle("停止后台免杀持续活跃") |
||||
); |
||||
final DemoRecyclerAdapter demoRecyclerAdapter = new DemoRecyclerAdapter(list); |
||||
demoRecyclerAdapter.setEventListener(this); |
||||
mAdapter = demoRecyclerAdapter; |
||||
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity()); |
||||
mRecyclerView.setLayoutManager(mLayoutManager); |
||||
mRecyclerView.addItemDecoration(new DefaultItemDecoration(ContextCompat.getColor(requireContext(), R.color.common_divider_color))); |
||||
mRecyclerView.setAdapter(mAdapter); |
||||
} |
||||
|
||||
@Override |
||||
public void onItemViewClicked(DemoRecyclerAdapter.Entity entity) { |
||||
switch (entity.code) { |
||||
case "1": |
||||
registerReceiver(); |
||||
appKeepActive.registerService(); |
||||
ToastUtil.showCenter("启动成功"); |
||||
break; |
||||
case "2": |
||||
unregisterReceiver(); |
||||
appKeepActive.unregisterService(); |
||||
ToastUtil.showCenter("停止成功"); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
public void registerReceiver () { |
||||
if (null == backgroundKeepActiveTask) { |
||||
backgroundKeepActiveTask = new BroadcastReceiver() { |
||||
@Override |
||||
public void onReceive(Context context, Intent intent) { |
||||
if (intent.getAction().equals(AppConstant.BACKGROUND_KEEP_ACTIVE_TASK_SCHEDULING)) { |
||||
ToastUtil.show("APP进入后台执行任务逻辑!"); |
||||
LogUtils.i("APP进入后台执行任务逻辑!"); |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
IntentFilter filter = new IntentFilter(); |
||||
filter.addAction(AppConstant.BACKGROUND_KEEP_ACTIVE_TASK_SCHEDULING); |
||||
getActivity().registerReceiver(backgroundKeepActiveTask, filter); |
||||
} |
||||
|
||||
public void unregisterReceiver() { |
||||
if (null != backgroundKeepActiveTask) getActivity().unregisterReceiver(backgroundKeepActiveTask); |
||||
} |
||||
|
||||
@Override |
||||
public void onStart() { |
||||
super.onStart(); |
||||
} |
||||
|
||||
@Override |
||||
public void onDestroy() { |
||||
super.onDestroy(); |
||||
} |
||||
|
||||
} |
@ -1,21 +0,0 @@
@@ -1,21 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:binding="http://schemas.android.com/apk/res-auto"> |
||||
<data> |
||||
<variable name="viewModel" type="com.kanglai.push.ui.vm.AuroraViewModel" /> |
||||
</data> |
||||
|
||||
<LinearLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:background="#F5F5F5" |
||||
android:orientation="vertical"> |
||||
|
||||
<include |
||||
android:id="@+id/include" |
||||
layout="@layout/layout_toolbar" |
||||
binding:toolbarViewModel="@{viewModel.toolbarViewModel}" /> |
||||
|
||||
|
||||
</LinearLayout> |
||||
</layout> |
@ -1,25 +0,0 @@
@@ -1,25 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:binding="http://schemas.android.com/apk/res-auto"> |
||||
<LinearLayout |
||||
android:orientation="vertical" |
||||
android:gravity="center" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent"> |
||||
<TextView |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_centerHorizontal="true" |
||||
android:text="当前是离线推送收到的消息" |
||||
android:textColor="#000000" |
||||
android:textSize="14sp" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/tv_body" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_centerHorizontal="true" |
||||
android:textColor="#000000" |
||||
android:textSize="15sp" /> |
||||
</LinearLayout> |
||||
</layout> |
@ -1,119 +0,0 @@
@@ -1,119 +0,0 @@
|
||||
package com.dolphin.core.entity; |
||||
|
||||
import android.os.Parcel; |
||||
import android.os.Parcelable; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
import lombok.Data; |
||||
import lombok.experimental.Accessors; |
||||
|
||||
/** |
||||
*<p> |
||||
* 扩展安全框架用户信息 |
||||
*</p> |
||||
* |
||||
* @Author: entfrm开发团队-王翔 |
||||
* @Date: 2022/6/28 |
||||
*/ |
||||
@Data |
||||
@Accessors |
||||
public class DolphinUser implements Parcelable { |
||||
|
||||
/** 用户id */ |
||||
private String id; |
||||
|
||||
/** 用户名称 */ |
||||
private String username; |
||||
|
||||
/** 用户密码 */ |
||||
private String password; |
||||
|
||||
/** 部门ID */ |
||||
private String deptId; |
||||
|
||||
/** 用户手机号 */ |
||||
private String phone; |
||||
|
||||
/** 账户是否被冻结 */ |
||||
private Boolean enabled; |
||||
|
||||
/** 多租户ID */ |
||||
private String tenantId; |
||||
|
||||
/** 用户按钮权限 */ |
||||
private List<Map<String, String>> authorities; |
||||
|
||||
/** 帐户未锁定 */ |
||||
private Boolean accountNonLocked; |
||||
|
||||
/** 帐户未过期 */ |
||||
private Boolean accountNonExpired; |
||||
|
||||
/** 凭证未过期 */ |
||||
private Boolean credentialsNonExpired; |
||||
|
||||
public DolphinUser() { |
||||
} |
||||
|
||||
/** 内存反序列化对象 */ |
||||
protected DolphinUser(Parcel in) { |
||||
id = in.readString(); |
||||
username = in.readString(); |
||||
password = in.readString(); |
||||
deptId = in.readString(); |
||||
phone = in.readString(); |
||||
enabled = in.readBoolean(); |
||||
tenantId = in.readString(); |
||||
authorities = in.readArrayList(Map.class.getClassLoader()); |
||||
accountNonLocked = in.readBoolean(); |
||||
accountNonExpired = in.readBoolean(); |
||||
credentialsNonExpired = in.readBoolean(); |
||||
} |
||||
|
||||
/** |
||||
* 内存序列化对象 |
||||
* @param dest 序列化对象 (包含序列化的一些操作) |
||||
* @param flags 0或1 (1表示当前对象需要作为返回值返回,不能立即释放资源,几乎所有情况都为0) |
||||
* @return void |
||||
*/ |
||||
@Override |
||||
public void writeToParcel(Parcel dest, int flags) { |
||||
dest.writeString(id); |
||||
dest.writeString(username); |
||||
dest.writeString(password); |
||||
dest.writeString(deptId); |
||||
dest.writeString(phone); |
||||
dest.writeBoolean(enabled); |
||||
dest.writeString(tenantId); |
||||
dest.writeList(authorities); |
||||
dest.writeBoolean(accountNonLocked); |
||||
dest.writeBoolean(accountNonExpired); |
||||
dest.writeBoolean(credentialsNonExpired); |
||||
} |
||||
|
||||
/** |
||||
* unix系统文件描述符,一般情况下为0就行 |
||||
* 0:标准输入文件stdin |
||||
* 1:标准输出文件stdout |
||||
* 2:标准错误输出文件stderr |
||||
*/ |
||||
@Override |
||||
public int describeContents() { |
||||
return 0; |
||||
} |
||||
|
||||
public static final Creator<DolphinUser> CREATOR = new Creator() { |
||||
@Override |
||||
public DolphinUser createFromParcel(Parcel in) { |
||||
return new DolphinUser(in); |
||||
} |
||||
|
||||
@Override |
||||
public DolphinUser[] newArray(int size) { |
||||
return new DolphinUser[size]; |
||||
} |
||||
}; |
||||
|
||||
} |
@ -1,174 +0,0 @@
@@ -1,174 +0,0 @@
|
||||
package com.dolphin.core.service; |
||||
|
||||
import android.app.AlarmManager; |
||||
import android.app.Notification; |
||||
import android.app.NotificationChannel; |
||||
import android.app.NotificationManager; |
||||
import android.app.PendingIntent; |
||||
import android.content.BroadcastReceiver; |
||||
import android.content.Context; |
||||
import android.content.Intent; |
||||
import android.content.IntentFilter; |
||||
import android.graphics.BitmapFactory; |
||||
import android.os.PowerManager; |
||||
import android.os.SystemClock; |
||||
|
||||
import com.blankj.utilcode.util.Utils; |
||||
import com.dolphin.core.R; |
||||
import com.dolphin.core.constant.AppConstant; |
||||
import com.dolphin.core.util.NotificationUtil; |
||||
|
||||
/** |
||||
*<p> |
||||
* 应用保持活跃 |
||||
*</p> |
||||
* |
||||
* @Author: wangxiang4 |
||||
* @since: 2023/2/6 |
||||
*/ |
||||
public class AppKeepActive { |
||||
|
||||
/** 活动上下文 */ |
||||
private Context mContext; |
||||
|
||||
/** 前台服务通知 */ |
||||
public static volatile Notification notification; |
||||
|
||||
/** 保持后台活跃服务意图 */ |
||||
private Intent backgroundKeepActiveFrontServiceIntent; |
||||
|
||||
/** 系统警报提醒服务 */ |
||||
private AlarmManager alarmManager; |
||||
|
||||
/** 警报待定异步意图 */ |
||||
private PendingIntent alarmPendingIntent; |
||||
|
||||
/** 屏幕唤醒锁定屏幕接收 */ |
||||
private BroadcastReceiver wakeLockScreenReceiver; |
||||
|
||||
/** 判断屏幕唤醒锁定屏幕接收是否注册 */ |
||||
private Boolean isRegisterPowerWakeLockReceiver = false; |
||||
|
||||
/** 手机电源管理 */ |
||||
private PowerManager powerManager; |
||||
|
||||
/** 屏幕唤醒 */ |
||||
private PowerManager.WakeLock wakeLock; |
||||
|
||||
/** 前台服务通知点击启动活动 */ |
||||
private Class<?> notificationClickStartClass; |
||||
|
||||
public AppKeepActive(Class<?> notificationClickStartClass) { |
||||
this(Utils.getApp(), notificationClickStartClass); |
||||
} |
||||
|
||||
public AppKeepActive(Context mContext, Class<?> notificationClickStartClass) { |
||||
this.mContext = mContext; |
||||
this.notificationClickStartClass = notificationClickStartClass; |
||||
powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); |
||||
notification = buildNotification(); |
||||
} |
||||
|
||||
/** 注册电源锁屏监听广播 */ |
||||
public void registerPowerWakeLockReceiver() { |
||||
if (isRegisterPowerWakeLockReceiver) return; |
||||
isRegisterPowerWakeLockReceiver = true; |
||||
if (null == wakeLock) wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "dolphin:keep-active"); |
||||
if (null == wakeLockScreenReceiver) { |
||||
wakeLockScreenReceiver = new BroadcastReceiver() { |
||||
@Override |
||||
public void onReceive(Context context, Intent intent) { |
||||
if (null == wakeLock) return; |
||||
String action = intent.getAction(); |
||||
if (Intent.ACTION_SCREEN_OFF.equals(action) && !wakeLock.isHeld()) { |
||||
wakeLock.acquire(); |
||||
if (null != alarmPendingIntent) return; |
||||
// 支持后台熄屏,定时执行后台持续活跃任务
|
||||
Intent alarmIntent = new Intent(); |
||||
alarmIntent.setAction(AppConstant.BACKGROUND_KEEP_ACTIVE_TASK_SCHEDULING); |
||||
// https://www.cnblogs.com/endv/p/11576121.html
|
||||
alarmPendingIntent = PendingIntent.getBroadcast(mContext, AppConstant.PERMISSION_REQUEST_CODE, alarmIntent, PendingIntent.FLAG_IMMUTABLE); |
||||
// 获取系统警报提醒服务
|
||||
alarmManager = (AlarmManager) mContext.getSystemService(mContext.ALARM_SERVICE); |
||||
// 设置一个闹钟,1秒之后每隔一段时间执行启动一次后台持续活跃任务,防止冻结后台任务
|
||||
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 1 * 1000, AppConstant.KEEP_ACTIVE_TASK_INTERVAL_TIME, alarmPendingIntent); |
||||
} else if (Intent.ACTION_USER_PRESENT.equals(action) && wakeLock.isHeld()) { |
||||
wakeLock.release(); |
||||
if (null == alarmManager) return; |
||||
alarmManager.cancel(alarmPendingIntent); |
||||
alarmPendingIntent = null; |
||||
alarmManager = null; |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
IntentFilter filter = new IntentFilter(); |
||||
filter.addAction(Intent.ACTION_SCREEN_OFF); |
||||
filter.addAction(Intent.ACTION_USER_PRESENT); |
||||
mContext.registerReceiver(wakeLockScreenReceiver, filter); |
||||
} |
||||
|
||||
/** 取消电源锁屏监听广播 */ |
||||
public void unregisterPowerWakeLockReceiver() { |
||||
if (!isRegisterPowerWakeLockReceiver) return; |
||||
if (null != wakeLockScreenReceiver) mContext.unregisterReceiver(wakeLockScreenReceiver); |
||||
isRegisterPowerWakeLockReceiver = false; |
||||
} |
||||
|
||||
/** 启动后台活跃前台服务 */ |
||||
public void startBackgroundKeepActiveFrontService() { |
||||
BackgroundKeepActiveFrontService.startBackgroundKeepActiveTask = true; |
||||
backgroundKeepActiveFrontServiceIntent = new Intent(mContext, BackgroundKeepActiveFrontService.class); |
||||
mContext.startForegroundService(backgroundKeepActiveFrontServiceIntent); |
||||
} |
||||
|
||||
/** 关闭后台活跃前台服务 */ |
||||
public void closeBackgroundKeepActiveFrontService() { |
||||
BackgroundKeepActiveFrontService.startBackgroundKeepActiveTask = false; |
||||
if (null != backgroundKeepActiveFrontServiceIntent) mContext.stopService(backgroundKeepActiveFrontServiceIntent); |
||||
} |
||||
|
||||
/** 注册应用保持活跃服务 */ |
||||
public void registerService() { |
||||
startBackgroundKeepActiveFrontService(); |
||||
registerPowerWakeLockReceiver(); |
||||
} |
||||
|
||||
/** 解绑应用保持活跃服务 */ |
||||
public void unregisterService() { |
||||
closeBackgroundKeepActiveFrontService(); |
||||
unregisterPowerWakeLockReceiver(); |
||||
} |
||||
|
||||
/** 构建前台服务通知 */ |
||||
private Notification buildNotification() { |
||||
NotificationUtil.notificationManager.createNotificationChannel(NotificationUtil.defaultNotificationChannel()); |
||||
PendingIntent pendingIntent = PendingIntent.getActivity(mContext, AppConstant.PERMISSION_REQUEST_CODE, new Intent(mContext, notificationClickStartClass), PendingIntent.FLAG_MUTABLE); |
||||
Notification notification = NotificationUtil.defaultNotificationBuilder() |
||||
.setContentTitle(mContext.getString(R.string.app_name)) |
||||
.setContentText("正在后台运行") |
||||
.setOngoing(true) |
||||
.setOnlyAlertOnce(true) |
||||
.setContentIntent(pendingIntent).build(); |
||||
// 通知栏以不能清除的方式展示
|
||||
notification.flags |= Notification.FLAG_NO_CLEAR; |
||||
return notification; |
||||
} |
||||
|
||||
public PowerManager getPowerManager() { |
||||
return powerManager; |
||||
} |
||||
|
||||
public void setPowerManager(PowerManager powerManager) { |
||||
this.powerManager = powerManager; |
||||
} |
||||
|
||||
public PowerManager.WakeLock getWakeLock() { |
||||
return wakeLock; |
||||
} |
||||
|
||||
public void setWakeLock(PowerManager.WakeLock wakeLock) { |
||||
this.wakeLock = wakeLock; |
||||
} |
||||
|
||||
} |
@ -1,99 +0,0 @@
@@ -1,99 +0,0 @@
|
||||
package com.dolphin.core.service; |
||||
|
||||
import android.app.ActivityManager; |
||||
import android.app.Service; |
||||
import android.content.Context; |
||||
import android.content.Intent; |
||||
import android.media.MediaPlayer; |
||||
import android.os.IBinder; |
||||
import android.os.PowerManager; |
||||
|
||||
import com.blankj.utilcode.util.ThreadUtils; |
||||
import com.blankj.utilcode.util.Utils; |
||||
import com.dolphin.core.R; |
||||
import com.dolphin.core.constant.AppConstant; |
||||
|
||||
import java.util.List; |
||||
import java.util.concurrent.TimeUnit; |
||||
|
||||
/** |
||||
*<p> |
||||
* 前台服务 |
||||
* 采用媒体锁持续保持后台活跃 |
||||
* https://developer.android.com/guide/components/services?hl=zh-cn
|
||||
*</p> |
||||
* |
||||
* @Author: wangxiang4 |
||||
* @since: 2023/2/6 |
||||
*/ |
||||
public class BackgroundKeepActiveFrontService extends Service { |
||||
|
||||
/** 流媒体播放器 */ |
||||
private MediaPlayer mediaPlayer; |
||||
|
||||
/** 启动服务异步处理任务 */ |
||||
public static volatile Boolean startBackgroundKeepActiveTask = false; |
||||
|
||||
/** 判断APP当前是否处于后台运行 */ |
||||
private boolean isAppBackstage() { |
||||
ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); |
||||
List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses(); |
||||
for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) { |
||||
if (appProcess.processName.equals(getPackageName())) { |
||||
if (appProcess.importance != ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { |
||||
return true; |
||||
} else { |
||||
return false; |
||||
} |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
@Override |
||||
public void onCreate() { |
||||
super.onCreate(); |
||||
mediaPlayer = MediaPlayer.create(this, R.raw.media_lock); |
||||
// 禁止播放程序进入休眠,熄灭屏幕后唤醒cpu
|
||||
mediaPlayer.setWakeMode(this, PowerManager.PARTIAL_WAKE_LOCK); |
||||
mediaPlayer.setLooping(true); |
||||
} |
||||
|
||||
@Override |
||||
public int onStartCommand(Intent intent, int flags, int startId) { |
||||
if (mediaPlayer != null) mediaPlayer.start(); |
||||
ThreadUtils.executeByFixedAtFixRate(AppConstant.DEFAULT_THREAD_POOL_SIZE, |
||||
backgroundKeepActiveTask, AppConstant.KEEP_ACTIVE_TASK_INTERVAL_TIME, TimeUnit.MILLISECONDS); |
||||
return super.onStartCommand(intent, flags, startId); |
||||
} |
||||
|
||||
/** 后台异步处理持续活跃任务 */ |
||||
ThreadUtils.Task<String> backgroundKeepActiveTask = new Utils.Task(result -> {}) { |
||||
@Override |
||||
public String doInBackground() { |
||||
// 设置线程取消
|
||||
if (!startBackgroundKeepActiveTask) cancel(); |
||||
if(isAppBackstage()){ |
||||
Intent intent = new Intent(); |
||||
intent.setAction(AppConstant.BACKGROUND_KEEP_ACTIVE_TASK_SCHEDULING); |
||||
sendBroadcast(intent); |
||||
} |
||||
startForeground(AppConstant.KEEP_ACTIVE_FRONT_SERVICE_NOTIFICATION_ID, AppKeepActive.notification); |
||||
return null; |
||||
} |
||||
}; |
||||
|
||||
@Override |
||||
public void onDestroy() { |
||||
super.onDestroy(); |
||||
mediaPlayer.stop(); |
||||
mediaPlayer.release(); |
||||
stopForeground(true); |
||||
} |
||||
|
||||
@Override |
||||
public IBinder onBind(Intent intent) { |
||||
return null; |
||||
} |
||||
|
||||
} |
Binary file not shown.
@ -1,50 +0,0 @@
@@ -1,50 +0,0 @@
|
||||
package com.dolphin.umeng.entity; |
||||
|
||||
import android.os.Parcel; |
||||
import android.os.Parcelable; |
||||
|
||||
import lombok.Data; |
||||
import lombok.experimental.Accessors; |
||||
|
||||
/** |
||||
* 用户实时聊天数据 |
||||
* @Author: liusixiang007 |
||||
* @since: 2023/6/1 |
||||
*/ |
||||
@Data |
||||
@Accessors |
||||
public class ChatMsg implements Parcelable { |
||||
public String concernFanId; |
||||
public String content; |
||||
|
||||
public ChatMsg() {} |
||||
public ChatMsg(String userId,String content){ |
||||
this.concernFanId = userId; |
||||
this.content = content; |
||||
} |
||||
protected ChatMsg(Parcel in) { |
||||
concernFanId = in.readString(); |
||||
} |
||||
|
||||
public static final Creator<ChatMsg> CREATOR = new Creator<ChatMsg>() { |
||||
@Override |
||||
public ChatMsg createFromParcel(Parcel in) { |
||||
return new ChatMsg(in); |
||||
} |
||||
|
||||
@Override |
||||
public ChatMsg[] newArray(int size) { |
||||
return new ChatMsg[size]; |
||||
} |
||||
}; |
||||
|
||||
@Override |
||||
public int describeContents() { |
||||
return 0; |
||||
} |
||||
|
||||
@Override |
||||
public void writeToParcel(Parcel parcel, int i) { |
||||
parcel.writeString(concernFanId); |
||||
} |
||||
} |
@ -1,81 +0,0 @@
@@ -1,81 +0,0 @@
|
||||
package com.dolphin.umeng.entity; |
||||
|
||||
import android.os.Parcel; |
||||
import android.os.Parcelable; |
||||
|
||||
import com.kongzue.dialogx.dialogs.BottomDialog; |
||||
|
||||
import lombok.Data; |
||||
import lombok.experimental.Accessors; |
||||
|
||||
/** |
||||
* 友盟数据传输类 |
||||
* 仅传输接收到的有用的数据 |
||||
* @Author: liusixiang007 |
||||
* @since: 2023/7/6 |
||||
*/ |
||||
@Data |
||||
@Accessors |
||||
public class CustomMsg implements Parcelable{ |
||||
|
||||
/**粉丝用户id*/ |
||||
private String fanUserId; |
||||
/**文字转语音*/ |
||||
private String playToText; |
||||
/**收到通知是否发出声音*/ |
||||
private String playSound; |
||||
/**收到通知是否闪灯*/ |
||||
private String playLights; |
||||
/**收到通知是否震动*/ |
||||
private String playVibrate; |
||||
/**离线铃声*/ |
||||
private String offlineRingtone; |
||||
/**在线铃声*/ |
||||
private String onlineRingtone; |
||||
/**通知标题*/ |
||||
private String title; |
||||
/**通知文字描述*/ |
||||
private String text; |
||||
|
||||
public CustomMsg(Parcel in) { |
||||
title = in.readString(); |
||||
text = in.readString(); |
||||
playVibrate = in.readString(); |
||||
playLights = in.readString(); |
||||
playSound = in.readString(); |
||||
playToText = in.readString(); |
||||
onlineRingtone = in.readString(); |
||||
offlineRingtone = in.readString(); |
||||
fanUserId = in.readString(); |
||||
} |
||||
|
||||
public static final Creator<CustomMsg> CREATOR = new Creator<CustomMsg>() { |
||||
@Override |
||||
public CustomMsg createFromParcel(Parcel in) { |
||||
return new CustomMsg(in); |
||||
} |
||||
|
||||
@Override |
||||
public CustomMsg[] newArray(int size) { |
||||
return new CustomMsg[size]; |
||||
} |
||||
}; |
||||
|
||||
@Override |
||||
public int describeContents() { |
||||
return 0; |
||||
} |
||||
|
||||
@Override |
||||
public void writeToParcel(Parcel parcel, int i) { |
||||
parcel.writeString(title); |
||||
parcel.writeString(text); |
||||
parcel.writeString(playVibrate); |
||||
parcel.writeString(playLights); |
||||
parcel.writeString(playSound); |
||||
parcel.writeString(playToText); |
||||
parcel.writeString(onlineRingtone); |
||||
parcel.writeString(offlineRingtone); |
||||
parcel.writeString(fanUserId); |
||||
} |
||||
} |
@ -1,56 +0,0 @@
@@ -1,56 +0,0 @@
|
||||
package com.dolphin.umeng.entity; |
||||
|
||||
import android.os.Parcel; |
||||
import android.os.Parcelable; |
||||
|
||||
import lombok.Data; |
||||
import lombok.experimental.Accessors; |
||||
|
||||
/** |
||||
*<p> |
||||
* 演示 |
||||
* 自定义消息传输数据 |
||||
*</p> |
||||
* |
||||
* @Author: wangxiang4 |
||||
* @since: 2023/2/12 |
||||
*/ |
||||
@Data |
||||
@Accessors |
||||
public class CustomMsgDemo implements Parcelable { |
||||
|
||||
protected String title; |
||||
|
||||
protected String data; |
||||
|
||||
public CustomMsgDemo() {} |
||||
|
||||
public CustomMsgDemo(Parcel in) { |
||||
title = in.readString(); |
||||
data = in.readString(); |
||||
} |
||||
|
||||
@Override |
||||
public void writeToParcel(Parcel dest, int flags) { |
||||
dest.writeString(title); |
||||
dest.writeString(data); |
||||
} |
||||
|
||||
@Override |
||||
public int describeContents() { |
||||
return 0; |
||||
} |
||||
|
||||
public static final Creator<CustomMsgDemo> CREATOR = new Creator() { |
||||
@Override |
||||
public CustomMsgDemo createFromParcel(Parcel in) { |
||||
return new CustomMsgDemo(in); |
||||
} |
||||
|
||||
@Override |
||||
public CustomMsgDemo[] newArray(int size) { |
||||
return new CustomMsgDemo[size]; |
||||
} |
||||
}; |
||||
|
||||
} |
@ -0,0 +1,65 @@
@@ -0,0 +1,65 @@
|
||||
package com.dolphin.umeng.entity; |
||||
|
||||
import android.os.Parcel; |
||||
import android.os.Parcelable; |
||||
|
||||
import lombok.Data; |
||||
import lombok.experimental.Accessors; |
||||
|
||||
@Data |
||||
@Accessors |
||||
public class PushChatMessage implements Parcelable{ |
||||
|
||||
private String fanUserId; |
||||
private String offlineRingtone; |
||||
private String onlineRingtone; |
||||
private Boolean playToText; |
||||
private Boolean playSound; |
||||
private Boolean playLights; |
||||
private Boolean playVibrate; |
||||
private String type; |
||||
private String title; |
||||
private String text; |
||||
|
||||
public PushChatMessage(Parcel in) { |
||||
title = in.readString(); |
||||
text = in.readString(); |
||||
playVibrate = in.readBoolean(); |
||||
playLights = in.readBoolean(); |
||||
playSound = in.readBoolean(); |
||||
playToText = in.readBoolean(); |
||||
onlineRingtone = in.readString(); |
||||
offlineRingtone = in.readString(); |
||||
fanUserId = in.readString(); |
||||
} |
||||
|
||||
public static final Creator<PushChatMessage> CREATOR = new Creator<PushChatMessage>() { |
||||
@Override |
||||
public PushChatMessage createFromParcel(Parcel in) { |
||||
return new PushChatMessage(in); |
||||
} |
||||
|
||||
@Override |
||||
public PushChatMessage[] newArray(int size) { |
||||
return new PushChatMessage[size]; |
||||
} |
||||
}; |
||||
|
||||
@Override |
||||
public int describeContents() { |
||||
return 0; |
||||
} |
||||
|
||||
@Override |
||||
public void writeToParcel(Parcel parcel, int i) { |
||||
parcel.writeString(title); |
||||
parcel.writeString(text); |
||||
parcel.writeBoolean(playVibrate); |
||||
parcel.writeBoolean(playLights); |
||||
parcel.writeBoolean(playSound); |
||||
parcel.writeBoolean(playToText); |
||||
parcel.writeString(onlineRingtone); |
||||
parcel.writeString(offlineRingtone); |
||||
parcel.writeString(fanUserId); |
||||
} |
||||
} |
@ -0,0 +1,92 @@
@@ -0,0 +1,92 @@
|
||||
package com.dolphin.umeng.util; |
||||
|
||||
import android.content.Context; |
||||
|
||||
import com.baidu.tts.client.SpeechError; |
||||
import com.baidu.tts.client.SpeechSynthesizer; |
||||
import com.baidu.tts.client.SpeechSynthesizerListener; |
||||
import com.baidu.tts.client.TtsMode; |
||||
import com.blankj.utilcode.util.LogUtils; |
||||
import com.blankj.utilcode.util.Utils; |
||||
|
||||
import lombok.experimental.UtilityClass; |
||||
|
||||
@UtilityClass |
||||
public class BaiduTtsUtil { |
||||
private volatile boolean isInitTts; |
||||
private SpeechSynthesizer mSpeechSynthesizer; |
||||
private static final String BD_APP_ID = "37122313"; |
||||
private static final String BD_APP_KEY = "BNrZhvnx5DgX74j847KKrjzn"; |
||||
private static final String BD_APP_SECRET_KEY = "bF33QKfD1grBbO1R0Ur1L0A65wGkj3GR"; |
||||
|
||||
static { |
||||
mSpeechSynthesizer = SpeechSynthesizer.getInstance(); |
||||
mSpeechSynthesizer.setContext(Utils.getApp().getApplicationContext()); |
||||
mSpeechSynthesizer.setSpeechSynthesizerListener(new SpeechSynthesizerListener() { |
||||
@Override |
||||
public void onSynthesizeStart(String s) { |
||||
LogUtils.d("准备开始合成,序列号:" + s); |
||||
} |
||||
|
||||
@Override |
||||
public void onSynthesizeDataArrived(String s, byte[] bytes, int i, int i1) {} |
||||
|
||||
@Override |
||||
public void onSynthesizeFinish(String s) { |
||||
LogUtils.d("合成结束回调, 序列号:" + s); |
||||
} |
||||
|
||||
@Override |
||||
public void onSpeechStart(String s) { // 开始播放 暂时提高媒体音量
|
||||
LogUtils.d("播放开始回调, 序列号:" + s); |
||||
} |
||||
|
||||
@Override |
||||
public void onSpeechProgressChanged(String s, int i) { |
||||
LogUtils.d("播放进度回调, progress:" + s + ";序列号:" + i); |
||||
} |
||||
|
||||
@Override |
||||
public void onSpeechFinish(String s) { // 播放结束之后恢复媒体音量
|
||||
LogUtils.d("SpeechSynthesizerListener-onSpeechFinish 播报结束"); |
||||
release(); // 播放结束之后就清除占用
|
||||
} |
||||
|
||||
@Override |
||||
public void onError(String s, SpeechError speechError) { |
||||
mSpeechSynthesizer.pause(); |
||||
LogUtils.d("语音合成报错 错误id"+s+" 报错原因 "+speechError); |
||||
} |
||||
}); |
||||
mSpeechSynthesizer.setAppId(BD_APP_ID); |
||||
mSpeechSynthesizer.setApiKey(BD_APP_KEY , BD_APP_SECRET_KEY); |
||||
// 设置在线发声音人: 0 普通女声(默认) 1 普通男声 2 特别男声 3 情感男声<度逍遥> 4 情感儿童声<度丫丫>
|
||||
mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_SPEAKER, "0"); |
||||
// 设置合成的音量,0-15 ,默认 5
|
||||
mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_VOLUME, "15"); |
||||
// 设置合成的语速,0-15 ,默认 5
|
||||
mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_SPEED, "5"); |
||||
// 设置合成的语调,0-15 ,默认 5
|
||||
mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_PITCH, "5"); |
||||
// 仅需要在线合成并不使用压缩传输
|
||||
mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_AUDIO_RATE, SpeechSynthesizer.AUDIO_BITRATE_PCM); |
||||
mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_AUDIO_ENCODE, SpeechSynthesizer.AUDIO_ENCODE_PCM); |
||||
int result = mSpeechSynthesizer.initTts(TtsMode.ONLINE); |
||||
isInitTts = result == 0; |
||||
} |
||||
|
||||
public int ttsSpeak(String text) { |
||||
if (mSpeechSynthesizer != null && isInitTts){ |
||||
return mSpeechSynthesizer.speak(text); |
||||
} else return 1; |
||||
} |
||||
|
||||
public void release() { |
||||
if (mSpeechSynthesizer != null){ |
||||
mSpeechSynthesizer.stop(); |
||||
mSpeechSynthesizer.release(); |
||||
isInitTts = false; |
||||
mSpeechSynthesizer = null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,42 @@
@@ -0,0 +1,42 @@
|
||||
package com.dolphin.umeng.util; |
||||
|
||||
import android.media.AudioManager; |
||||
import android.media.MediaPlayer; |
||||
import android.net.Uri; |
||||
import android.os.PowerManager; |
||||
import android.text.TextUtils; |
||||
|
||||
import com.blankj.utilcode.util.Utils; |
||||
import com.blankj.utilcode.util.VolumeUtils; |
||||
import com.dolphin.umeng.R; |
||||
|
||||
import lombok.experimental.UtilityClass; |
||||
|
||||
@UtilityClass |
||||
public class MultimediaUtil { |
||||
|
||||
private MediaPlayer mediaPlayer; |
||||
|
||||
public void playSound(String onlineRingtone) { |
||||
if (TextUtils.isEmpty(onlineRingtone)) { |
||||
mediaPlayer = MediaPlayer.create(Utils.getApp().getApplicationContext(), R.raw.audio_system_hint); |
||||
} else mediaPlayer = MediaPlayer.create(Utils.getApp().getApplicationContext(), Uri.parse(onlineRingtone)); |
||||
mediaPlayer.setWakeMode(Utils.getApp().getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK); |
||||
if (VolumeUtils.getMinVolume(AudioManager.STREAM_MUSIC) == 0) { |
||||
VolumeUtils.setVolume(AudioManager.STREAM_MUSIC, VolumeUtils.getMaxVolume(AudioManager.STREAM_MUSIC)/3, AudioManager.FLAG_PLAY_SOUND); |
||||
} |
||||
mediaPlayer.start(); |
||||
} |
||||
|
||||
public void ttsSpeak(String ttsText) { |
||||
BaiduTtsUtil.ttsSpeak(ttsText); |
||||
} |
||||
|
||||
public void playSoundAndTtsSpeak(String onlineRingtone, String ttsText) { |
||||
playSound(onlineRingtone); |
||||
mediaPlayer.setOnCompletionListener(mp -> { |
||||
ttsSpeak(ttsText); |
||||
}); |
||||
} |
||||
|
||||
} |
@ -1,105 +0,0 @@
@@ -1,105 +0,0 @@
|
||||
package com.dolphin.umeng.util; |
||||
|
||||
import android.content.Context; |
||||
import android.hardware.camera2.CameraAccessException; |
||||
import android.hardware.camera2.CameraManager; |
||||
import android.media.AudioManager; |
||||
import android.media.MediaPlayer; |
||||
import android.net.Uri; |
||||
import android.os.PowerManager; |
||||
import android.os.VibrationEffect; |
||||
import android.os.Vibrator; |
||||
import android.text.TextUtils; |
||||
|
||||
import com.blankj.utilcode.util.LogUtils; |
||||
import com.dolphin.umeng.R; |
||||
import com.dolphin.umeng.entity.CustomMsg; |
||||
|
||||
import java.util.Timer; |
||||
import java.util.TimerTask; |
||||
|
||||
/** |
||||
* 推送类型响应类 |
||||
* @Author: liusixiang007 |
||||
* @since: 2023/7/10 |
||||
*/ |
||||
public class PushTypeHandle { |
||||
|
||||
private Context context; |
||||
private MediaPlayer mediaPlayer; // 音乐提示播放器
|
||||
private CustomMsg msg; // 响应属性实体类
|
||||
private TtsSyntherizer mTtsSyntherizer; |
||||
|
||||
public PushTypeHandle(Context context, CustomMsg item){ |
||||
this.mTtsSyntherizer = new TtsSyntherizer(context); |
||||
this.context = context; |
||||
this.msg = item; |
||||
} |
||||
|
||||
/** |
||||
* 判断响应类型 先闪光 震动 再 提示音 和语音转文字 |
||||
*/ |
||||
public void judgePushType() { |
||||
if ("true".equals(msg.getPlayLights())) isPlayLights(); |
||||
if ("true".equals(msg.getPlayVibrate())) isPlayVibrate(); |
||||
if ("true".equals(msg.getPlaySound())) isPlaySound(msg); |
||||
} |
||||
|
||||
/** |
||||
* 是否播放声音 以及 文字转语音 |
||||
* @param item |
||||
*/ |
||||
public void isPlaySound(CustomMsg item) { |
||||
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); |
||||
if (TextUtils.isEmpty(item.getOnlineRingtone())) { // 没有设置离线铃声
|
||||
mediaPlayer = MediaPlayer.create(context, R.raw.audio_system_hint); |
||||
}else { // 设置了提示铃声
|
||||
mediaPlayer = MediaPlayer.create(context, Uri.parse(item.getOnlineRingtone())); |
||||
} |
||||
mediaPlayer.setWakeMode(context, PowerManager.PARTIAL_WAKE_LOCK); // 设置离线播放模式
|
||||
int currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC); |
||||
if(currentVolume == 0) { // 媒体通道为静音状态 则设置为33%的音量
|
||||
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC) / 3, 0); |
||||
} |
||||
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { // 播放结束的逻辑
|
||||
@Override |
||||
public void onCompletion(MediaPlayer mp) { |
||||
if ("true".equals(item.getPlayToText())) mTtsSyntherizer.ttsSpeak(item.getTitle()); // 开始播放语音合成
|
||||
if (currentVolume == 0) audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0); // 恢复媒体通道静音
|
||||
} |
||||
}); |
||||
mediaPlayer.start(); // 开始播放提示音
|
||||
} |
||||
|
||||
/**闪光灯闪烁 一次 1s 后关闭*/ |
||||
public void isPlayLights() { |
||||
CameraManager cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); |
||||
try { |
||||
String cameraId = cameraManager.getCameraIdList()[0]; |
||||
cameraManager.setTorchMode(cameraId, true); // 开启闪光灯
|
||||
Timer timer = new Timer(); |
||||
timer.schedule(new TimerTask() { |
||||
@Override |
||||
public void run() { |
||||
try { |
||||
cameraManager.setTorchMode(cameraId, false); |
||||
} catch (CameraAccessException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
}, 1000); |
||||
} catch (CameraAccessException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
|
||||
/**震动 800毫秒*/ |
||||
public void isPlayVibrate() { |
||||
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); |
||||
// 检查设备是否支持震动
|
||||
if (vibrator != null && vibrator.hasVibrator()){ |
||||
VibrationEffect vibrationEffect = VibrationEffect.createOneShot(800, VibrationEffect.DEFAULT_AMPLITUDE); // 定义震动时常(单位毫秒)以及震动强度
|
||||
vibrator.vibrate(vibrationEffect); // 单位:毫秒
|
||||
} |
||||
} |
||||
} |
@ -1,116 +0,0 @@
@@ -1,116 +0,0 @@
|
||||
package com.dolphin.umeng.util; |
||||
|
||||
import android.content.Context; |
||||
|
||||
import com.baidu.tts.client.SpeechError; |
||||
import com.baidu.tts.client.SpeechSynthesizer; |
||||
import com.baidu.tts.client.SpeechSynthesizerListener; |
||||
import com.baidu.tts.client.TtsMode; |
||||
import com.blankj.utilcode.util.LogUtils; |
||||
|
||||
/** |
||||
* 百度在线语音合成 |
||||
* @Author: liusixiang007 |
||||
* @since: 2023/8/11 |
||||
*/ |
||||
public class TtsSyntherizer { |
||||
|
||||
private Context context; |
||||
private volatile boolean isInitTts = false; // 当前播放状态
|
||||
protected SpeechSynthesizer mSpeechSynthesizer; |
||||
private static final String BD_APP_ID = "37122313"; |
||||
private static final String BD_APP_KEY = "BNrZhvnx5DgX74j847KKrjzn"; |
||||
private static final String BD_APP_SECRET_KEY = "bF33QKfD1grBbO1R0Ur1L0A65wGkj3GR"; |
||||
|
||||
public TtsSyntherizer(Context context) { |
||||
this.context = context; |
||||
initTTs(); |
||||
} |
||||
|
||||
private void initTTs() { |
||||
new Thread(new Runnable() { |
||||
@Override |
||||
public void run() { |
||||
mSpeechSynthesizer = SpeechSynthesizer.getInstance(); |
||||
mSpeechSynthesizer.setContext(context); |
||||
mSpeechSynthesizer.setSpeechSynthesizerListener(new SpeechSynthesizerListener() { |
||||
@Override |
||||
public void onSynthesizeStart(String s) { |
||||
LogUtils.d("准备开始合成,序列号:" + s); |
||||
} |
||||
|
||||
@Override |
||||
public void onSynthesizeDataArrived(String s, byte[] bytes, int i, int i1) { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void onSynthesizeFinish(String s) { |
||||
LogUtils.d("合成结束回调, 序列号:" + s); |
||||
} |
||||
|
||||
@Override |
||||
public void onSpeechStart(String s) { // 开始播放 暂时提高媒体音量
|
||||
LogUtils.d("播放开始回调, 序列号:" + s); |
||||
} |
||||
|
||||
@Override |
||||
public void onSpeechProgressChanged(String s, int i) { |
||||
LogUtils.d("播放进度回调, progress:" + s + ";序列号:" + i); |
||||
} |
||||
|
||||
@Override |
||||
public void onSpeechFinish(String s) { // 播放结束之后恢复媒体音量
|
||||
LogUtils.d("SpeechSynthesizerListener-onSpeechFinish 播报结束"); |
||||
release(); // 播放结束之后就清除占用
|
||||
} |
||||
|
||||
@Override |
||||
public void onError(String s, SpeechError speechError) { |
||||
mSpeechSynthesizer.pause(); |
||||
LogUtils.d("语音合成报错 错误id"+s+" 报错原因 "+speechError); |
||||
} |
||||
}); |
||||
|
||||
mSpeechSynthesizer.setAppId(BD_APP_ID); |
||||
mSpeechSynthesizer.setApiKey(BD_APP_KEY , BD_APP_SECRET_KEY); |
||||
// 设置在线发声音人: 0 普通女声(默认) 1 普通男声 2 特别男声 3 情感男声<度逍遥> 4 情感儿童声<度丫丫>
|
||||
mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_SPEAKER, "0"); |
||||
// 设置合成的音量,0-15 ,默认 5
|
||||
mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_VOLUME, "15"); |
||||
// 设置合成的语速,0-15 ,默认 5
|
||||
mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_SPEED, "5"); |
||||
// 设置合成的语调,0-15 ,默认 5
|
||||
mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_PITCH, "5"); |
||||
// mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_MIX_MODE, SpeechSynthesizer.MIX_MODE_DEFAULT);
|
||||
// 仅需要在线合成并不使用压缩传输
|
||||
mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_AUDIO_RATE, SpeechSynthesizer.AUDIO_BITRATE_PCM); |
||||
mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_AUDIO_ENCODE, SpeechSynthesizer.AUDIO_ENCODE_PCM); |
||||
int result = mSpeechSynthesizer.initTts(TtsMode.ONLINE); |
||||
if (result == 0) { |
||||
isInitTts = true; |
||||
} else { |
||||
isInitTts = false; |
||||
} |
||||
} |
||||
}).start(); |
||||
} |
||||
|
||||
public int ttsSpeak(String text) { |
||||
if (mSpeechSynthesizer != null && isInitTts){ |
||||
int result = mSpeechSynthesizer.speak(text); |
||||
return result; |
||||
}else { |
||||
return 1; |
||||
} |
||||
} |
||||
|
||||
public void release() { |
||||
if (mSpeechSynthesizer != null){ |
||||
mSpeechSynthesizer.stop(); |
||||
mSpeechSynthesizer.release(); |
||||
isInitTts = false; |
||||
mSpeechSynthesizer = null; |
||||
} |
||||
} |
||||
} |
@ -1,8 +1,5 @@
@@ -1,8 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<paths> |
||||
<!-- QQ 官方分享SDK 共享路径 --> |
||||
<root-path name="opensdk_root" path=""/> |
||||
<external-files-path name="opensdk_external" path="Images/tmp"/> |
||||
<!-- 友盟微信分享SDK 共享路径--> |
||||
<external-files-path name="umeng_cache" path="umeng_cache/"/> |
||||
</paths> |
Loading…
Reference in new issue