Commit 972d8d8b by jeffrey

1.3 逻辑优化

parent 09ff24fa
......@@ -22,8 +22,8 @@ android {
applicationId "com.xf.weixinclick"
minSdkVersion 16
targetSdkVersion 25
versionCode 3
versionName "1.2"
versionCode 4
versionName "1.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
......
......@@ -66,6 +66,7 @@
android:name=".NewService"
android:enabled="true"
android:exported="true"
android:process=":remote"
android:label="@string/app_name"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
......
......@@ -61,7 +61,7 @@ public class MainActivity extends BaseActivity {
@Override
void initAction() {
Log.d("fei","测试下魅族log");
HeartBeatAction.get().start();
......@@ -119,14 +119,14 @@ public class MainActivity extends BaseActivity {
@Override
public void onClick(View v) {
// WeChatStatus.receiverMsg();
Intent intent = new Intent();
//// 报名该有activity
ComponentName cmp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI");
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setComponent(cmp);
startActivity(intent);
// Intent intent = new Intent();
// //// 报名该有activity
// ComponentName cmp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI");
// intent.setAction(Intent.ACTION_MAIN);
// intent.addCategory(Intent.CATEGORY_LAUNCHER);
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// intent.setComponent(cmp);
// startActivity(intent);
new Thread(new Runnable() {
......@@ -142,7 +142,9 @@ public class MainActivity extends BaseActivity {
// msg.setQr_addr("https://weapp-dev.wangjia.com/qr.jpg?dd=1");
msg.setUnique_id("1111111111111");
msg.setTime_config(new Gson().fromJson("{\"qrcode_timeout\":60,\"after_open_weixin_index_delay\":2000,\"after_open_weixin_file_helper_delay\":6000,\"after_paste_message_delay\":2000,\"after_send_message_delay\":2000,\"after_click_message_delay\":5000,\"long_press_qrcode_delay\":4000,\"after_click_decode_button_delay\":5000,\"after_click_confirm_button_delay\":3000}", DelayBean.class));
EventBus.getDefault().post(msg);
// EventBus.getDefault().post(msg);
startWorkService(MainActivity.this,msg);
}
}).start();
......@@ -151,6 +153,13 @@ public class MainActivity extends BaseActivity {
}
public static void startWorkService(Context context,ReceiverMsg msg){
Intent intent = new Intent(context,NewService.class);
intent.putExtra(NewService.PARAMS_MSG,msg);
context.startService(intent);
}
public static String getLocalVersionName(Context ctx) {
String localVersion = "";
try {
......
package com.xf.weixinclick.bean;
import java.io.Serializable;
/**
* 创建日期:2018/3/6 on 15:20
* 描述:
......@@ -25,7 +27,7 @@ package com.xf.weixinclick.bean;
//// 点击确定登录按钮延迟,单位毫秒,备注:等待加载公众号登录成功界面,此时发送回调通知公众号登录成功
// 'after_click_confirm_button_delay' => 3000,
public class DelayBean {
public class DelayBean implements Serializable {
int qrcode_timeout;
int after_open_weixin_index_delay;
int after_open_weixin_file_helper_delay;
......
......@@ -11,6 +11,7 @@ import android.util.Log;
import com.alibaba.sdk.android.push.MessageReceiver;
import com.alibaba.sdk.android.push.notification.CPushMessage;
import com.google.gson.Gson;
import com.xf.weixinclick.MainActivity;
import com.xf.weixinclick.NewService;
import com.xf.weixinclick.R;
import com.xf.weixinclick.bean.msg.ReceiverMsg;
......@@ -47,39 +48,34 @@ public class MyMessageReceiver extends MessageReceiver {
@Override
public void onMessage(final Context context, final CPushMessage cPushMessage) {
Log.e("MyMessageReceiver", "onMessageaaa "+cPushMessage.getAppId());
Log.e("MyMessageReceiver", "onMessageaaa "+cPushMessage.getTraceInfo().toString());
Log.e("MyMessageReceiver", "onMessageaaa " + cPushMessage.getAppId());
Log.e("MyMessageReceiver", "onMessageaaa " + cPushMessage.getTraceInfo().toString());
Log.e("MyMessageReceiver", "onMessage, messageId: " + cPushMessage.getMessageId()
+ ", title: " + cPushMessage.getTitle()
+ ", content:" + cPushMessage.getContent());
Intent intent = new Intent();
ComponentName cmp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI");// 报名该有activity
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setComponent(cmp);
myApplication.getInstence().startActivity(intent);
new Thread(new Runnable() {
@Override
public void run() {
ReceiverMsg msg = new Gson().fromJson(cPushMessage.getContent(), ReceiverMsg.class);
long second = System.currentTimeMillis()/1000 - msg.getPushed_at() ;
if (second < msg.getTime_config().getQrcode_timeout()){
try {
Thread.sleep(msg.getTime_config().getAfter_open_weixin_index_delay());
} catch (InterruptedException e) {
e.printStackTrace();
}
NewService.showToast(context,String.format("接收到消息,时间:%d秒前",second));
EventBus.getDefault().post(msg);
}else {
NewService.showToast(context,String.format("接收到消息,任务超时,时间:%d秒前",second));
}
NewService.showToast(context,String.format("origin_id:%s,unique_id:%s",msg.getOrigin_id(),msg.getUnique_id()));
// Intent intent = new Intent();
// ComponentName cmp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI");// 报名该有activity
// intent.setAction(Intent.ACTION_MAIN);
// intent.addCategory(Intent.CATEGORY_LAUNCHER);
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// intent.setComponent(cmp);
// myApplication.getInstence().startActivity(intent);
ReceiverMsg msg = new Gson().fromJson(cPushMessage.getContent(), ReceiverMsg.class);
long second = System.currentTimeMillis() / 1000 - msg.getPushed_at();
if (second < msg.getTime_config().getQrcode_timeout()) {
try {
Thread.sleep(msg.getTime_config().getAfter_open_weixin_index_delay());
} catch (InterruptedException e) {
e.printStackTrace();
}
}).start();
NewService.showToast(context, String.format("接收到消息,时间:%d秒前", second));
// EventBus.getDefault().post(msg);
MainActivity.startWorkService(context, msg);
} else {
NewService.showToast(context, String.format("接收到消息,任务超时,时间:%d秒前", second));
}
NewService.showToast(context, String.format("origin_id:%s,unique_id:%s", msg.getOrigin_id(), msg.getUnique_id()));
// showNotify(context);
......@@ -109,7 +105,7 @@ public class MyMessageReceiver extends MessageReceiver {
}
private void showNotify(Context context){
private void showNotify(Context context) {
Calendar calendar = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
String strTime = df.format(calendar.getTime());
......@@ -117,10 +113,10 @@ public class MyMessageReceiver extends MessageReceiver {
Notification notification = new NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("微信click 有新消息")
.setContentText( "时间 " + strTime )
.setContentText("时间 " + strTime)
.build();
NotificationManager notifyManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notifyManager.notify(1,notification);
notifyManager.notify(1, notification);
}
......
package com.xf.weixinclick.utils;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import com.xf.weixinclick.MainActivity;
import com.xf.weixinclick.R;
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
/**
* 创建日期:2018/3/28 on 9:52
* 描述:
* 作者:Li
*/
public class NotificationUtils {
public static final int FOREGROUND_NOTIFICATION_ID = 88;
public static void foreground(Context context, Service service){
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
//设置小图标
.setSmallIcon(R.mipmap.ic_launcher)
//设置通知标题
.setContentTitle("我正在运行")
.setContentIntent(PendingIntent.getActivity(context,1,new Intent(context, MainActivity.class),FLAG_UPDATE_CURRENT))
//设置通知内容
.setContentText("有这个说明正在运行");
Notification notification = builder.build();
service.startForeground(FOREGROUND_NOTIFICATION_ID,notification);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment