|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package com.xinyingpower.microphoto;
|
|
|
|
|
|
|
|
|
|
import android.Manifest;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
|
import android.graphics.SurfaceTexture;
|
|
|
|
@ -9,9 +10,13 @@ import android.os.Build;
|
|
|
|
|
import android.os.Environment;
|
|
|
|
|
import android.os.Handler;
|
|
|
|
|
import android.os.SystemClock;
|
|
|
|
|
|
|
|
|
|
import androidx.core.app.ActivityCompat;
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
|
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.telephony.SubscriptionManager;
|
|
|
|
|
import android.telephony.TelephonyManager;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
import android.view.Display;
|
|
|
|
|
import android.view.View;
|
|
|
|
@ -22,6 +27,7 @@ import com.xinyingpower.microphoto.databinding.ActivityMainBinding;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
|
@ -37,6 +43,7 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ActivityMainBinding binding;
|
|
|
|
|
private int defaultDataSubId;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
@ -50,24 +57,24 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
int width = defaultDisplay.getWidth();
|
|
|
|
|
int height = defaultDisplay.getHeight();
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "Screen Size: " + width + " x " + height);
|
|
|
|
|
Log.d(TAG, "Screen Size: " + width + " x " + height);
|
|
|
|
|
|
|
|
|
|
this.binding.startServBtn.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String[] accessPermissions = new String[] {
|
|
|
|
|
String[] accessPermissions = new String[]{
|
|
|
|
|
Manifest.permission.CAMERA,
|
|
|
|
|
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
|
|
|
|
Manifest.permission.FOREGROUND_SERVICE,
|
|
|
|
|
Manifest.permission.READ_PHONE_STATE,
|
|
|
|
|
/*Manifest.permission.SET_TIME,*/
|
|
|
|
|
};
|
|
|
|
|
boolean needRequire = false;
|
|
|
|
|
for(String access : accessPermissions) {
|
|
|
|
|
boolean needRequire = false;
|
|
|
|
|
for (String access : accessPermissions) {
|
|
|
|
|
int curPermission = ActivityCompat.checkSelfPermission(MainActivity.this, access);
|
|
|
|
|
if(curPermission != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
|
if (curPermission != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
|
needRequire = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
@ -106,6 +113,7 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
MicroPhotoService.takePhoto(MainActivity.this, 1, 255, true);
|
|
|
|
|
// setDefaultDataSubId(1);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -113,6 +121,7 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
MicroPhotoService.takePhoto(MainActivity.this, 2, 255, true);
|
|
|
|
|
// setDefaultDataSubId(2);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -132,8 +141,33 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Handler handler=new Handler();
|
|
|
|
|
Runnable runnable=new Runnable(){
|
|
|
|
|
|
|
|
|
|
binding.simchange.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
|
|
|
|
|
defaultDataSubId = getDefaultDataSubId();
|
|
|
|
|
System.out.println(defaultDataSubId);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
binding.simchange2.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
if (defaultDataSubId == 0) {
|
|
|
|
|
setDefaultDataSubId(1);
|
|
|
|
|
} else {
|
|
|
|
|
if (defaultDataSubId == 1) {
|
|
|
|
|
setDefaultDataSubId(2);
|
|
|
|
|
} else {
|
|
|
|
|
setDefaultDataSubId(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
Handler handler = new Handler();
|
|
|
|
|
Runnable runnable = new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
binding.startServBtn.performClick();
|
|
|
|
@ -143,8 +177,32 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void takePhoto()
|
|
|
|
|
{
|
|
|
|
|
private void setDefaultDataSubId(int subId) {
|
|
|
|
|
SubscriptionManager subscriptionManager = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
|
|
|
|
|
try {
|
|
|
|
|
Method method = subscriptionManager.getClass().getDeclaredMethod("setDefaultDataSubId", int.class);
|
|
|
|
|
method.invoke(subscriptionManager, subId);
|
|
|
|
|
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
|
|
Method method1 = telephonyManager.getClass().getDeclaredMethod("setDataEnabled", boolean.class);
|
|
|
|
|
method1.invoke(telephonyManager, true);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
Log.e(TAG, "wjz debug setDefaultDataSubId: error is " + e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int getDefaultDataSubId() {
|
|
|
|
|
SubscriptionManager subscriptionManager = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
|
|
|
|
|
try {
|
|
|
|
|
Method method = subscriptionManager.getClass().getDeclaredMethod("getDefaultDataSubscriptionId");
|
|
|
|
|
return (int) method.invoke(subscriptionManager);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
Log.e(TAG, "wjz debug getDefaultDataSubId: error is " + e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void takePhoto() {
|
|
|
|
|
File path = Environment.getExternalStorageDirectory();
|
|
|
|
|
File file = new File(path, "photo.jpg");
|
|
|
|
|
boolean res = false;
|
|
|
|
@ -153,8 +211,7 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
res = DSCameraManager.getInstace().takePhoto(file.getAbsolutePath(), 2);
|
|
|
|
|
|
|
|
|
|
if (!res)
|
|
|
|
|
{
|
|
|
|
|
if (!res) {
|
|
|
|
|
int aa = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|