完成公众号
This commit is contained in:
parent
22158b6eb3
commit
b11622f561
@ -18,6 +18,7 @@ public class PathConfig {
|
|||||||
public static final int VIEW_STATE_LOADING = 0x1234;//加载中
|
public static final int VIEW_STATE_LOADING = 0x1234;//加载中
|
||||||
|
|
||||||
//=============================主页按钮模块类型===========================
|
//=============================主页按钮模块类型===========================
|
||||||
|
public static final int NOTIFY_ID = 9999;//通知栏ID
|
||||||
public static final String MODULE_CALL = "call";
|
public static final String MODULE_CALL = "call";
|
||||||
public static final String MODULE_PRISON = "prison";
|
public static final String MODULE_PRISON = "prison";
|
||||||
public static final String MODULE_CHECK = "check";
|
public static final String MODULE_CHECK = "check";
|
||||||
@ -33,8 +34,8 @@ public class PathConfig {
|
|||||||
public static final String ACTION_FROM_SOCKET_PUSH_MSG = "com.tenlionsoft.xz_cultural.SOCKET_MSG_PUBLIC_ACTION";
|
public static final String ACTION_FROM_SOCKET_PUSH_MSG = "com.tenlionsoft.xz_cultural.SOCKET_MSG_PUBLIC_ACTION";
|
||||||
|
|
||||||
public static final String PUSH_DATA_KEY = "PUBLIC_CODE_KEY";
|
public static final String PUSH_DATA_KEY = "PUBLIC_CODE_KEY";
|
||||||
|
public static final String PROJECT_NAME = "city-governance";/* ===项目名称==*/
|
||||||
public static final String PROJECT_NAME = "locationReal";//TODO ===项目名称==
|
public static final String PROJECT_NAME_CH = "数字文化云";
|
||||||
public static final String ACTION_SYSTEM_MESSAGE = "com.sucstepsoft.hs.message";
|
public static final String ACTION_SYSTEM_MESSAGE = "com.sucstepsoft.hs.message";
|
||||||
public static final String ACTION_LOCATION_MESSAGE = "com.sucstepsoft.realtimelocation.MESSAGE_RECEIVED_ACTION";
|
public static final String ACTION_LOCATION_MESSAGE = "com.sucstepsoft.realtimelocation.MESSAGE_RECEIVED_ACTION";
|
||||||
public static final String ACTION_PUNCH_TIME_MESSAGE = "com.sucstepsoft.realtimelocation.MESSAGE_PUNCH_ACTION";
|
public static final String ACTION_PUNCH_TIME_MESSAGE = "com.sucstepsoft.realtimelocation.MESSAGE_PUNCH_ACTION";
|
||||||
|
@ -23,6 +23,7 @@ import com.sucstepsoft.cm_utils.core.retrofit_net.api.BaseApiService;
|
|||||||
import com.sucstepsoft.cm_utils.utils.ExceptionHandler;
|
import com.sucstepsoft.cm_utils.utils.ExceptionHandler;
|
||||||
import com.sucstepsoft.cm_utils.utils.LogUtils;
|
import com.sucstepsoft.cm_utils.utils.LogUtils;
|
||||||
import com.sucstepsoft.cm_utils.utils.UserLgUtils;
|
import com.sucstepsoft.cm_utils.utils.UserLgUtils;
|
||||||
|
import com.sucstepsoft.cm_utils.utils.toast.ToastUtils;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
@ -199,6 +200,8 @@ public class CommonWebActivity extends BaseActivity {
|
|||||||
setResult(RESULT_OK);
|
setResult(RESULT_OK);
|
||||||
finish();
|
finish();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
ToastUtils.show("打开微信失败,请稍后重试");
|
||||||
|
finish();
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -212,7 +215,10 @@ public class CommonWebActivity extends BaseActivity {
|
|||||||
String query = "";
|
String query = "";
|
||||||
String str = "userId=" + UserLgUtils.getUserId();
|
String str = "userId=" + UserLgUtils.getUserId();
|
||||||
try {
|
try {
|
||||||
query = URLEncoder.encode(str, "UTF-8");
|
String key = URLEncoder.encode("userId", "UTF-8");
|
||||||
|
String value = URLEncoder.encode(UserLgUtils.getUserId(), "UTF-8");
|
||||||
|
query = key + "=" + value;
|
||||||
|
// query = URLEncoder.encode(str, "UTF-8");
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,45 @@ public class NotificationUtils extends ContextWrapper {
|
|||||||
}
|
}
|
||||||
return mManager;
|
return mManager;
|
||||||
}
|
}
|
||||||
|
private static NotificationManager mNotificationManager;
|
||||||
|
private final static String PRIMARY_CHANNEL = "citygovernance";
|
||||||
|
|
||||||
|
public static Notification buildNotification(Context context, String title, String hintMsg) {
|
||||||
|
Notification notification = null;
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
NotificationChannel channel = new NotificationChannel(PRIMARY_CHANNEL,
|
||||||
|
context.getString(R.string.app_name), NotificationManager.IMPORTANCE_HIGH);
|
||||||
|
channel.setLightColor(Color.GREEN);
|
||||||
|
channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
|
||||||
|
getNotificationManager(context).createNotificationChannel(channel);
|
||||||
|
Notification.Builder builder = new Notification.Builder(context,
|
||||||
|
PRIMARY_CHANNEL)
|
||||||
|
.setContentTitle(title)
|
||||||
|
.setContentText(hintMsg)
|
||||||
|
.setVisibility(Notification.VISIBILITY_PUBLIC)
|
||||||
|
.setSmallIcon(R.drawable.app_logo_smal)
|
||||||
|
.setAutoCancel(true);
|
||||||
|
notification = builder.build();
|
||||||
|
} else {
|
||||||
|
Notification.Builder builder = new Notification.Builder(context);
|
||||||
|
builder.setSmallIcon(R.drawable.app_logo_smal);
|
||||||
|
builder.setContentTitle(title);
|
||||||
|
builder.setContentText(hintMsg)
|
||||||
|
.setPriority(Notification.PRIORITY_MAX)
|
||||||
|
.setWhen(System.currentTimeMillis());
|
||||||
|
notification = builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
return notification;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static NotificationManager getNotificationManager(Context context) {
|
||||||
|
if (mNotificationManager == null) {
|
||||||
|
mNotificationManager = (NotificationManager) context.getSystemService(
|
||||||
|
Context.NOTIFICATION_SERVICE);
|
||||||
|
}
|
||||||
|
return mNotificationManager;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送通知
|
* 发送通知
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- Required -->
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- Required -->
|
||||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
<uses-permission android:name="android.permission.VIBRATE" />
|
<uses-permission android:name="android.permission.VIBRATE" />
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||||
<uses-permission
|
<uses-permission
|
||||||
android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"
|
android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"
|
||||||
tools:ignore="ProtectedPermissions" />
|
tools:ignore="ProtectedPermissions" />
|
||||||
@ -155,6 +156,9 @@
|
|||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
<service
|
||||||
|
android:name=".cultural.socket.SocketService"
|
||||||
|
android:exported="true" />
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
@ -217,6 +217,7 @@ public class MainActivity extends BaseActivity {
|
|||||||
doCheckPermission();
|
doCheckPermission();
|
||||||
checkAppVersion();
|
checkAppVersion();
|
||||||
getUserInfo();
|
getUserInfo();
|
||||||
|
getUserIsPublicCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,6 +48,7 @@ import com.sucstepsoft.cm_utils.core.beans.AddPhotoBean;
|
|||||||
import com.sucstepsoft.cm_utils.core.beans.BaseImageBean;
|
import com.sucstepsoft.cm_utils.core.beans.BaseImageBean;
|
||||||
import com.sucstepsoft.cm_utils.core.retrofit_net.BaseUrlApi;
|
import com.sucstepsoft.cm_utils.core.retrofit_net.BaseUrlApi;
|
||||||
import com.sucstepsoft.cm_utils.core.retrofit_net.RetrofitManager;
|
import com.sucstepsoft.cm_utils.core.retrofit_net.RetrofitManager;
|
||||||
|
import com.sucstepsoft.cm_utils.core.retrofit_net.api.BaseApiService;
|
||||||
import com.sucstepsoft.cm_utils.core.widget.base.BannerImageTextAllAdapter;
|
import com.sucstepsoft.cm_utils.core.widget.base.BannerImageTextAllAdapter;
|
||||||
import com.sucstepsoft.cm_utils.core.widget.base.BaseActivity;
|
import com.sucstepsoft.cm_utils.core.widget.base.BaseActivity;
|
||||||
import com.sucstepsoft.cm_utils.core.widget.base.CommonWebActivity;
|
import com.sucstepsoft.cm_utils.core.widget.base.CommonWebActivity;
|
||||||
@ -57,6 +58,7 @@ import com.sucstepsoft.cm_utils.core.widget.views.ButtomDialogView;
|
|||||||
import com.sucstepsoft.cm_utils.core.widget.views.ItemSplitDivider;
|
import com.sucstepsoft.cm_utils.core.widget.views.ItemSplitDivider;
|
||||||
import com.sucstepsoft.cm_utils.core.widget.views.NestedScrollWebView;
|
import com.sucstepsoft.cm_utils.core.widget.views.NestedScrollWebView;
|
||||||
import com.sucstepsoft.cm_utils.core.widget.views.TypeFaceTextView;
|
import com.sucstepsoft.cm_utils.core.widget.views.TypeFaceTextView;
|
||||||
|
import com.sucstepsoft.cm_utils.utils.AppUtils;
|
||||||
import com.sucstepsoft.cm_utils.utils.ConvertUtils;
|
import com.sucstepsoft.cm_utils.utils.ConvertUtils;
|
||||||
import com.sucstepsoft.cm_utils.utils.ExceptionHandler;
|
import com.sucstepsoft.cm_utils.utils.ExceptionHandler;
|
||||||
import com.sucstepsoft.cm_utils.utils.FileUtils;
|
import com.sucstepsoft.cm_utils.utils.FileUtils;
|
||||||
@ -81,6 +83,7 @@ import com.tengshisoft.mudulemain.R;
|
|||||||
import com.tengshisoft.mudulemain.R2;
|
import com.tengshisoft.mudulemain.R2;
|
||||||
import com.tengshisoft.mudulemain.cultural.adapter.CommentAdapter;
|
import com.tengshisoft.mudulemain.cultural.adapter.CommentAdapter;
|
||||||
import com.tengshisoft.mudulemain.cultural.adapter.NewsCategoryAdapter;
|
import com.tengshisoft.mudulemain.cultural.adapter.NewsCategoryAdapter;
|
||||||
|
import com.tengshisoft.mudulemain.cultural.beans.AttentionCodeBean;
|
||||||
import com.tengshisoft.mudulemain.cultural.beans.BaseUserBean;
|
import com.tengshisoft.mudulemain.cultural.beans.BaseUserBean;
|
||||||
import com.tengshisoft.mudulemain.cultural.beans.CollectBean;
|
import com.tengshisoft.mudulemain.cultural.beans.CollectBean;
|
||||||
import com.tengshisoft.mudulemain.cultural.beans.CommentListBean;
|
import com.tengshisoft.mudulemain.cultural.beans.CommentListBean;
|
||||||
@ -88,7 +91,7 @@ import com.tengshisoft.mudulemain.cultural.beans.CommentPublishBean;
|
|||||||
import com.tengshisoft.mudulemain.cultural.beans.LikeBean;
|
import com.tengshisoft.mudulemain.cultural.beans.LikeBean;
|
||||||
import com.tengshisoft.mudulemain.cultural.beans.NewsDetailBean;
|
import com.tengshisoft.mudulemain.cultural.beans.NewsDetailBean;
|
||||||
import com.tengshisoft.mudulemain.cultural.net.HomeApi;
|
import com.tengshisoft.mudulemain.cultural.net.HomeApi;
|
||||||
import com.tengshisoft.mudulemain.cultural.socket.WsManager;
|
import com.tengshisoft.mudulemain.cultural.socket.SocketService;
|
||||||
import com.tengshisoft.mudulemain.cultural.widget.ButtomCommentListDialogView;
|
import com.tengshisoft.mudulemain.cultural.widget.ButtomCommentListDialogView;
|
||||||
import com.youth.banner.Banner;
|
import com.youth.banner.Banner;
|
||||||
import com.youth.banner.transformer.ScaleInTransformer;
|
import com.youth.banner.transformer.ScaleInTransformer;
|
||||||
@ -385,7 +388,6 @@ public class NewsLocalDetailActivity extends BaseActivity {
|
|||||||
} else {
|
} else {
|
||||||
//是否需要关注公众号
|
//是否需要关注公众号
|
||||||
if (newsDetailBean.getNewsViewAuth().contains("2")) {
|
if (newsDetailBean.getNewsViewAuth().contains("2")) {
|
||||||
startSocket();
|
|
||||||
showPublicCodeDialog(newsDetailBean);
|
showPublicCodeDialog(newsDetailBean);
|
||||||
} else {
|
} else {
|
||||||
setDataToView(newsDetailBean);
|
setDataToView(newsDetailBean);
|
||||||
@ -416,12 +418,12 @@ public class NewsLocalDetailActivity extends BaseActivity {
|
|||||||
* 开启Socket
|
* 开启Socket
|
||||||
*/
|
*/
|
||||||
private void startSocket() {
|
private void startSocket() {
|
||||||
WsManager wsManager = new WsManager
|
Intent intent = new Intent(mActivity, SocketService.class);
|
||||||
.Builder(getApplication())
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
.wsUrl(BaseUrlApi.SOCKET_IP + UserLgUtils.getUserId())
|
mActivity.startForegroundService(intent);
|
||||||
.needReconnect(true)
|
} else {
|
||||||
.build();
|
mActivity.startService(intent);
|
||||||
wsManager.startConnect();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -433,6 +435,7 @@ public class NewsLocalDetailActivity extends BaseActivity {
|
|||||||
if (!UserLgUtils.getIsPublicCode()) {
|
if (!UserLgUtils.getIsPublicCode()) {
|
||||||
mRlPublicCode.setVisibility(View.VISIBLE);
|
mRlPublicCode.setVisibility(View.VISIBLE);
|
||||||
mBtnPublic.setOnClickListener(v -> {
|
mBtnPublic.setOnClickListener(v -> {
|
||||||
|
startSocket();
|
||||||
Intent intent = new Intent(mActivity, CommonWebActivity.class);
|
Intent intent = new Intent(mActivity, CommonWebActivity.class);
|
||||||
mResultLauncher.launch(intent);
|
mResultLauncher.launch(intent);
|
||||||
});
|
});
|
||||||
@ -1182,6 +1185,19 @@ public class NewsLocalDetailActivity extends BaseActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
|
//在socket断链的情况先手动获取一次是否关注
|
||||||
|
LogUtils.e("是否关注" + UserLgUtils.getIsPublicCode());
|
||||||
|
if (!UserLgUtils.getIsPublicCode()) {
|
||||||
|
if (mContentSkeleton != null) {
|
||||||
|
mContentSkeleton.show();
|
||||||
|
} else {
|
||||||
|
mContentSkeleton = Skeleton.bind(mLlNewsContent)
|
||||||
|
.load(R.layout.item_skeleton_news_content_local)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
mRlPublicCode.setVisibility(View.GONE);
|
||||||
|
getUserIsPublicCode();
|
||||||
|
}
|
||||||
mCommentPage = 1;
|
mCommentPage = 1;
|
||||||
if (!TextUtils.isEmpty(UserLgUtils.getToken())) {
|
if (!TextUtils.isEmpty(UserLgUtils.getToken())) {
|
||||||
getCommentListByLogin(mCommentPage);
|
getCommentListByLogin(mCommentPage);
|
||||||
@ -1190,6 +1206,40 @@ public class NewsLocalDetailActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void getUserIsPublicCode() {
|
||||||
|
if (!TextUtils.isEmpty(UserLgUtils.getUserId())) {
|
||||||
|
RetrofitManager.getInstance()
|
||||||
|
.create(BaseApiService.class)
|
||||||
|
.getIsPublicCode(UserLgUtils.getUserId())
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(new Observer<Boolean>() {
|
||||||
|
@Override
|
||||||
|
public void onSubscribe(Disposable d) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNext(Boolean baseSuccessBean) {
|
||||||
|
UserLgUtils.putIsPublicCode(baseSuccessBean);
|
||||||
|
getNewsDetail();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Throwable e) {
|
||||||
|
getNewsDetail();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onComplete() {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
getNewsDetail();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 显示评论dialog
|
* 显示评论dialog
|
||||||
*/
|
*/
|
||||||
@ -1537,6 +1587,18 @@ public class NewsLocalDetailActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void refreshPage() {
|
||||||
|
if (mContentSkeleton != null) {
|
||||||
|
mContentSkeleton.show();
|
||||||
|
} else {
|
||||||
|
mContentSkeleton = Skeleton.bind(mLlNewsContent)
|
||||||
|
.load(R.layout.item_skeleton_news_content_local)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
mRlPublicCode.setVisibility(View.GONE);
|
||||||
|
getNewsDetail();
|
||||||
|
}
|
||||||
|
|
||||||
public class SocketMsg extends BroadcastReceiver {
|
public class SocketMsg extends BroadcastReceiver {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1544,8 +1606,17 @@ public class NewsLocalDetailActivity extends BaseActivity {
|
|||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
if (PathConfig.ACTION_FROM_SOCKET_PUSH_MSG.equals(action)) {
|
if (PathConfig.ACTION_FROM_SOCKET_PUSH_MSG.equals(action)) {
|
||||||
//关注公众号
|
//关注公众号
|
||||||
String strData = intent.getStringExtra(PathConfig.PUSH_DATA_KEY);
|
//关闭socket
|
||||||
LogUtils.e("二维码返回:" + strData);
|
stopService(new Intent(mActivity, SocketService.class));
|
||||||
|
try {
|
||||||
|
String strData = intent.getStringExtra(PathConfig.PUSH_DATA_KEY);
|
||||||
|
AttentionCodeBean errorBean = new Gson().fromJson(strData, AttentionCodeBean.class);
|
||||||
|
UserLgUtils.putIsPublicCode(errorBean.isAttention());
|
||||||
|
//刷新页面
|
||||||
|
refreshPage();
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1557,6 +1628,10 @@ public class NewsLocalDetailActivity extends BaseActivity {
|
|||||||
mAudio.pause();
|
mAudio.pause();
|
||||||
mAudio.release();
|
mAudio.release();
|
||||||
}
|
}
|
||||||
|
boolean processIsRuning = AppUtils.getProcessIsRuning(mActivity, "com.tengshisoft.mudulemain.cultural.socket.SocketService");
|
||||||
|
if (processIsRuning) {
|
||||||
|
stopService(new Intent(mActivity, SocketService.class));
|
||||||
|
}
|
||||||
if (mSocketMsg != null) {
|
if (mSocketMsg != null) {
|
||||||
unregisterReceiver(mSocketMsg);
|
unregisterReceiver(mSocketMsg);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.tengshisoft.mudulemain.cultural.beans;
|
||||||
|
|
||||||
|
public class AttentionCodeBean {
|
||||||
|
|
||||||
|
private String appId;
|
||||||
|
private String userId;
|
||||||
|
private boolean attention;
|
||||||
|
|
||||||
|
public String getAppId() {
|
||||||
|
return appId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAppId(String appId) {
|
||||||
|
this.appId = appId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserId(String userId) {
|
||||||
|
this.userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAttention() {
|
||||||
|
return attention;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAttention(boolean attention) {
|
||||||
|
this.attention = attention;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,217 @@
|
|||||||
|
package com.tengshisoft.mudulemain.cultural.socket;
|
||||||
|
|
||||||
|
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 androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.sucstepsoft.cm_utils.constant.PathConfig;
|
||||||
|
import com.sucstepsoft.cm_utils.core.retrofit_net.BaseUrlApi;
|
||||||
|
import com.sucstepsoft.cm_utils.core.widget.base.NotificationUtils;
|
||||||
|
import com.sucstepsoft.cm_utils.utils.LogUtils;
|
||||||
|
import com.sucstepsoft.cm_utils.utils.UserLgUtils;
|
||||||
|
import com.tengshisoft.mudulemain.R;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import io.reactivex.disposables.Disposable;
|
||||||
|
|
||||||
|
public class SocketService extends Service {
|
||||||
|
|
||||||
|
|
||||||
|
private MediaPlayer mMediaPlayer;
|
||||||
|
private WsManager mWsManager;
|
||||||
|
private Disposable mSocketHeart;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate() {
|
||||||
|
super.onCreate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
|
startPlayVoice();
|
||||||
|
startForegroundNotify();
|
||||||
|
startSocket();
|
||||||
|
return START_STICKY;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void startSocket() {
|
||||||
|
mWsManager = new WsManager
|
||||||
|
.Builder(getApplication())
|
||||||
|
.wsUrl(BaseUrlApi.SOCKET_IP + UserLgUtils.getUserId())
|
||||||
|
.needReconnect(true)
|
||||||
|
.build();
|
||||||
|
mWsManager.startConnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 进程保活-开启前台通知,提升服务进程
|
||||||
|
*/
|
||||||
|
private void startForegroundNotify() {
|
||||||
|
startForeground(PathConfig.NOTIFY_ID, NotificationUtils.buildNotification(getApplicationContext(), PathConfig.PROJECT_NAME_CH, PathConfig.PROJECT_NAME_CH + "平台正在运行中..."));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 进程保活-后台播放音乐
|
||||||
|
*/
|
||||||
|
private void startPlayVoice() {
|
||||||
|
if (mMediaPlayer == null) {
|
||||||
|
mMediaPlayer = MediaPlayer.create(this, R.raw.no_kill);
|
||||||
|
mMediaPlayer.setVolume(0f, 0f);
|
||||||
|
mMediaPlayer.setOnCompletionListener(mp -> playVoice());
|
||||||
|
playVoice();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开始播放音乐
|
||||||
|
*/
|
||||||
|
private void playVoice() {
|
||||||
|
if (mMediaPlayer != null && !mMediaPlayer.isPlaying()) {
|
||||||
|
mMediaPlayer.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void pauseVoice() {
|
||||||
|
if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
|
||||||
|
mMediaPlayer.pause();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断activity是否在运行
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean isActivityAlive() {
|
||||||
|
ActivityManager am = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
|
||||||
|
List<ActivityManager.RunningTaskInfo> runningTasks = am.getRunningTasks(100);
|
||||||
|
for (ActivityManager.RunningTaskInfo info : runningTasks) {
|
||||||
|
LogUtils.e("前台运行===" + info.topActivity.getClassName());
|
||||||
|
if (this.getPackageName().equals(info.topActivity.getPackageName())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断App是否在前台
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private boolean appOnForeground() {
|
||||||
|
ActivityManager am = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
|
||||||
|
List<ActivityManager.RunningAppProcessInfo> appProcesses = am.getRunningAppProcesses();
|
||||||
|
if (appProcesses == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (ActivityManager.RunningAppProcessInfo info : appProcesses) {
|
||||||
|
if (info.processName.equals(this.getPackageName()) && info.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送系统通知
|
||||||
|
*/
|
||||||
|
private void sendSystemNotify(String from, JSONObject obj) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送socket已办
|
||||||
|
*/
|
||||||
|
private void sendSocketNoticeMsg(String msg) {
|
||||||
|
if (mWsManager != null) {
|
||||||
|
mWsManager.sendMessage(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* socket
|
||||||
|
*/
|
||||||
|
private void startSocketService() {
|
||||||
|
if (mWsManager == null) {
|
||||||
|
mWsManager = new WsManager
|
||||||
|
.Builder(getApplication())
|
||||||
|
.wsUrl(BaseUrlApi.SOCKET_IP)
|
||||||
|
.needReconnect(true)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mWsManager.isWsConnected()) {
|
||||||
|
mWsManager.startConnect();
|
||||||
|
//心跳
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 停止连接socket
|
||||||
|
*/
|
||||||
|
private void stopSocketService() {
|
||||||
|
if (mWsManager != null && mWsManager.isWsConnected()) {
|
||||||
|
mWsManager.stopConnect();
|
||||||
|
mWsManager = null;
|
||||||
|
if (mSocketHeart != null && !mSocketHeart.isDisposed()) {
|
||||||
|
mSocketHeart.dispose();
|
||||||
|
mSocketHeart = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送一个通知
|
||||||
|
*/
|
||||||
|
private void sendNotify(String from, String msg, String page, int type) {
|
||||||
|
// NotificationUtils utils = new NotificationUtils(SocketService.this);
|
||||||
|
// if (TextUtils.isEmpty(page)) {
|
||||||
|
// utils.sendNotification(1000865, from, msg);
|
||||||
|
// } else {
|
||||||
|
// // 判断是普通通知还是通话通知
|
||||||
|
// Intent intent = new Intent();
|
||||||
|
// intent.setAction(LionActions.ACTION_PUSH_MSG_ACTIVITY);
|
||||||
|
// intent.putExtra("page", page);
|
||||||
|
// intent.putExtra("type", type);
|
||||||
|
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
// PendingIntent pIntent = PendingIntent.getActivity(this, 12, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||||
|
// utils.sendNotificationPendingIntent(from, msg, pIntent);
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
|
||||||
|
stopSocketService();
|
||||||
|
|
||||||
|
if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
|
||||||
|
mMediaPlayer.stop();
|
||||||
|
mMediaPlayer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public IBinder onBind(Intent intent) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -10,7 +10,6 @@ import android.text.TextUtils;
|
|||||||
|
|
||||||
import com.sucstepsoft.cm_utils.constant.PathConfig;
|
import com.sucstepsoft.cm_utils.constant.PathConfig;
|
||||||
import com.sucstepsoft.cm_utils.utils.LogUtils;
|
import com.sucstepsoft.cm_utils.utils.LogUtils;
|
||||||
import com.tengshisoft.mudulemain.cultural.utils.AesUtil;
|
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
@ -94,6 +93,7 @@ public class WsManager implements IWsManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMessage(WebSocket webSocket, final ByteString bytes) {
|
public void onMessage(WebSocket webSocket, final ByteString bytes) {
|
||||||
|
LogUtils.e("接收到消息=" + bytes.toString());
|
||||||
if (Looper.myLooper() != Looper.getMainLooper()) {
|
if (Looper.myLooper() != Looper.getMainLooper()) {
|
||||||
wsMainHandler.post(() -> sendNotify(bytes.toString()));
|
wsMainHandler.post(() -> sendNotify(bytes.toString()));
|
||||||
} else {
|
} else {
|
||||||
@ -103,6 +103,7 @@ public class WsManager implements IWsManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMessage(WebSocket webSocket, final String text) {
|
public void onMessage(WebSocket webSocket, final String text) {
|
||||||
|
LogUtils.e("接收到消息=" + text);
|
||||||
if (Looper.myLooper() != Looper.getMainLooper()) {
|
if (Looper.myLooper() != Looper.getMainLooper()) {
|
||||||
wsMainHandler.post(() -> sendNotify(text));
|
wsMainHandler.post(() -> sendNotify(text));
|
||||||
} else {
|
} else {
|
||||||
|
@ -290,7 +290,8 @@
|
|||||||
android:id="@+id/rl_public_code"
|
android:id="@+id/rl_public_code"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:visibility="gone">
|
android:visibility="gone"
|
||||||
|
tools:visibility="visible">
|
||||||
|
|
||||||
<com.github.mmin18.widget.RealtimeBlurView
|
<com.github.mmin18.widget.RealtimeBlurView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -299,24 +300,32 @@
|
|||||||
app:realtimeOverlayColor="#8000" />
|
app:realtimeOverlayColor="#8000" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:id="@+id/tv_public_code_hint"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerInParent="true"
|
android:layout_centerInParent="true"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="关注公众号继续阅读"
|
android:text="关注公众号继续阅读"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:textSize="@dimen/text_20"
|
android:textSize="@dimen/text_20"
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold"
|
||||||
|
tools:textColor="@color/black" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/btn_public"
|
android:id="@+id/btn_public"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_below="@id/tv_public_code_hint"
|
||||||
android:layout_marginLeft="20dp"
|
android:layout_alignLeft="@id/tv_public_code_hint"
|
||||||
android:layout_marginRight="20dp"
|
android:layout_alignRight="@id/tv_public_code_hint"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginTop="20dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
android:layout_marginBottom="10dp"
|
android:layout_marginBottom="10dp"
|
||||||
android:background="@drawable/sel_btn_submit_no_size"
|
android:background="@drawable/sel_btn_submit_no_size"
|
||||||
|
android:minHeight="0dp"
|
||||||
|
android:paddingTop="5dp"
|
||||||
|
android:paddingBottom="5dp"
|
||||||
android:text="去关注"
|
android:text="去关注"
|
||||||
android:textColor="@color/white" />
|
android:textColor="@color/white" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
BIN
modulemain/src/main/res/raw/no_kill.mp3
Executable file
BIN
modulemain/src/main/res/raw/no_kill.mp3
Executable file
Binary file not shown.
Loading…
Reference in New Issue
Block a user