BUG修改,极光推送添加

master
lijie 2023-08-08 17:32:34 +08:00
parent 9c7fd037ad
commit df9930f1ff
14 changed files with 180 additions and 34 deletions

View File

@ -19,6 +19,16 @@ android {
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk {
// SO
abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a'
}
manifestPlaceholders = [
JPUSH_PKGNAME: applicationId,
JPUSH_APPKEY : "2d2ceb987c93daf0a175f684", //JPush Appkey.
JPUSH_CHANNEL: "developer-default", //.
]
}
android.applicationVariants.all { variant ->
@ -40,6 +50,7 @@ android {
buildFeatures {
viewBinding true
}
}
@ -73,5 +84,8 @@ dependencies {
implementation 'com.github.nanchen2251:CompressHelper:1.0.5'
implementation 'com.google.zxing:core:3.4.0'
implementation 'com.journeyapps:zxing-android-embedded:3.6.0'
// JPush 5.0.0 5.0.0 JCore
implementation 'cn.jiguang.sdk:jpush:5.0.0'
}

View File

@ -6,8 +6,7 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!--在SDCard中创建与删除文件权限-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- 在SDCard中创建与删除文件权限 -->
<uses-permission
android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"
tools:ignore="ProtectedPermissions" />
@ -24,7 +23,6 @@
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<uses-permission
android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />
@ -48,30 +46,56 @@
android:theme="@style/Theme.AfricanFinance"
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:name=".activity.WebActivity"
android:exported="false"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize" />
<activity
android:name=".activity.LoginActivity"
android:exported="true"
android:screenOrientation="portrait">
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activity.MainActivity"
android:exported="true"
android:screenOrientation="portrait" />
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize" />
<activity
android:name=".activity.CustomCaptureActivity"
android:exported="true"
android:screenOrientation="portrait" />
<!-- Since JCore2.0.0 Required SDK核心功能 -->
<!-- 可配置android:process参数将Service放在其他进程中android:enabled属性不能是false -->
<!-- 这个是自定义Service要继承极光JCommonService可以在更多手机平台上使得推送通道保持的更稳定 -->
<service
android:name=".service.MyJpushService"
android:enabled="true"
android:exported="false"
android:process=":pushcore">
<intent-filter>
<action android:name="cn.jiguang.user.service.action" />
</intent-filter>
</service>
<!-- Required since 3.0.7 -->
<!-- 新的 tag/alias 接口结果返回需要开发者配置一个自定的广播 -->
<!-- 3.3.0开始所有事件将通过该类回调 -->
<!-- 该广播需要继承 JPush 提供的 JPushMessageReceiver 类, 并如下新增一个 Intent-Filter -->
<receiver
android:name=".service.MyJpushReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" />
<category android:name="com.cmx.wanhui" />
</intent-filter>
</receiver>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.cmx.wanhui.fileProvider"

View File

@ -1,12 +1,14 @@
package com.cmx.wanhui.activity
import android.Manifest
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
import android.text.TextUtils
import android.util.Log
import android.view.View
import android.view.inputmethod.InputMethodManager
import androidx.core.app.ActivityCompat
import com.cmx.wanhui.R
import com.cmx.wanhui.constant.Events
@ -15,6 +17,7 @@ import com.cmx.wanhui.model.LoginRes
import com.cmx.wanhui.retrofit.RetrofitAPIManager
import com.cmx.wanhui.utils.MyUtils.setAndroidNativeLightStatusBar
import com.cmx.wanhui.utils.MyUtils.setFullscreen
import com.cmx.wanhui.utils.SpUtils
import com.cmx.wanhui.utils.SpUtils.putString
import com.cmx.wanhui.view.ConfirmDialog
import com.lsxiao.apollo.core.Apollo
@ -45,7 +48,7 @@ class LoginActivity : BaseActivity() {
return@OnClickListener
}
if (TextUtils.isEmpty(edt_password.text.toString().trim { it <= ' ' })) {
Toasty.info(this@LoginActivity, "请输入密码").show()
Toasty.info(this, "请输入密码").show()
return@OnClickListener
}
toLogin()
@ -91,6 +94,7 @@ class LoginActivity : BaseActivity() {
if (response.isSuccessful && response.body()!!.code == 0) {
putString(this@LoginActivity, "token", response.body()!!.access_token)
putString(this@LoginActivity, "admin", response.body()!!.is_admin)
putString(this@LoginActivity, "sign", response.body()!!.sign)
val intent = Intent(this@LoginActivity, MainActivity::class.java)
startActivity(intent)
finish()

View File

@ -9,8 +9,10 @@ import androidx.annotation.RequiresApi
import androidx.navigation.NavController
import androidx.navigation.Navigation
import androidx.navigation.ui.NavigationUI
import cn.jpush.android.api.JPushInterface
import com.cmx.wanhui.R
import com.cmx.wanhui.constant.Events
import com.cmx.wanhui.utils.SpUtils
import com.cmx.wanhui.view.ConfirmDialog
import com.cmx.wanhui.view.ConfirmDialog.*
import com.google.zxing.integration.android.IntentIntegrator
@ -28,6 +30,7 @@ class MainActivity : BaseActivity() {
navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_main)
NavigationUI.setupWithNavController(nav_view, navController!!)
nav_view.itemIconTintList = null
JPushInterface.setAlias(this, 1, SpUtils.getString(this, "sign"))
}

View File

@ -2,6 +2,7 @@ package com.cmx.wanhui.activity
import android.app.Application
import android.content.Context
import cn.jpush.android.api.JPushInterface
import com.lsxiao.apollo.core.Apollo
import io.reactivex.android.schedulers.AndroidSchedulers
@ -10,6 +11,8 @@ class MyApplication : Application() {
super.onCreate()
mInstance = this
Apollo.init(AndroidSchedulers.mainThread(), this)
JPushInterface.setDebugMode(true)
JPushInterface.init(this)
}
override fun attachBaseContext(base: Context) {

View File

@ -62,6 +62,7 @@ interface Events {
* 原生返回_发送给web返回
*/
const val JS_OPEN_WEB_BACK = "js_open_web_back"
/**
* web无法在返回退出APP
*/

View File

@ -8,6 +8,7 @@ class LoginRes {
* is_admin : 1
*/
var code = 0
var sign: String? = null
var message: String? = null
var access_token: String? = null
var is_admin: String? = null

View File

@ -0,0 +1,105 @@
package com.cmx.wanhui.service;
import android.app.Notification;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import com.lsxiao.apollo.core.Apollo;
import com.lsxiao.apollo.core.contract.ApolloBinder;
import cn.jpush.android.api.CustomMessage;
import cn.jpush.android.api.JPushMessage;
import cn.jpush.android.api.NotificationMessage;
import cn.jpush.android.service.JPushMessageReceiver;
/**
* @author lyh
*/
public class MyJpushReceiver extends JPushMessageReceiver {
private static final String TAG = "自定义消息";
@Override
public Notification getNotification(Context context, NotificationMessage notificationMessage) {
Log.e("getNotification", "getNotification");
return null;
}
@Override
public void onMessage(Context context, CustomMessage customMessage) {
//c.a().a(context, var2);
String extra = customMessage.extra;
Log.e("融云自定义消息", extra);
Log.e("融云自定义消息Id", customMessage.messageId);
// if (!TextUtils.isEmpty(extra)) {
// try {
// MsgExtraBean bean = new Gson().fromJson(extra, MsgExtraBean.class);
// MsgExtraDetBean beanDet = new Gson().fromJson(bean.getMsg(), MsgExtraDetBean.class);
// Apollo.emit(Events.JPUSH_MSG, new MsgDetBean(customMessage.messageId, "1", beanDet.getExtras().getClinicId()));
//
// } catch (Exception e) {
// Log.e("3333", "3333");
// }
// }
//
// if (!TextUtils.isEmpty(extra)) {
// Gson gson = new Gson();
// RtcInUserBean jpushRongcloudMessage = gson.fromJson(extra, RtcInUserBean.class);
// String appPackageName = RxAppTool.getAppPackageName(context);
// int operatingStatus = AppContext.operatingStatus(context, appPackageName, appPackageName + ".ui.MainActivity");
// if (0 == operatingStatus) {
// //APP不存在
// Log.d("我是APP", "我不运行");
// Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(RxAppTool.getAppPackageName(context));
// launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
// context.startActivity(launchIntent);
// } else if (1 == operatingStatus) {
// //前台运行
//
// } else if (2 == operatingStatus) {
// //前台运行
//
// } else if (3 == operatingStatus) {
// //后台运行
// Log.d("我是APP", "我在后台运行");
// Intent mainIntent = new Intent(context, MainActivity.class);
// //将MainAtivity的launchMode设置成SingleTask, 或者在下面flag中加上Intent.FLAG_CLEAR_TOP,
// //如果Task栈中有MainActivity的实例就会把它移到栈顶把在它之上的Activity都清理出栈
// //如果Task栈不存在MainActivity实例则在栈顶创建
// mainIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// context.startActivity(mainIntent);
// }
// }
}
@Override
public void onNotifyMessageOpened(Context context, NotificationMessage notificationMessage) {
// Apollo.emit(Events.JPUSH_MSG_CLICK, notificationMessage.msgId);
// Log.e("onNotifyMessageOpened", notificationMessage.toString());
}
@Override
public void onNotifyMessageArrived(Context context, NotificationMessage notificationMessage) {
Log.e("onNotifyMessageArrived", "onNotifyMessageArrived");
//收到消息
ApolloBinder bind = Apollo.bind(context);
//c.a().a(context, notificationMessage, "cn.jpush.android.intent.NOTIFICATION_RECEIVED");
String notificationExtras = notificationMessage.notificationExtras;
//if (notificationExtras.indexOf("com.smxy.demo.push.doamin.Invitation") >= 0) {
if (!TextUtils.isEmpty(notificationExtras)) {
//Apollo.emit(Events.JPUSH_INVITATION_MESSAGE, jpushInvitationNoticeData);
}
if (bind != null) {
bind.unbind();
}
}
@Override
public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {
super.onAliasOperatorResult(context, jPushMessage);
Log.e("onAliasOperatorResult: ", "onAliasOperatorResult");
}
}

View File

@ -0,0 +1,7 @@
package com.cmx.wanhui.service
import cn.jpush.android.service.JCommonService
class MyJpushService : JCommonService() {
}

View File

@ -29,9 +29,8 @@ open class BaseFragment : Fragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requireActivity().window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
mBaseLoadingDialog = BaseLoadingDialog(activity)
MyUtils.setFullscreen(requireActivity(), false, false)
MyUtils.setAndroidNativeLightStatusBar(requireActivity(), true)
mApolloBinder = Apollo.bind(this)
}
@ -40,14 +39,14 @@ open class BaseFragment : Fragment() {
* 相关属性设置
*/
fun setWebView(webView: WebView) {
val webSettings = webView!!.settings
val webSettings = webView.settings
webSettings.javaScriptEnabled = true
webSettings.cacheMode = WebSettings.LOAD_NO_CACHE
webSettings.domStorageEnabled = true
webSettings.allowFileAccess = true //文件访问
webSettings.allowFileAccessFromFileURLs = true
webView!!.addJavascriptInterface(AndroidtoJs(), "AndroidtoJs")
webView!!.webViewClient = object : WebViewClient() {
webView.addJavascriptInterface(AndroidtoJs(), "AndroidtoJs")
webView.webViewClient = object : WebViewClient() {
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
super.onPageStarted(view, url, favicon)
showDialog()

View File

@ -1,6 +1,5 @@
package com.cmx.wanhui.ui;
import static com.cmx.wanhui.constant.Events.SERVER_URL;
import android.app.Activity;
import android.content.ClipData;
@ -15,30 +14,17 @@ import android.view.View;
import android.view.ViewGroup;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import com.cmx.wanhui.activity.LoginActivity;
import com.cmx.wanhui.constant.Events;
import com.cmx.wanhui.databinding.FragmentHomeBinding;
import com.cmx.wanhui.model.QRBean;
import com.cmx.wanhui.utils.AndroidtoJs;
import com.cmx.wanhui.utils.L;
import com.cmx.wanhui.utils.MyUtils;
import com.cmx.wanhui.view.BaseLoadingDialog;
import com.cmx.wanhui.view.ConfirmDialog;
import com.google.gson.Gson;
import com.lsxiao.apollo.core.Apollo;
import com.lsxiao.apollo.core.annotations.Receive;
import com.lsxiao.apollo.core.contract.ApolloBinder;
import java.io.File;
import java.io.IOException;
@ -133,7 +119,6 @@ public class HomeFragment extends BaseFragment {
return imageFile;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode != INPUT_FILE_REQUEST_CODE || mUploadMessage == null) {

View File

@ -33,7 +33,6 @@
android:hint="请输入用户名"
android:paddingStart="10dip"
android:singleLine="true"
android:text="wanhui"
android:textColorHint="#919191"
android:textSize="16sp" />
<!-- wanhui-->
@ -52,7 +51,6 @@
android:inputType="textPassword"
android:paddingStart="10dip"
android:singleLine="true"
android:text="123456"
android:textColorHint="#919191"
android:textSize="16sp" />

View File

@ -11,4 +11,6 @@
<color name="green_theme_light">#ff00be47</color>
<color name="base_col">#1890FF</color>
<color name="title_col">#FAFAFA</color>
</resources>

View File

@ -2,9 +2,9 @@
<!-- Base application theme. -->
<style name="Theme.AfricanFinance" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/green_theme_light</item>
<item name="colorPrimaryVariant">@color/green_theme_light</item>
<item name="colorOnPrimary">@color/white</item>
<item name="colorPrimary">@color/title_col</item>
<item name="colorPrimaryVariant">@color/title_col</item>
<item name="colorOnPrimary">@color/title_col</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/green_theme_light</item>
<item name="colorSecondaryVariant">@color/green_theme_light</item>