增加绑定网络的接口、实现usb摄像头拍照
parent
38bcdd355e
commit
410eff11a9
@ -1,20 +0,0 @@
|
||||
{
|
||||
"version": 3,
|
||||
"artifactType": {
|
||||
"type": "APK",
|
||||
"kind": "Directory"
|
||||
},
|
||||
"applicationId": "com.xinyingpower.microphoto",
|
||||
"variantName": "release",
|
||||
"elements": [
|
||||
{
|
||||
"type": "SINGLE",
|
||||
"filters": [],
|
||||
"attributes": [],
|
||||
"versionCode": 101010,
|
||||
"versionName": "1.0.10",
|
||||
"outputFile": "app-release.apk"
|
||||
}
|
||||
],
|
||||
"elementType": "File"
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string-array name="networks">
|
||||
<item>当前网络</item>
|
||||
<item>SIM1</item>
|
||||
<item>SIM2</item>
|
||||
<item>WIFI</item>
|
||||
</string-array>
|
||||
</resources>
|
@ -0,0 +1,305 @@
|
||||
package com.xypower.common;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
public class TelephonyInfo {
|
||||
|
||||
private static TelephonyInfo telephonyInfo;
|
||||
private String imeiSIM1;
|
||||
private String imeiSIM2;
|
||||
private String imsiSIM1;
|
||||
private String imsiSIM2;
|
||||
private String iccidSIM1;
|
||||
private String iccidSIM2;
|
||||
private boolean isSIM1Ready;
|
||||
private boolean isSIM2Ready;
|
||||
private String numberSIM1;
|
||||
private String numberSIM2;
|
||||
private int mcc1;
|
||||
private int mcc2;
|
||||
private int mnc1;
|
||||
private int mnc2;
|
||||
private int defaultSimm;
|
||||
|
||||
private int smsDefaultSimm;
|
||||
|
||||
public String getNumberSIM1() {
|
||||
return numberSIM1 == null ? "" : numberSIM1;
|
||||
}
|
||||
|
||||
public String getNumberSIM2() {
|
||||
return numberSIM2 == null ? "" : numberSIM2;
|
||||
}
|
||||
|
||||
public String getImeiSIM1() {
|
||||
return imeiSIM1 == null ? "" : imeiSIM1;
|
||||
}
|
||||
|
||||
public String getImeiSIM2() {
|
||||
return imeiSIM2 == null ? "" : imeiSIM2;
|
||||
}
|
||||
|
||||
public String getImsiSIM1() {
|
||||
return imsiSIM1 == null ? "" : imsiSIM1;
|
||||
}
|
||||
|
||||
public String getImsiSIM2() {
|
||||
return imsiSIM2 == null ? "" : imsiSIM2;
|
||||
}
|
||||
|
||||
public String getIccidSIM1() {
|
||||
return iccidSIM1 == null ? "" : iccidSIM1;
|
||||
}
|
||||
|
||||
public String getIccidSIM2() {
|
||||
return iccidSIM2 == null ? "" : iccidSIM2;
|
||||
}
|
||||
|
||||
public boolean isSIM1Ready() {
|
||||
return isSIM1Ready;
|
||||
}
|
||||
|
||||
public boolean isSIM2Ready() {
|
||||
return isSIM2Ready;
|
||||
}
|
||||
|
||||
public boolean isDualSIM() {
|
||||
return imeiSIM2 != null && !imeiSIM2.equals("");
|
||||
}
|
||||
|
||||
public int getMcc1() {
|
||||
return mcc1;
|
||||
}
|
||||
|
||||
public int getMcc2() {
|
||||
return mcc2;
|
||||
}
|
||||
|
||||
public int getMnc1() {
|
||||
return mnc1;
|
||||
}
|
||||
|
||||
public int getMnc2() {
|
||||
return mnc2;
|
||||
}
|
||||
|
||||
public int getDefaultSimm() {
|
||||
return defaultSimm;
|
||||
}
|
||||
|
||||
public int getSmsDefaultSimm() {
|
||||
return smsDefaultSimm;
|
||||
}
|
||||
|
||||
private TelephonyInfo() {
|
||||
|
||||
}
|
||||
|
||||
public static TelephonyInfo getInstance(Context context) {
|
||||
if (telephonyInfo == null) {
|
||||
telephonyInfo = new TelephonyInfo();
|
||||
|
||||
TelephonyManager telephonyManager = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE));
|
||||
|
||||
telephonyInfo.imeiSIM1 = telephonyManager.getDeviceId();
|
||||
telephonyInfo.imeiSIM2 = "";
|
||||
telephonyInfo.imsiSIM1 = telephonyManager.getSubscriberId();
|
||||
telephonyInfo.imsiSIM2 = "";
|
||||
telephonyInfo.iccidSIM1 = telephonyManager.getSimSerialNumber();
|
||||
telephonyInfo.iccidSIM2 = "";
|
||||
telephonyInfo.numberSIM1 = "";
|
||||
telephonyInfo.numberSIM2 = "";
|
||||
telephonyInfo.defaultSimm = -1;
|
||||
telephonyInfo.smsDefaultSimm = -1;
|
||||
|
||||
telephonyInfo.isSIM1Ready = telephonyManager.getSimState() == TelephonyManager.SIM_STATE_READY;
|
||||
telephonyInfo.isSIM2Ready = false;
|
||||
|
||||
try {
|
||||
telephonyInfo.isSIM1Ready = getSIMStateBySlot(context, "getSimStateGemini", 0);
|
||||
telephonyInfo.isSIM2Ready = getSIMStateBySlot(context, "getSimStateGemini", 1);
|
||||
} catch (GeminiMethodNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
try {
|
||||
telephonyInfo.isSIM1Ready = getSIMStateBySlot(context, "getSimState", 0);
|
||||
telephonyInfo.isSIM2Ready = getSIMStateBySlot(context, "getSimState", 1);
|
||||
} catch (GeminiMethodNotFoundException e1) {
|
||||
//Call here for next manufacturer's predicted method name if you wish
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
telephonyInfo.imeiSIM1 = getDeviceIdBySlot(context, "getDeviceIdGemini", 0);
|
||||
telephonyInfo.imeiSIM2 = getDeviceIdBySlot(context, "getDeviceIdGemini", 1);
|
||||
} catch (GeminiMethodNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
try {
|
||||
telephonyInfo.imeiSIM1 = getDeviceIdBySlot(context, "getDeviceId", 0);
|
||||
telephonyInfo.imeiSIM2 = getDeviceIdBySlot(context, "getDeviceId", 1);
|
||||
} catch (GeminiMethodNotFoundException e1) {
|
||||
//Call here for next manufacturer's predicted method name if you wish
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
telephonyInfo.imsiSIM1 = getDeviceIdBySlot(context, "getSubscriberIdGemini", 0);
|
||||
telephonyInfo.imsiSIM2 = getDeviceIdBySlot(context, "getSubscriberIdGemini", 1);
|
||||
} catch (GeminiMethodNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
try {
|
||||
telephonyInfo.imsiSIM1 = getDeviceIdBySlot(context, "getSubscriberId", 0);
|
||||
telephonyInfo.imsiSIM2 = getDeviceIdBySlot(context, "getSubscriberId", 1);
|
||||
} catch (GeminiMethodNotFoundException e1) {
|
||||
//Call here for next manufacturer's predicted method name if you wish
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
telephonyInfo.iccidSIM1 = getDeviceIdBySlot(context, "getSimSerialNumberGemini", 0);
|
||||
telephonyInfo.iccidSIM2 = getDeviceIdBySlot(context, "getSimSerialNumberGemini", 1);
|
||||
} catch (GeminiMethodNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
try {
|
||||
telephonyInfo.iccidSIM1 = getDeviceIdBySlot(context, "getSimSerialNumber", 0);
|
||||
telephonyInfo.iccidSIM2 = getDeviceIdBySlot(context, "getSimSerialNumber", 1);
|
||||
} catch (GeminiMethodNotFoundException e1) {
|
||||
//Call here for next manufacturer's predicted method name if you wish
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
Object tm = context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
Method method_getDefaultSim;
|
||||
|
||||
try {
|
||||
method_getDefaultSim = tm.getClass().getDeclaredMethod("getDefaultSim");
|
||||
method_getDefaultSim.setAccessible(true);
|
||||
telephonyInfo.defaultSimm = (Integer) method_getDefaultSim.invoke(tm);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Method method_getSmsDefaultSim;
|
||||
try {
|
||||
method_getSmsDefaultSim = tm.getClass().getDeclaredMethod("getSmsDefaultSim");
|
||||
telephonyInfo.smsDefaultSimm = (Integer) method_getSmsDefaultSim.invoke(tm);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
SubscriptionManager sm = SubscriptionManager.from(context);
|
||||
|
||||
// it returns a list with a SubscriptionInfo instance for each simcard
|
||||
// there is other methods to retrieve SubscriptionInfos (see [2])
|
||||
List<SubscriptionInfo> sis = sm.getActiveSubscriptionInfoList();
|
||||
|
||||
telephonyInfo.iccidSIM1 = "";
|
||||
telephonyInfo.iccidSIM2 = "";
|
||||
|
||||
if (sis != null) {
|
||||
for (int i = 0; i < sis.size(); i++) {
|
||||
SubscriptionInfo si = sis.get(i);
|
||||
|
||||
if (si.getSimSlotIndex() == 0) {
|
||||
telephonyInfo.iccidSIM1 = si.getIccId();
|
||||
telephonyInfo.numberSIM1 = si.getNumber();
|
||||
telephonyInfo.mcc1 = si.getMcc();
|
||||
telephonyInfo.mnc1 = si.getMnc();
|
||||
} else {
|
||||
telephonyInfo.iccidSIM2 = si.getIccId();
|
||||
telephonyInfo.numberSIM2 = si.getNumber();
|
||||
telephonyInfo.mcc2 = si.getMcc();
|
||||
telephonyInfo.mnc2 = si.getMnc();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return telephonyInfo;
|
||||
}
|
||||
|
||||
private static String getDeviceIdBySlot(Context context, String predictedMethodName, int slotID) throws GeminiMethodNotFoundException {
|
||||
String imei = null;
|
||||
|
||||
TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
|
||||
try {
|
||||
Class<?> telephonyClass = Class.forName(telephony.getClass().getName());
|
||||
|
||||
Class<?>[] parameter = new Class[1];
|
||||
parameter[0] = int.class;
|
||||
Method getSimID = telephonyClass.getMethod(predictedMethodName, parameter);
|
||||
|
||||
Object[] obParameter = new Object[1];
|
||||
obParameter[0] = slotID;
|
||||
Object ob_phone = getSimID.invoke(telephony, obParameter);
|
||||
|
||||
if(ob_phone != null){
|
||||
imei = ob_phone.toString();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new GeminiMethodNotFoundException(predictedMethodName);
|
||||
}
|
||||
|
||||
return imei;
|
||||
}
|
||||
|
||||
private static boolean getSIMStateBySlot(Context context, String predictedMethodName, int slotID) throws GeminiMethodNotFoundException {
|
||||
|
||||
boolean isReady = false;
|
||||
|
||||
TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
|
||||
try {
|
||||
Class<?> telephonyClass = Class.forName(telephony.getClass().getName());
|
||||
|
||||
Class<?>[] parameter = new Class[1];
|
||||
parameter[0] = int.class;
|
||||
Method getSimStateGemini = telephonyClass.getMethod(predictedMethodName, parameter);
|
||||
|
||||
Object[] obParameter = new Object[1];
|
||||
obParameter[0] = slotID;
|
||||
Object ob_phone = getSimStateGemini.invoke(telephony, obParameter);
|
||||
|
||||
if(ob_phone != null){
|
||||
int simState = Integer.parseInt(ob_phone.toString());
|
||||
if(simState == TelephonyManager.SIM_STATE_READY){
|
||||
isReady = true;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new GeminiMethodNotFoundException(predictedMethodName);
|
||||
}
|
||||
|
||||
return isReady;
|
||||
}
|
||||
|
||||
private static class GeminiMethodNotFoundException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -996812356902545308L;
|
||||
|
||||
public GeminiMethodNotFoundException(String info) {
|
||||
super(info);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,224 @@
|
||||
package com.xypower.mpapp;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Rect;
|
||||
import android.os.IBinder;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.xypower.mpmaster.R;
|
||||
|
||||
public class FloatingWindow extends Service {
|
||||
|
||||
private Context mContext;
|
||||
private WindowManager mWindowManager;
|
||||
private View mView;
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
mContext = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
|
||||
|
||||
allAboutLayout(intent);
|
||||
moveView();
|
||||
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
|
||||
try {
|
||||
if (mView != null) {
|
||||
mWindowManager.removeView(mView);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
// ex.printStackTrace();
|
||||
Log.e("FW", "Exception " + ex.getMessage());
|
||||
}
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
WindowManager.LayoutParams mWindowsParams;
|
||||
private void moveView() {
|
||||
/*
|
||||
DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
|
||||
int width = (int) (metrics.widthPixels * 1f);
|
||||
int height = (int) (metrics.heightPixels * 1f);
|
||||
|
||||
mWindowsParams = new WindowManager.LayoutParams(
|
||||
width,//WindowManager.LayoutParams.WRAP_CONTENT,
|
||||
height,//WindowManager.LayoutParams.WRAP_CONTENT,
|
||||
//WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
|
||||
|
||||
(Build.VERSION.SDK_INT <= 25) ? WindowManager.LayoutParams.TYPE_PHONE : WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
|
||||
,
|
||||
|
||||
//WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
|
||||
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
|
||||
| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN // Not displaying keyboard on bg activity's EditText
|
||||
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
|
||||
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
|
||||
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
|
||||
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON,
|
||||
//WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, //Not work with EditText on keyboard
|
||||
PixelFormat.TRANSLUCENT);
|
||||
|
||||
|
||||
mWindowsParams.gravity = Gravity.TOP | Gravity.LEFT;
|
||||
//params.x = 0;
|
||||
mWindowsParams.y = 100;
|
||||
mWindowManager.addView(mView, mWindowsParams);
|
||||
|
||||
mView.setOnTouchListener(new View.OnTouchListener() {
|
||||
private int initialX;
|
||||
private int initialY;
|
||||
private float initialTouchX;
|
||||
private float initialTouchY;
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
if (System.currentTimeMillis() - startTime <= 300) {
|
||||
return false;
|
||||
}
|
||||
if (isViewInBounds(mView, (int) (event.getRawX()), (int) (event.getRawY()))) {
|
||||
editTextReceiveFocus();
|
||||
} else {
|
||||
editTextDontReceiveFocus();
|
||||
}
|
||||
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
initialX = mWindowsParams.x;
|
||||
initialY = mWindowsParams.y;
|
||||
initialTouchX = event.getRawX();
|
||||
initialTouchY = event.getRawY();
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
mWindowsParams.x = initialX + (int) (event.getRawX() - initialTouchX);
|
||||
mWindowsParams.y = initialY + (int) (event.getRawY() - initialTouchY);
|
||||
mWindowManager.updateViewLayout(mView, mWindowsParams);
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
private boolean isViewInBounds(View view, int x, int y) {
|
||||
Rect outRect = new Rect();
|
||||
int[] location = new int[2];
|
||||
view.getDrawingRect(outRect);
|
||||
view.getLocationOnScreen(location);
|
||||
outRect.offset(location[0], location[1]);
|
||||
return outRect.contains(x, y);
|
||||
}
|
||||
|
||||
private void editTextReceiveFocus() {
|
||||
if (!wasInFocus) {
|
||||
mWindowsParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
|
||||
mWindowManager.updateViewLayout(mView, mWindowsParams);
|
||||
wasInFocus = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void editTextDontReceiveFocus() {
|
||||
if (wasInFocus) {
|
||||
mWindowsParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
|
||||
mWindowManager.updateViewLayout(mView, mWindowsParams);
|
||||
wasInFocus = false;
|
||||
hideKeyboard(mContext, edt1);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean wasInFocus = true;
|
||||
private EditText edt1;
|
||||
private void allAboutLayout(Intent intent) {
|
||||
|
||||
LayoutInflater layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
mView = layoutInflater.inflate(R.layout.ovelay_window, null);
|
||||
|
||||
edt1 = (EditText) mView.findViewById(R.id.edt1);
|
||||
final TextView tvValue = (TextView) mView.findViewById(R.id.tvValue);
|
||||
Button btnClose = (Button) mView.findViewById(R.id.btnClose);
|
||||
|
||||
edt1.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mWindowsParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
|
||||
mWindowsParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE;
|
||||
mWindowManager.updateViewLayout(mView, mWindowsParams);
|
||||
wasInFocus = true;
|
||||
showSoftKeyboard(v);
|
||||
}
|
||||
});
|
||||
|
||||
edt1.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
||||
tvValue.setText(edt1.getText());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable editable) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
btnClose.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
stopSelf();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void hideKeyboard(Context context, View view) {
|
||||
if (view != null) {
|
||||
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void showSoftKeyboard(View view) {
|
||||
if (view.requestFocus()) {
|
||||
InputMethodManager imm = (InputMethodManager)
|
||||
getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue