|
@@ -10,13 +10,14 @@ import android.content.ServiceConnection;
|
|
import android.content.pm.PackageManager;
|
|
import android.content.pm.PackageManager;
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
import android.os.CountDownTimer;
|
|
import android.os.CountDownTimer;
|
|
|
|
+import android.os.Handler;
|
|
import android.os.IBinder;
|
|
import android.os.IBinder;
|
|
|
|
+import android.os.Parcel;
|
|
import android.os.RemoteException;
|
|
import android.os.RemoteException;
|
|
import android.text.TextUtils;
|
|
import android.text.TextUtils;
|
|
import android.util.Log;
|
|
import android.util.Log;
|
|
import android.view.View;
|
|
import android.view.View;
|
|
import android.view.WindowManager;
|
|
import android.view.WindowManager;
|
|
-import android.widget.ImageView;
|
|
|
|
import android.widget.TextView;
|
|
import android.widget.TextView;
|
|
import android.widget.Toast;
|
|
import android.widget.Toast;
|
|
|
|
|
|
@@ -51,9 +52,6 @@ public class TakeActivity extends BaseActivity {
|
|
// @BindView(R.id.img_code_btn)
|
|
// @BindView(R.id.img_code_btn)
|
|
// ImageView img_code_btn;
|
|
// ImageView img_code_btn;
|
|
|
|
|
|
- private IDCardServiceAidl mService;
|
|
|
|
- private Context context;
|
|
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
void initView() {
|
|
void initView() {
|
|
titleBar = findViewById(R.id.tb_main_bar);
|
|
titleBar = findViewById(R.id.tb_main_bar);
|
|
@@ -81,6 +79,9 @@ public class TakeActivity extends BaseActivity {
|
|
super.onCreate(savedInstanceState);
|
|
super.onCreate(savedInstanceState);
|
|
setContentView(R.layout.activity_take);
|
|
setContentView(R.layout.activity_take);
|
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
|
|
|
+
|
|
|
|
+// registerReceiver();
|
|
|
|
+ bindIDCardService();
|
|
}
|
|
}
|
|
@Override
|
|
@Override
|
|
protected void onStart() {
|
|
protected void onStart() {
|
|
@@ -89,9 +90,10 @@ public class TakeActivity extends BaseActivity {
|
|
if (!hasPermission) {
|
|
if (!hasPermission) {
|
|
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 101);
|
|
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 101);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ if (mService != null) {
|
|
|
|
+ readCardAutoFu();
|
|
|
|
+ }
|
|
registerReceiver();
|
|
registerReceiver();
|
|
-// bindIDCardService();
|
|
|
|
}
|
|
}
|
|
@Override
|
|
@Override
|
|
protected void onStop() {
|
|
protected void onStop() {
|
|
@@ -290,13 +292,14 @@ public class TakeActivity extends BaseActivity {
|
|
intent.setAction("com.sunmi.idcard");
|
|
intent.setAction("com.sunmi.idcard");
|
|
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
|
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
|
}
|
|
}
|
|
|
|
+ private IDCardServiceAidl mService;
|
|
private ServiceConnection mConnection = new ServiceConnection() {
|
|
private ServiceConnection mConnection = new ServiceConnection() {
|
|
@Override
|
|
@Override
|
|
public void onServiceConnected(ComponentName name, IBinder service) {
|
|
public void onServiceConnected(ComponentName name, IBinder service) {
|
|
mService = IDCardServiceAidl.Stub.asInterface(service);
|
|
mService = IDCardServiceAidl.Stub.asInterface(service);
|
|
Log.e("id_card", " 服务已连接");
|
|
Log.e("id_card", " 服务已连接");
|
|
Toast.makeText(TakeActivity.this, "请将身份证放置到指示位置!", Toast.LENGTH_SHORT).show();
|
|
Toast.makeText(TakeActivity.this, "请将身份证放置到指示位置!", Toast.LENGTH_SHORT).show();
|
|
- auto();
|
|
|
|
|
|
+ readCardAutoFu();
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -305,12 +308,14 @@ public class TakeActivity extends BaseActivity {
|
|
Log.e("id_card", "服务已断开");
|
|
Log.e("id_card", "服务已断开");
|
|
}
|
|
}
|
|
};
|
|
};
|
|
- public void auto() {
|
|
|
|
|
|
+
|
|
|
|
+ private void readCardAutoFu() {
|
|
try {
|
|
try {
|
|
mService.readCardAuto(new CardCallback.Stub() {
|
|
mService.readCardAuto(new CardCallback.Stub() {
|
|
@Override
|
|
@Override
|
|
public void getCardData(final IDCardInfo info, int code) {
|
|
public void getCardData(final IDCardInfo info, int code) {
|
|
Log.i(TAG, "getCardData: code=" + code + ", id info:" + info);
|
|
Log.i(TAG, "getCardData: code=" + code + ", id info:" + info);
|
|
|
|
+ Toast.makeText(TakeActivity.this, "身份证读取状态code=" + code, Toast.LENGTH_SHORT).show();
|
|
if (code == 10) {
|
|
if (code == 10) {
|
|
//读取成功
|
|
//读取成功
|
|
Log.i(TAG, "getCardData: " + info.toString());
|
|
Log.i(TAG, "getCardData: " + info.toString());
|
|
@@ -321,11 +326,11 @@ public class TakeActivity extends BaseActivity {
|
|
bundle.putString("idcard", info.getIdCard());
|
|
bundle.putString("idcard", info.getIdCard());
|
|
ActivityUtils.launchActivity(TakeActivity.this, TicketCollectionActivity.class, bundle);
|
|
ActivityUtils.launchActivity(TakeActivity.this, TicketCollectionActivity.class, bundle);
|
|
} else if (code == -10) {
|
|
} else if (code == -10) {
|
|
-// Toast.makeText(TakeActivity.this, "身份证读取失败!" + code, Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
+ Toast.makeText(TakeActivity.this, "身份证读取失败!" + code, Toast.LENGTH_SHORT).show();
|
|
//读取失败
|
|
//读取失败
|
|
Log.i(TAG, "auto read card did not get data");
|
|
Log.i(TAG, "auto read card did not get data");
|
|
} else {
|
|
} else {
|
|
-// Toast.makeText(TakeActivity.this, "身份证读取失败!" + code, Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
+ Toast.makeText(TakeActivity.this, "身份证读取失败!" + code, Toast.LENGTH_SHORT).show();
|
|
Log.i(TAG, "what is wrong");
|
|
Log.i(TAG, "what is wrong");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -335,29 +340,4 @@ public class TakeActivity extends BaseActivity {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- public void read(View view) {
|
|
|
|
- try {
|
|
|
|
- if (mService != null) {
|
|
|
|
- IDCardInfo cardInfo = mService.readCard();
|
|
|
|
- if (cardInfo != null) {
|
|
|
|
- //显示图片
|
|
|
|
- Log.i(TAG, "read: " + cardInfo.toString());
|
|
|
|
- } else {
|
|
|
|
- Log.i(TAG, "card info is null ");
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- Log.i(TAG, "service is null");
|
|
|
|
- }
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- Log.i(TAG, "got error: " + e.getMessage());
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- public void cancelAuto(View v) {
|
|
|
|
- try {
|
|
|
|
- mService.cancelAutoReading();
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
}
|
|
}
|