Blame view

footsafety/app/src/main/java/android/serialport/api/MyApp.java 951 Bytes
f7a13682   “wangming”   项目初始化
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
  package android.serialport.api;
  
  import java.io.File;
  import java.io.IOException;
  import java.security.InvalidParameterException;
  
  import android.app.Application;
  import android.content.Context;
  
  import androidx.multidex.MultiDex;
  
  import etelligens.com.foodsafety.utils.LocaleHelper;
  
  public class MyApp extends Application{
  
  	public SerialPortFinder mSerialPortFinder = new SerialPortFinder();
  	private SerialPort mSerialPort = null;
  
  	public SerialPort getSerialPort() throws SecurityException, IOException, InvalidParameterException {
  		if (mSerialPort == null) {
  			/* Open the serial port */
  			mSerialPort = new SerialPort(new File("/dev/ttyMT2"), 9600, 0);
  		}
  		return mSerialPort;
  	}
  
  	public void closeSerialPort() {
  		if (mSerialPort != null) {
  			mSerialPort.close();
  			mSerialPort = null;
  		}
  
  	}
  	protected void attachBaseContext(Context base) {
  		super.attachBaseContext(LocaleHelper.onAttach(base));
  		MultiDex.install(this);
  	}
  
  
  }