Commit 4b4eecc5 by amateur

1

1 parent 489ab2cd
......@@ -30,6 +30,31 @@ android {
]
}
}
manifestPlaceholders = [
JPUSH_PKGNAME : applicationId,
JPUSH_APPKEY : "ef86f246857d981193987dee",//值来自开发者平台取得的AppKey
JPUSH_CHANNEL : "default_developer",
//meizu_config_start
// MEIZU_APPKEY : "MZ-魅族的APPKEY",
// MEIZU_APPID : "MZ-魅族的APPID",
//meizu_config_end
//xiaomi_config_start
XIAOMI_APPID : "MI-小米的APPID",
XIAOMI_APPKEY : "MI-小米的APPKEY",
//xiaomi_config_end
//oppo_config_start
// OPPO_APPKEY : "OP-oppo的APPKEY",
// OPPO_APPID : "OP-oppo的APPID",
// OPPO_APPSECRET: "OP-oppo的APPSECRET",
// //oppo_config_end
// //vivo_config_start
// VIVO_APPKEY : "vivo的APPKEY",
// VIVO_APPID : "vivo的APPID",
//vivo_config_end
]
}
buildTypes {
......@@ -81,6 +106,8 @@ dependencies {
implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.2'
implementation 'com.github.bumptech.glide:glide:4.12.0'
implementation 'org.greenrobot:eventbus:3.2.0'
implementation 'cn.jiguang.sdk:jpush:4.3.0' // 此处以JPush 4.3.0 版本为例。
implementation 'cn.jiguang.sdk:jcore:2.9.0' // 此处以JCore 2.9.0 版本为例。
implementation "io.objectbox:objectbox-android:$objectboxVersion"
annotationProcessor "io.objectbox:objectbox-processor:$objectboxVersion"
implementation 'me.jessyan:autosize:1.2.1'
......
......@@ -55,3 +55,14 @@
# OkHttp platform used only on JVM and when Conscrypt dependency is available.
-dontwarn okhttp3.internal.platform.ConscryptPlatform
-dontwarn org.conscrypt.ConscryptHostnameVerifier
#jpush
-dontoptimize
-dontpreverify
-dontwarn cn.jpush.**
-keep class cn.jpush.** { *; }
-keep class * extends cn.jpush.android.helpers.JPushMessageReceiver { *; }
-dontwarn cn.jiguang.**
-keep class cn.jiguang.** { *; }
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.whaty.nafmii">
<permission
android:name="${applicationId}.permission.JPUSH_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="${applicationId}.permission.JPUSH_MESSAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
......@@ -23,6 +29,8 @@
android:supportsRtl="true"
android:theme="@style/Nafmii.Fullscreen"
android:usesCleartextTraffic="true">
<activity android:name=".activity.JPushTestActivity"></activity>
<meta-data
android:name="design_width_in_dp"
android:value="360" />
......@@ -35,6 +43,7 @@
android:theme="@style/Nafmii.Fullscreen.NoTitleBar.Main">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
......@@ -57,16 +66,39 @@
<activity
android:name=".activity.OutsideWebviewActivity"
android:theme="@style/Nafmii.Fullscreen.NoTitleBar" />
<activity android:name=".activity.InputUrlActivity"></activity>
<activity android:name=".activity.InputUrlActivity" />
<activity
android:name=".activity.TestHomeActivity"
android:theme="@style/Nafmii.Fullscreen.NoTitleBar"></activity>
<activity android:name=".activity.AdvertisementWebviewActvity"></activity>
android:theme="@style/Nafmii.Fullscreen.NoTitleBar" />
<activity android:name=".activity.AdvertisementWebviewActvity" />
<service
android:name="com.tencent.smtt.export.external.DexClassLoaderProviderService"
android:label="dexopt"
android:process=":dexopt" />
<service
android:name="com.polysoft.nafmii.jpush.JPushService"
android:enabled="true"
android:exported="false"
android:process=":pushcore"
tools:ignore="Instantiatable">
<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="com.polysoft.nafmii.jpush.JPushReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
<provider
android:name="androidx.core.content.FileProvider"
......
package com.polysoft.nafmii.jpush;
import com.polysoft.nafmii.utils.CtxUtils;
import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.data.JPushLocalNotification;
public class JPushMgr {
// 是否停止推送
public static boolean isPushStopped() {
return JPushInterface.isPushStopped(CtxUtils.getApplication());
}
// 是否可以在通知栏上展示
public static boolean isNotification() {
return JPushInterface.isNotificationEnabled(CtxUtils.getApplication()) == 1;
}
// 发送本地通知栏信息
public static void snedLoaclNotice(JPushLocalNotification ln) {
if (isNotification()) {
JPushInterface.addLocalNotification(CtxUtils.getApplication(), ln);
}
}
// 获取注册到极光的id
public static String getRegistrationID() {
return JPushInterface.getRegistrationID(CtxUtils.getApplication());
}
public static void setAlias(String alias) {
String millis = String.valueOf(System.currentTimeMillis());
String val = millis.substring(millis.length() - 5, millis.length());
int code = Integer.parseInt(val);
JPushInterface.setAlias(CtxUtils.getApplication(), code, alias);
}
}
package com.polysoft.nafmii.jpush;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import cn.jpush.android.api.CmdMessage;
import cn.jpush.android.api.CustomMessage;
import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.api.JPushMessage;
import cn.jpush.android.api.NotificationMessage;
import cn.jpush.android.service.JPushMessageReceiver;
public class JPushReceiver extends JPushMessageReceiver {
private static final String TAG = "PushMessageReceiver";
@Override
public void onMessage(Context context, CustomMessage customMessage) {
Log.e(TAG, "[onMessage] " + customMessage);
Intent intent = new Intent("com.jiguang.demo.message");
intent.putExtra("msg", customMessage.message);
context.sendBroadcast(intent);
}
@Override
public void onNotifyMessageOpened(Context context, NotificationMessage message) {
Log.e(TAG, "[onNotifyMessageOpened] " + message);
// try{
// //打开自定义的Activity
// Intent i = new Intent(context, TestActivity.class);
// Bundle bundle = new Bundle();
// bundle.putString(JPushInterface.EXTRA_NOTIFICATION_TITLE,message.notificationTitle);
// bundle.putString(JPushInterface.EXTRA_ALERT,message.notificationContent);
// i.putExtras(bundle);
// i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP );
// context.startActivity(i);
// }catch (Throwable throwable){
//
// }
}
@Override
public void onMultiActionClicked(Context context, Intent intent) {
Log.e(TAG, "[onMultiActionClicked] 用户点击了通知栏按钮");
String nActionExtra = intent.getExtras().getString(JPushInterface.EXTRA_NOTIFICATION_ACTION_EXTRA);
//开发者根据不同 Action 携带的 extra 字段来分配不同的动作。
if (nActionExtra == null) {
Log.d(TAG, "ACTION_NOTIFICATION_CLICK_ACTION nActionExtra is null");
return;
}
if (nActionExtra.equals("my_extra1")) {
Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮一");
} else if (nActionExtra.equals("my_extra2")) {
Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮二");
} else if (nActionExtra.equals("my_extra3")) {
Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮三");
} else {
Log.e(TAG, "[onMultiActionClicked] 用户点击通知栏按钮未定义");
}
}
@Override
public void onNotifyMessageArrived(Context context, NotificationMessage message) {
Log.e(TAG, "[onNotifyMessageArrived] " + message);
}
@Override
public void onNotifyMessageDismiss(Context context, NotificationMessage message) {
Log.e(TAG, "[onNotifyMessageDismiss] " + message);
}
@Override
public void onRegister(Context context, String registrationId) {
Log.e(TAG, "[onRegister] " + registrationId);
Intent intent = new Intent("com.jiguang.demo.register");
context.sendBroadcast(intent);
}
@Override
public void onConnected(Context context, boolean isConnected) {
Log.e(TAG, "[onConnected] " + isConnected);
}
@Override
public void onCommandResult(Context context, CmdMessage cmdMessage) {
Log.e(TAG, "[onCommandResult] " + cmdMessage);
}
// @Override
// public void onTagOperatorResult(Context context, JPushMessage jPushMessage) {
// TagAliasOperatorHelper.getInstance().onTagOperatorResult(context,jPushMessage);
// super.onTagOperatorResult(context, jPushMessage);
// }
//
// @Override
// public void onCheckTagOperatorResult(Context context, JPushMessage jPushMessage) {
// TagAliasOperatorHelper.getInstance().onCheckTagOperatorResult(context,jPushMessage);
// super.onCheckTagOperatorResult(context, jPushMessage);
// }
//
@Override
public void onAliasOperatorResult(Context context, JPushMessage jPushMessage) {
super.onAliasOperatorResult(context, jPushMessage);
Log.d(TAG, "onAliasOperatorResult: " + jPushMessage.toString());
}
//
// @Override
// public void onMobileNumberOperatorResult(Context context, JPushMessage jPushMessage) {
// TagAliasOperatorHelper.getInstance().onMobileNumberOperatorResult(context,jPushMessage);
// super.onMobileNumberOperatorResult(context, jPushMessage);
// }
@Override
public void onNotificationSettingsCheck(Context context, boolean isOn, int source) {
super.onNotificationSettingsCheck(context, isOn, source);
Log.e(TAG, "[onNotificationSettingsCheck] isOn:" + isOn + ",source:" + source);
}
}
package com.polysoft.nafmii.jpush;
import cn.jpush.android.service.JCommonService;
public class JPushService extends JCommonService {
}
......@@ -6,6 +6,7 @@ import com.polysoft.nafmii.utils.CtxUtils;
import com.polysoft.nafmii.utils.ExecutorUtils;
import com.polysoft.nafmii.utils.ZipUtils;
import cn.jpush.android.api.JPushInterface;
import me.jessyan.autosize.AutoSizeConfig;
import ren.yale.android.cachewebviewlib.WebViewCacheInterceptor;
import ren.yale.android.cachewebviewlib.WebViewCacheInterceptorInst;
......@@ -24,6 +25,8 @@ public class MyApplication extends Application {
builder.setDebug(BuildConfig.DEBUG);
WebViewCacheInterceptorInst.getInstance().init(builder);
JPushInterface.setDebugMode(true);
JPushInterface.init(this);
ExecutorUtils.io(() -> {
ZipUtils.unZipDistAssets();
......
......@@ -17,6 +17,8 @@ import java.util.Map;
public class HomeActivity extends WebviewActivity implements View.OnClickListener, ModulesFragmentMgr.OnChangeModuleListener {
private static final String TAG = HomeActivity.class.getName();
private ModulesFragmentMgr modulesMgr;
private HashMap<ModulesEnum, RadioButton> moduleViewsMap;
private View footerView;
......@@ -28,6 +30,7 @@ public class HomeActivity extends WebviewActivity implements View.OnClickListene
this.initHomeModule();
}
private void initView() {
this.footerView = super.findViewById(R.id.home_footer_group);
this.footerView.setVisibility(View.VISIBLE);
......
......@@ -46,10 +46,10 @@ public class InputUrlActivity extends AppCompatActivity {
private void jumpHome() {
EditText input = findViewById(R.id.input_url);
String url = input.getText().toString();
if (TextUtils.isEmpty(url)) {
ToastUtils.showLong("url 不能为空");
return;
}
// if (TextUtils.isEmpty(url)) {
// ToastUtils.showLong("url 不能为空");
// return;
// }
RadioButton button1 = findViewById(R.id.input_channel_1);
RadioButton button2 = findViewById(R.id.input_channel_2);
......
package com.whaty.nafmii.activity;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import com.polysoft.nafmii.utils.ToastUtils;
import com.polysoft.nafmii.webview.JsInterfaceHandler;
import com.whaty.nafmii.R;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.data.JPushLocalNotification;
public class JPushTestActivity extends AppCompatActivity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_jpush_test);
findViewById(R.id.jpush_local_btn).setOnClickListener(this);
findViewById(R.id.jpush_btn_alias).setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.jpush_local_btn:
this.localNotice();
break;
case R.id.jpush_btn_alias:
this.setAlias();
break;
default:
break;
}
}
private void localNotice() {
String registrationID = JPushInterface.getRegistrationID(this);
if (TextUtils.isEmpty(registrationID)) {
ToastUtils.showLong("registrationID is null");
return;
}
boolean pushStopped = JPushInterface.isPushStopped(this);
if (JPushInterface.isNotificationEnabled(this) == 1) {
buildLocalNotification(this,"本地标题", "通知内容");
}
}
private void setAlias() {
JPushInterface.setAlias(this, 10000, "123");
}
public void buildLocalNotification(Context context, String tittle, String content){
JPushLocalNotification ln = new JPushLocalNotification();
ln.setBuilderId(0);
ln.setContent(content);
ln.setTitle(tittle);
long id = System.currentTimeMillis()/1000;
ln.setNotificationId(id) ;
ln.setBroadcastTime(System.currentTimeMillis());
Map<String , Object> map = new HashMap<String, Object>() ;
map.put("name", "jpush") ;
map.put("test", "111") ;
JSONObject json = new JSONObject(map) ;
ln.setExtras(json.toString()) ;
JPushInterface.addLocalNotification(context, ln);
ToastUtils.showLong("添加本地通知,notification_id:" + id);
}
}
\ No newline at end of file
......@@ -19,6 +19,8 @@ import com.polysoft.nafmii.viewmodel.AdvertisementViewModel;
import com.polysoft.nafmii.webview.X5Core;
import com.whaty.nafmii.R;
import cn.jpush.android.api.JPushInterface;
public class MainActivity extends BaseActivity {
private AdvertisementViewModel.LiveData mAdvertisementData;
......@@ -40,6 +42,7 @@ public class MainActivity extends BaseActivity {
if (this.checkPermissionSetting()) {
X5Core.init();
JPushInterface.resumePush(this);
this.showLayout();
}
}
......@@ -56,7 +59,8 @@ public class MainActivity extends BaseActivity {
private void checkAndRequestPermission() {
String[] permissions = new String[]{
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.CAMERA
Manifest.permission.CAMERA,
Manifest.permission.READ_PHONE_STATE
};
PermissionUtils.requestMorePermissions(this, permissions);
}
......
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
tools:context=".activity.JPushTestActivity">
<Button
android:id="@+id/jpush_local_btn"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="本地发送通知"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/jpush_btn_alias"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="设置别名"
android:layout_marginBottom="10dp"
app:layout_constraintBottom_toTopOf="@+id/jpush_local_btn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!