Java Code Examples for android.view.accessibility.AccessibilityEvent#getParcelableData()

The following examples show how to use android.view.accessibility.AccessibilityEvent#getParcelableData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WechatAccService.java    From RedEnvelopeAssistant with MIT License 6 votes vote down vote up
/** handle notification notice */
@TargetApi(Build.VERSION_CODES.KITKAT)
public void handleNotificationChange(AccessibilityEvent event) {
	log( "handleNotificationChange eventtype:" + event.getEventType());
	if (event == null)
		return;
	
	if (!(event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED)) {
		return;
	}
	if (event.getParcelableData() instanceof Notification) {
		Notification notification = (Notification) event
				.getParcelableData();
		if (notification.tickerText != null
				&& notification.tickerText.toString().contains(getString(R.string.wechat_acc_service_red_envelope_notification_identification))) {
			log("来红包啦 get red envelope message");
			RedEnvelopeHelper.openNotification(event);
		}
	}
}
 
Example 2
Source File: NotificationUpdateServiceOld.java    From deskcon-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
        Notification not = (Notification) event.getParcelableData();
	
        	
		// permissions
		boolean send_other_notifications = sharedPrefs.getBoolean("send_other_notifications", false);
		ArrayList<String> whitelist = getNotificationWhitelist();
		String packagename = String.valueOf(event.getPackageName());
		
		if (not != null && send_other_notifications && whitelist.contains(packagename)) {
			Log.d("Notification: ", "new post");

			if (not.tickerText != null) {
				String text = not.tickerText.toString();
				startUpdateServiceCommand(text);
			}
		}
    }
}
 
Example 3
Source File: AccessibilityService.java    From AcDisplay with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    switch (event.getEventType()) {
        case AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED:
            Parcelable parcelable = event.getParcelableData();
            if (parcelable instanceof Notification) {
                if (Device.hasJellyBeanMR2Api()) {
                    // No need to use the accessibility service
                    // instead of NotificationListener.
                    return;
                }

                Notification notification = (Notification) parcelable;
                OpenNotification openNotification = OpenNotification.newInstance(notification);
                NotificationPresenter.getInstance().postNotificationFromMain(this, openNotification, 0);
            }
            break;
    }
}
 
Example 4
Source File: IdleState.java    From WaterMonitor with Apache License 2.0 6 votes vote down vote up
/**
 * @param nodeInfo
 * @param accessibilityEvent
 * @return If from notification ,msg format :{@link Constant#MONITOR_TAG} + ":real QQ No: "+{@link Constant#MONITOR_CMD_VIDEO}
 */
private String retrieveQQNumber(AccessibilityNodeInfo nodeInfo, AccessibilityEvent accessibilityEvent) {
    if (accessibilityEvent.getEventType() == TYPE_NOTIFICATION_STATE_CHANGED) {
        Parcelable data = accessibilityEvent.getParcelableData();
        if (data instanceof Notification) {
            if (((Notification) data).tickerText != null) {
                return ((Notification) data).tickerText.toString().split(":")[1];
            }
        }
    } else {
        List<AccessibilityNodeInfo> nodeInfos = nodeInfo.findAccessibilityNodeInfosByText(MONITOR_TAG);
        if (!AppUtils.isListEmpty(nodeInfos)) {
            String tag;
            for (AccessibilityNodeInfo info : nodeInfos) {
                if (BuildConfig.DEBUG) {
                    Log.d(TAG, "retrieveQQNumber: " + info.getText());
                }
                tag = (String) info.getText();
                if (!TextUtils.isEmpty(tag) && tag.contains(MONITOR_TAG)) {
                    return tag.substring(Constant.MONITOR_TAG.length());
                }
            }
        }
    }
    return Privacy.QQ_NUMBER;
}
 
Example 5
Source File: MD5_jni.java    From stynico with MIT License 6 votes vote down vote up
/** 打开通知栏消息 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void openNotify(AccessibilityEvent event)
{
	if (event.getParcelableData() == null || !(event.getParcelableData() instanceof Notification))
	{
		return;
	}
	// 将微信的通知栏消息打开
	Notification notification = (Notification) event.getParcelableData();
	PendingIntent pendingIntent = notification.contentIntent;
	try
	{
		pendingIntent.send();
	} catch (PendingIntent.CanceledException e)
	{
		e.printStackTrace();
	}
}
 
Example 6
Source File: dex_smali.java    From stynico with MIT License 6 votes vote down vote up
/** 打开通知栏消息*/
   private void openNotify(AccessibilityEvent event)
   {
       if (event.getParcelableData() == null || !(event.getParcelableData() instanceof Notification))
{
           return;
       }
       Notification notification = (Notification) event.getParcelableData();
       PendingIntent pendingIntent = notification.contentIntent;
       try
{
           pendingIntent.send();
       }
catch (PendingIntent.CanceledException e)
{
           e.printStackTrace();
       }
   }
 
Example 7
Source File: IdleState.java    From WaterMonitor with Apache License 2.0 6 votes vote down vote up
/**
 * retract monitor cmd from notification
 *
 * @param nodeInfo
 * @param accessibilityEvent
 * @return
 */
private boolean isNotificationMonitorMsg(AccessibilityNodeInfo nodeInfo, AccessibilityEvent accessibilityEvent) {
    if (accessibilityEvent.getEventType() == TYPE_NOTIFICATION_STATE_CHANGED) {
        if (BuildConfig.DEBUG) {
            Log.d(TAG, "isNotificationMonitorMsg: ");
        }
        Parcelable data = accessibilityEvent.getParcelableData();
        if (data instanceof Notification) {
            if (((Notification) data).tickerText != null) {
                return (((Notification) data).tickerText.toString().startsWith(MONITOR_TAG)
                        && ((Notification) data).tickerText.toString().endsWith(Constant.MONITOR_CMD_VIDEO));
            }
        }
    }
    return false;
}
 
Example 8
Source File: peService.java    From styT with Apache License 2.0 5 votes vote down vote up
/**
 * 描述:处理QQ状态栏
 * 作者:卜俊文
 * 邮箱:[email protected]
 * 日期:2017/11/1 下午1:49
 */
public void progressQQStatusBar(AccessibilityEvent event) {
    List<CharSequence> text = event.getText();
    //开始检索界面上是否有QQ红包的文本,并且他是通知栏的信息
    if (text != null && text.size() > 0) {
        for (CharSequence charSequence : text) {
            if (charSequence.toString().contains(QQConstant.QQ_ENVELOPE_KEYWORD)) {
                //说明存在红包弹窗,马上进去
                if (event.getParcelableData() != null && event.getParcelableData() instanceof Notification) {
                    Notification notification = (Notification) event.getParcelableData();
                    if (notification == null) {
                        return;
                    }
                    PendingIntent pendingIntent = notification.contentIntent;
                    if (pendingIntent == null) {
                        return;
                    }
                    try {
                        //要跳转之前,先进行解锁屏幕,然后再跳转,有可能你现在屏幕是锁屏状态,先进行解锁,然后打开页面,有密码的可能就不行了
                        wakeUpAndUnlock(HApp.context);
                        //跳转
                        pendingIntent.send();
                    } catch (PendingIntent.CanceledException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
 
Example 9
Source File: RedEnvelopeHelper.java    From RedEnvelopeAssistant with MIT License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static void openNotification(AccessibilityEvent event) {
    if( !(event.getParcelableData() instanceof Notification)) {
        return;
    }
    Notification notification = (Notification) event.getParcelableData();
    PendingIntent pendingIntent = notification.contentIntent;
    try {
        pendingIntent.send();
    } catch (PendingIntent.CanceledException e) {
        e.printStackTrace();
    }
}
 
Example 10
Source File: AccessibilityEventUtils.java    From talkback with Apache License 2.0 5 votes vote down vote up
/**
 * Extracts a {@link Notification} from an {@link AccessibilityEvent}.
 *
 * @param event The event to extract from.
 * @return The extracted Notification, or {@code null} on error.
 */
public static @Nullable Notification extractNotification(AccessibilityEvent event) {
  final Parcelable parcelable = event.getParcelableData();

  if (!(parcelable instanceof Notification)) {
    return null;
  }

  return (Notification) parcelable;
}
 
Example 11
Source File: AccessibilityEventUtils.java    From talkback with Apache License 2.0 5 votes vote down vote up
/** Returns whether the {@link AccessibilityEvent} contains {@link Notification} data. */
public static boolean isNotificationEvent(AccessibilityEvent event) {
  // Real notification events always have parcelable data.
  return event != null
      && event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED
      && event.getParcelableData() != null;
}
 
Example 12
Source File: BotifierAccessibilityService.java    From Botifier with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void onAccessibilityEvent(AccessibilityEvent event) {
if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
	Notification notification = (Notification) event.getParcelableData();
	if (notification == null ) {
       	return;
       }
	sendCmd(event, notification, NotificationEvents.NOTIFICATION_ADDED);
     }
  }
 
Example 13
Source File: AppCompatDlalog.java    From stynico with MIT License 5 votes vote down vote up
/**
    *
    * @param event
    */
   private void sendNotifacationReply(AccessibilityEvent event)
   {
       hasAction = true;
       if (event.getParcelableData() != null
    && event.getParcelableData() instanceof Notification)
{
           Notification notification = (Notification) event
	.getParcelableData();
           String content = notification.tickerText.toString();
           String[] cc = content.split(":");
           name = cc[0].trim();
           scontent = cc[1].trim();

        //   android.util.Log.i("maptrix", "sender name =" + name);
      //     android.util.Log.i("maptrix", "sender content =" + scontent);


           PendingIntent pendingIntent = notification.contentIntent;
           try
    {
               pendingIntent.send();
           }
    catch (PendingIntent.CanceledException e)
    {
               e.printStackTrace();
           }
       }
   }
 
Example 14
Source File: WechatService.java    From WechatHook-Dusan with Apache License 2.0 5 votes vote down vote up
private void handleNotificationEvent(AccessibilityEvent event) {
    Parcelable data = event.getParcelableData();
    if (data == null || !(data instanceof Notification)) {
        return;
    }
    List<CharSequence> texts = event.getText();
    if (!texts.isEmpty()) {
        String text = String.valueOf(texts.get(0));//包括微信名  :
        handleNotification(text, (Notification) data);
    }
}
 
Example 15
Source File: PushMonitorAccessibilityService.java    From NewsPushMonitor with Apache License 2.0 5 votes vote down vote up
@Override
public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
    int type = accessibilityEvent.getEventType();
    if (type != AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
        return;
    }

    String pkg = accessibilityEvent.getPackageName().toString();
    long time = accessibilityEvent.getEventTime();
    Notification notification = (Notification) accessibilityEvent.getParcelableData();
    List<CharSequence> texts = accessibilityEvent.getText();

    StringBuilder sb = new StringBuilder();
    for (CharSequence text : texts) {
        sb.append(text).append("###");
    }

    LogWriter.i(TAG, "onAccessibilityEvent "
            + "package=" + pkg
            + ",time=" + time
            + ",text=" + sb.toString());

    LogWriter.i(TAG, "Parse notification for " + pkg + " begin!");
    BaseNotificationParser notificationParser = NotificationParserFactory.getNotificationParser(pkg);
    BaseNotificationParser.NewsInfo newsInfo = notificationParser.parse(notification);
    LogWriter.i(TAG, "when:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(newsInfo.when));
    LogWriter.i(TAG, "ContentTitle:" + newsInfo.contentTitle);
    LogWriter.i(TAG, "ContentText:" + newsInfo.contentText);
    LogWriter.i(TAG, "Url:" + newsInfo.url);
    LogWriter.i(TAG, "Parse notification for " + pkg + " end!");
    LogWriter.i(TAG, "##################################################################");

    commitNewsInfoToServer(newsInfo);
    showNewsInfo(newsInfo);
}
 
Example 16
Source File: dex_smali.java    From styT with Apache License 2.0 5 votes vote down vote up
/**
 * 打开通知栏消息
 */
private void openNotify(AccessibilityEvent event) {
    if (event.getParcelableData() == null || !(event.getParcelableData() instanceof Notification)) {
        return;
    }
    Notification notification = (Notification) event.getParcelableData();
    PendingIntent pendingIntent = notification.contentIntent;
    try {
        pendingIntent.send();
    } catch (PendingIntent.CanceledException e) {
        e.printStackTrace();
    }
}
 
Example 17
Source File: dili.java    From styT with Apache License 2.0 5 votes vote down vote up
/**
 * 打开通知栏消息
 */
private void openNotify(AccessibilityEvent event) {
    if (event.getParcelableData() == null || !(event.getParcelableData() instanceof Notification)) {
        return;
    }
    Notification notification = (Notification) event.getParcelableData();
    PendingIntent pendingIntent = notification.contentIntent;
    try {
        pendingIntent.send();
    } catch (PendingIntent.CanceledException e) {
        e.printStackTrace();
    }
}
 
Example 18
Source File: RedPacketService.java    From styT with Apache License 2.0 5 votes vote down vote up
/**
 * 开启红包所在的聊天页面
 */
private void openWeChatPage(AccessibilityEvent event) {
    //A instanceof B 用来判断内存中实际对象A是不是B类型,常用于强制转换前的判断
    if (event.getParcelableData() != null && event.getParcelableData() instanceof Notification) {
        Notification notification = (Notification) event.getParcelableData();
        //打开对应的聊天界面
        PendingIntent pendingIntent = notification.contentIntent;
        try {
            pendingIntent.send();
        } catch (PendingIntent.CanceledException e) {
            e.printStackTrace();
        }
    }
}
 
Example 19
Source File: AccessibilityEventUtils.java    From brailleback with Apache License 2.0 4 votes vote down vote up
/**
 * @return If the <code>first</code> event is equal to the <code>second</code>.
 */
public static boolean eventEquals(AccessibilityEvent first, AccessibilityEvent second) {
    // TODO: The framework should implement AccessibilityEvent#equals()
    if (first == null || second == null) {
        return false;
    }
    if (first.getEventType() != second.getEventType()) {
        return false;
    }
    if (first.getPackageName() == null) {
        if (second.getPackageName() != null) {
            return false;
        }
    } else if (!first.getPackageName().equals(second.getPackageName())) {
        return false;
    }
    if (first.getClassName() == null) {
        if (second.getClassName() != null) {
            return false;
        }
    } else if (!first.getClassName().equals(second.getClassName())) {
        return false;
    }
    if (!first.getText().equals(second.getText())) {
        // The result of getText() is never null.
        return false;
    }
    if (first.getContentDescription() == null) {
        if (second.getContentDescription() != null) {
            return false;
        }
    } else if (!first.getContentDescription().equals(second.getContentDescription())) {
        return false;
    }
    if (first.getBeforeText() == null) {
        if (second.getBeforeText() != null) {
            return false;
        }
    } else if (!first.getBeforeText().equals(second.getBeforeText())) {
        return false;
    }
    if (first.getParcelableData() != null) {
        // Parcelable data may not implement equals() correctly.
        return false;
    }
    if (first.getAddedCount() != second.getAddedCount()) {
        return false;
    }
    if (first.isChecked() != second.isChecked()) {
        return false;
    }
    if (first.isEnabled() != second.isEnabled()) {
        return false;
    }
    if (first.getFromIndex() != second.getFromIndex()) {
        return false;
    }
    if (first.isFullScreen() != second.isFullScreen()) {
        return false;
    }
    if (first.getCurrentItemIndex() != second.getCurrentItemIndex()) {
        return false;
    }
    if (first.getItemCount() != second.getItemCount()) {
        return false;
    }
    if (first.isPassword() != second.isPassword()) {
        return false;
    }
    if (first.getRemovedCount() != second.getRemovedCount()) {
        return false;
    }
    if (first.getEventTime() != second.getEventTime()) {
        return false;
    }
    return true;
}
 
Example 20
Source File: NotificationListenerAccessibilityService.java    From heads-up with GNU General Public License v3.0 4 votes vote down vote up
@Override
   public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent)
{
       if (accessibilityEvent.getEventType() ==
		AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED)
	{
           try {
               if (Build.VERSION.SDK_INT >= 18) return;

               // Ignore toasts
               Notification notification = (Notification) accessibilityEvent.getParcelableData();
               if (notification == null) return;
               // Do not Ignore ongoing stuff if show non-cancelable feature is selected
               if ((notification.flags & Notification.FLAG_ONGOING_EVENT) != 0 && !PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).
                       getBoolean("show_non_cancelable", false)) return;

               DecisionMaker decisionMaker = new DecisionMaker();
               decisionMaker.handleActionAdd(notification,
                       accessibilityEvent.getPackageName().toString(),
                       null,
                       0,
                       null,
                       getApplicationContext(),
                       "accessibility");

           } catch (Exception e) {
               e.printStackTrace();
               try {
                   String report = e.getMessage();
                   if (report == null) report = "";
                   Writer writer = new StringWriter();
                   PrintWriter printWriter = new PrintWriter(writer);
                   e.printStackTrace(printWriter);
                   report = report.concat( writer.toString() );
                   SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                   if (preferences != null && report.length() > 0) {
                       SharedPreferences.Editor editor = preferences.edit();
                       editor.putString("lastBug", report);
                       editor.apply();
                   }
               } catch (Exception e2) {
                   e2.printStackTrace();
               }
           }
       }
   }