增加扫码的回调
This commit is contained in:
parent
64ecbe17f4
commit
8c1cee23dd
@ -14,8 +14,8 @@ import android.util.Log;
|
|||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
|
import com.jc.jcfw.JcSDK;
|
||||||
import com.king.zxing.CameraScan;
|
import com.king.zxing.CameraScan;
|
||||||
import com.king.zxing.CaptureActivity;
|
import com.king.zxing.CaptureActivity;
|
||||||
import com.king.zxing.util.CodeUtils;
|
import com.king.zxing.util.CodeUtils;
|
||||||
@ -50,6 +50,7 @@ public class MainActivity extends Activity
|
|||||||
|
|
||||||
public static final int RC_READ_PHOTO = 0X02;
|
public static final int RC_READ_PHOTO = 0X02;
|
||||||
private String title;
|
private String title;
|
||||||
|
private String funId;
|
||||||
|
|
||||||
protected String updateUnityCommandLineArguments(String cmdLine) {
|
protected String updateUnityCommandLineArguments(String cmdLine) {
|
||||||
return cmdLine;
|
return cmdLine;
|
||||||
@ -81,13 +82,18 @@ public class MainActivity extends Activity
|
|||||||
switch (requestCode){
|
switch (requestCode){
|
||||||
case REQUEST_CODE_SCAN:
|
case REQUEST_CODE_SCAN:
|
||||||
String result = CameraScan.parseScanResult(data);
|
String result = CameraScan.parseScanResult(data);
|
||||||
Log.i(TAG, "scan qrcode result: " + result);
|
Log.i(TAG, "scan qrcode with funId: " +funId+ " result: " + result);
|
||||||
|
String jsonStr = String.format("{errcode: 0, data: '%s'}", result);
|
||||||
|
JcSDK.csCallback(funId, jsonStr);
|
||||||
|
funId = "";
|
||||||
break;
|
break;
|
||||||
case REQUEST_CODE_PHOTO:
|
case REQUEST_CODE_PHOTO:
|
||||||
// parsePhoto(data);
|
parsePhoto(data);
|
||||||
Log.i(TAG, "request qrcode img result: " + data);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
JcSDK.csCallback(funId, "{errcode: 0, errmsg: 'cancel'}");
|
||||||
|
funId = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,6 +243,10 @@ public class MainActivity extends Activity
|
|||||||
public void onPermissionsDenied(int requestCode, List<String> list) {
|
public void onPermissionsDenied(int requestCode, List<String> list) {
|
||||||
// Some permissions have been denied
|
// Some permissions have been denied
|
||||||
// ...
|
// ...
|
||||||
|
if (requestCode ==RC_CAMERA && null != funId && !"".equals(funId)) {
|
||||||
|
JcSDK.csCallback(funId, "{errcode: 1, errmsg: 'no camera permission'}");
|
||||||
|
funId = "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// end of easypermissions
|
// end of easypermissions
|
||||||
@ -278,20 +288,23 @@ public class MainActivity extends Activity
|
|||||||
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),data.getData());
|
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),data.getData());
|
||||||
asyncThread(() -> {
|
asyncThread(() -> {
|
||||||
final String result = CodeUtils.parseCode(bitmap);
|
final String result = CodeUtils.parseCode(bitmap);
|
||||||
runOnUiThread(() -> {
|
|
||||||
LogUtils.d("result:" + result);
|
LogUtils.d("result:" + result);
|
||||||
Toast.makeText(getContext(),result,Toast.LENGTH_SHORT).show();
|
String jsonStr = String.format("{errcode: 0, data: '%s'}", result);
|
||||||
});
|
JcSDK.csCallback(funId, jsonStr);
|
||||||
|
funId = "";
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
JcSDK.csCallback(funId, String.format("{errcode: 1, errmsg: '%s'}", e.toString()));
|
||||||
|
funId = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showQRScan(String title) {
|
public void showQRScan(String funId, String title) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
|
this.funId = funId;
|
||||||
checkCameraPermissions();
|
checkCameraPermissions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,27 +18,27 @@ public class JcSDK {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @Deprecated
|
||||||
* 不使用该方法, 直接由unity调用cpp方法
|
* 不使用该方法, 直接由unity调用cpp方法
|
||||||
* @param password
|
* @param password
|
||||||
*/
|
*/
|
||||||
public static void initWallet(String password) {
|
public static void initWallet(String password) {
|
||||||
Log.i(TAG, "call init wallet from unity with password: " + password);
|
Log.i(TAG, "call init wallet from unity with password: " + password);
|
||||||
CocosJSHelper.initWallet(password);
|
CocosJSHelper.initWallet(password);
|
||||||
commonCB.stringCallback("wallet init success");
|
commonCB.stringCallback("", "wallet init success");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 回调至c#
|
||||||
|
* @param funId
|
||||||
|
* @param msg
|
||||||
|
*/
|
||||||
|
public static void csCallback(String funId, String msg) {
|
||||||
|
if (!funId.equals("jscall")) {
|
||||||
|
commonCB.stringCallback(funId, msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static void connectWallet(String url){
|
|
||||||
// Uri uri = Uri.parse(url);
|
|
||||||
// Log.i(TAG, url);
|
|
||||||
// Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
|
||||||
// try {
|
|
||||||
// MainActivity.app.startActivity(intent);
|
|
||||||
// } catch (ActivityNotFoundException e) {
|
|
||||||
// Intent i = new Intent(Intent.ACTION_VIEW);
|
|
||||||
// i.setData(Uri.parse("https://metamask.io/download/"));
|
|
||||||
// MainActivity.app.startActivity(i);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
/**
|
/**
|
||||||
* check if metamask installed and jump to metamask
|
* check if metamask installed and jump to metamask
|
||||||
* @param url
|
* @param url
|
||||||
@ -58,7 +58,7 @@ public class JcSDK {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void scanQRCode(String title) {
|
public static void scanQRCode(String funid, String title) {
|
||||||
MainActivity.app.showQRScan(title);
|
MainActivity.app.showQRScan(funid, title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
package com.jc.jcfw;
|
package com.jc.jcfw;
|
||||||
|
|
||||||
public interface UnityCallback {
|
public interface UnityCallback {
|
||||||
public void stringCallback(String str);
|
public void stringCallback(String funId, String str);
|
||||||
}
|
}
|
||||||
|
@ -233,8 +233,7 @@ function restoreFromMnemonic(funId, mnemonic, password) {
|
|||||||
|
|
||||||
function scanQRCode(funId, title) {
|
function scanQRCode(funId, title) {
|
||||||
try {
|
try {
|
||||||
jsb.scanQRCode(title);
|
jsb.scanQRCode(funId, title);
|
||||||
return JSON.stringify({errcode: 0});
|
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
return JSON.stringify({errcode: 1, errmsg: err});
|
return JSON.stringify({errcode: 1, errmsg: err});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user