扫码盒子通用接收原理 1.本质上是键盘输入事件 2.可以响应EditText的输入事件(前提是获得焦点) 接收代码: 完事,就是这么简单,需要额外注意一点: 如果是在PopupWindow中开启回调的话,由于PopupWindow盖在Activity之上,抢了Activity上EditText的焦点。 所以需要在配置PopupWindow时,要将这个配置改成false:this.setFocusable(false);  或者注释掉这行代码,因为它默认是false。首先写接收源: (假设在MainActivity接收付款码)
 
<EditText         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:id="@+id/edit_pay_code"         android:visibility="visible"></EditText> 
public ScanKeyManager scanKeyManager;                  EditText edt = findViewById(R.id.edit_pay_code);         edt.setOnEditorActionListener(new TextView.OnEditorActionListener() {             @Override             public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {                 String str = v.getText().toString().trim();                 Log.e("付款码:", str + "");                 if (str.length() == 18) {//134609522362925502                     v.setText("");                     if (scanKeyManager != null)                         scanKeyManager.analysisKeyEvent(str);                 }                 return true;             }         }); 
/*  *作者:赵星海  *时间:2020/5/27 16:22  *用途: 扫码盒子接收回调  */  public class ScanKeyManager {      public OnScanValueListener mListener;      public interface OnScanValueListener {         void onScanValue(String value);     }      public ScanKeyManager(OnScanValueListener listener) {         this.mListener = listener;     }      public void analysisKeyEvent(String str) {         mListener.onScanValue(str+"");     }       }当你要开启扫码接收的时候:(假设在PopupWindow中获得付款码)
 
 Toast.makeText(mContext, "请出示付款码", Toast.LENGTH_SHORT).show();                 ((MainActivity) mContext).scanKeyManager = new ScanKeyManager(new ScanKeyManager.OnScanValueListener() {                     @Override                     public void onScanValue(String value) {                         // Log.e("扫码结果:",""+value);                         // Toast.makeText(mContext,"结果"+value,Toast.LENGTH_SHORT).show();                         if (value == null) return;                         if (value.trim().substring(0, 2).equals("28")) {                             goPay(2, value);//1微信 2支付宝                          } else {                             goPay(1, value);                         }                       }                 });付款完成后,需要关闭接收。
 
((MainActivity) mContext).scanKeyManager = null; 
    /**      * 设置窗口的相关属性      */     @SuppressLint("InlinedApi")     private void setPopupWindow() {         this.setContentView(mPopView);// 设置View         this.setWidth(LinearLayout.LayoutParams.MATCH_PARENT);// 设置弹出窗口的宽         this.setHeight(LinearLayout.LayoutParams.MATCH_PARENT);// 设置弹出窗口的高         // this.setFocusable(true);// 设置弹出窗口可获得焦点      } 
 
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算
官方软件产品操作指南 (170)