|
|
|
@ -28,6 +28,8 @@ import androidx.core.content.FileProvider;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.example.beijing_daxing.R;
|
|
|
|
|
import com.example.beijing_daxing.rfid.RFID;
|
|
|
|
|
import com.example.beijing_daxing.rfid.impl.Device6109;
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
|
import com.handheld.uhfr.*;
|
|
|
|
|
import com.uhf.api.cls.Reader;
|
|
|
|
@ -43,7 +45,7 @@ import java.util.List;
|
|
|
|
|
|
|
|
|
|
import okhttp3.MediaType;
|
|
|
|
|
|
|
|
|
|
public abstract class BaseActivity extends AppCompatActivity {
|
|
|
|
|
public abstract class BaseActivity extends AppCompatActivity implements Device6109.EpcDataInterface {
|
|
|
|
|
// public static String url = "http://192.168.0.102:8090/api";
|
|
|
|
|
// public static String url = "http://192.168.42.239:8090/api";
|
|
|
|
|
public static String url = "http://119.45.202.115:8090/api";
|
|
|
|
@ -53,45 +55,39 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|
|
|
|
public UHFRManager uhfLongerManager;
|
|
|
|
|
private MediaPlayer mediaPlayer;
|
|
|
|
|
public MyReceiver myReceiver;
|
|
|
|
|
public Intent broadcastIntent;
|
|
|
|
|
|
|
|
|
|
@SuppressLint("UnspecifiedRegisterReceiverFlag")
|
|
|
|
|
public RFID rfidModel;
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
gson = new Gson();
|
|
|
|
|
|
|
|
|
|
initDialog();
|
|
|
|
|
initSan();
|
|
|
|
|
broadcastIntent = new Intent("android.rfid.FUN_KEY");
|
|
|
|
|
broadcastIntent.putExtra("keydown", false);
|
|
|
|
|
myReceiver = new MyReceiver();
|
|
|
|
|
IntentFilter intentFilter = new IntentFilter();
|
|
|
|
|
intentFilter.addAction("android.rfid.FUN_KEY");
|
|
|
|
|
registerReceiver(myReceiver, intentFilter);
|
|
|
|
|
mediaPlayer = MediaPlayer.create(this, R.raw.msg);
|
|
|
|
|
rfidModel=new Device6109(this);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void epcData(List<Reader.TAGINFO> data) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class MyReceiver extends BroadcastReceiver {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
|
|
|
|
|
|
var keydown = intent.getBooleanExtra("keydown", false);
|
|
|
|
|
|
|
|
|
|
Log.e("TAG", "接收到广播:" + keydown);
|
|
|
|
|
if (!keydown) {
|
|
|
|
|
// readTime = System.currentTimeMillis();
|
|
|
|
|
sanEpc();
|
|
|
|
|
rfidModel.sanRFID();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void sanEpc() {
|
|
|
|
|
List<Reader.TAGINFO> strings = uhfLongerManager.tagInventoryRealTime();
|
|
|
|
|
// Log.e("TAG", "驱动" + (uhfLongerManager == null));
|
|
|
|
|
if (strings == null || strings.isEmpty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mediaPlayer.start();
|
|
|
|
|
sanRfid(strings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initDialog() {
|
|
|
|
|
dialog = new ProgressDialog(this);
|
|
|
|
@ -101,27 +97,7 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|
|
|
|
dialog.setMessage("请求网络...");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initSan() {
|
|
|
|
|
|
|
|
|
|
myReceiver = new MyReceiver();
|
|
|
|
|
IntentFilter intentFilter = new IntentFilter();
|
|
|
|
|
intentFilter.addAction("android.rfid.FUN_KEY");
|
|
|
|
|
registerReceiver(myReceiver, intentFilter);
|
|
|
|
|
mediaPlayer = MediaPlayer.create(this, R.raw.msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setPower(int power) {
|
|
|
|
|
try {
|
|
|
|
|
Reader.READER_ERR readerErr = uhfLongerManager.setPower(power, power);
|
|
|
|
|
Log.e("TAG", "setPower:" + readerErr.name());
|
|
|
|
|
|
|
|
|
|
int[] power1 = uhfLongerManager.getPower();
|
|
|
|
|
Log.e("TAG", "readPower:" + power1[0] + "," + power1[1]);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onDestroy() {
|
|
|
|
@ -130,8 +106,6 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected abstract void sanRfid(List<Reader.TAGINFO> epcs);
|
|
|
|
|
|
|
|
|
|
public static final int CAMERA_PHOTO = 0X02;
|
|
|
|
|
public File outputImage;
|
|
|
|
|
public Uri img_uri;
|
|
|
|
@ -143,12 +117,9 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|
|
|
|
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
outputImage = new File(getExternalCacheDir(), "output_imgage" + format.format(new Date()) + ".jpg");
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
outputImage.createNewFile();
|
|
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
Log.e("TAG", "teke_photo:文件创建错误");
|
|
|
|
|
e.printStackTrace();
|
|
|
|
@ -180,30 +151,6 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
|
if (resultCode == RESULT_OK) {
|
|
|
|
|
/*
|
|
|
|
|
try {
|
|
|
|
|
Bitmap bitmap;
|
|
|
|
|
InputStream inputStream = getContentResolver().openInputStream(img_uri);
|
|
|
|
|
if (inputStream!= null) {
|
|
|
|
|
bitmap = BitmapFactory.decodeStream(inputStream);
|
|
|
|
|
FileOutputStream outputStream = new FileOutputStream(outputImage);
|
|
|
|
|
if (bitmap!= null) {
|
|
|
|
|
bitmap.compress(Bitmap.CompressFormat.JPEG, 70, outputStream);
|
|
|
|
|
takePhotoCall(outputImage, bitmap);
|
|
|
|
|
outputStream.close();
|
|
|
|
|
} else {
|
|
|
|
|
Log.e("Error", "Bitmap is null after decoding.");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Log.e("Error", "InputStream is null.");
|
|
|
|
|
}
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
Log.e("Error", "Error reading or writing file.", e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Bitmap bitmap = null;
|
|
|
|
|
try {
|
|
|
|
|
Log.e("TAG", "onActivityResult:" + img_uri.getPath());
|
|
|
|
|