用Jpush极光推送实现抓取特定某个用户Log到七牛云服务器

场景##

我们的app常常会出现某个特定用户的手机出现异常情况,(注意不是所有用户,特定机型特定用户)如果用友盟,那么多log你也抓不完 ,看不到log就无法解决问题。
那么问题来了,如何实现对特定某个用户实时抓取log呢,比如我就想要用户id为 lixiaodaoaaa这个用户的日志信息呢?(用户自己不知道我们要抓她的log,对了你可以干点邪恶的事)
发送通知给他,而接收到通知,设备可以啥都不提示,可以干点邪恶的事,不过我想想还是算了。(他的log.我们默认log都会用LogUtils保存在特定目录下。)

解决方法##

首先我们知道极光推送可以对特定设备实现特定用户 发送自定义消息,那么为何不可以向指定的用户发送推送消息,当该用户接收到消息后(当接收到消息,用户自己不知道,我们悄悄处理)
,上传文件到七牛云服务器
上呢?

操作方法##

根据设备名称,我们可以在Jpush初始化的时候得到设备别名,我们就发送这个通知

代码里去处理一下##

创建自定义消息,可以不一定创建通知,用户可能不知道他收到了消息,但是我们程序可以知道当收到消息要做什么操作


  public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();
	Log.d(TAG, "[JPushReceiver] onReceive - " + intent.getAction() + ", extras: " + printBundle(bundle));
    if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
        String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);
        Log.d(TAG, "[JPushReceiver] 接收Registration Id : " + regId);

    } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
    	Log.d(TAG, "[JPushReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE));
		String pushMsg = bundle.getString(JPushInterface.EXTRA_MESSAGE);
		if (pushMsg.contains("upload")) {
			logFile = LogUtils.getLogFile(context);
			if (logFile == null) return;
			uploadLogToQiniuCloud(context,logFile);
			return;
		}
		if(StringUtils.isEmpty(pushMsg)){
			return;
		}
		createCustomerNotification(context, pushMsg);
    } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {

然后去看下七牛空间吧##

这样子,想啥时候得到数据,只需要发送一下通知,对这个用户。。就OK了##

原文地址:https://www.cnblogs.com/lixiaodaoaaa/p/4834998.html