编译工程
This commit is contained in:
@@ -1,117 +1,117 @@
|
||||
package com.navinfo.collect;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.PermissionChecker;
|
||||
|
||||
import com.baidu.ai.edge.core.base.Consts;
|
||||
|
||||
|
||||
/**
|
||||
* Created by linyiran on 6/16/22.
|
||||
*/
|
||||
public abstract class BaseActivity extends AppCompatActivity {
|
||||
private static final int REQUEST_PERMISSION = 1;
|
||||
|
||||
protected boolean allPermissionsGranted;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setLayout();
|
||||
requestPermission();
|
||||
onActivityCreated(savedInstanceState);
|
||||
}
|
||||
|
||||
protected abstract void setLayout();
|
||||
|
||||
protected abstract void onActivityCreated(Bundle savedInstanceState);
|
||||
|
||||
private void requestPermission() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
String[] permissions = new String[]{
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
Manifest.permission.INTERNET,
|
||||
Manifest.permission.ACCESS_NETWORK_STATE,
|
||||
Manifest.permission.READ_PHONE_STATE,
|
||||
Manifest.permission.CAMERA
|
||||
};
|
||||
allPermissionsGranted = true;
|
||||
for (String perm : permissions) {
|
||||
if ((PermissionChecker.checkSelfPermission(this, perm) != PermissionChecker.PERMISSION_GRANTED)) {
|
||||
allPermissionsGranted = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!allPermissionsGranted) {
|
||||
ActivityCompat.requestPermissions(BaseActivity.this, permissions, REQUEST_PERMISSION);
|
||||
} else {
|
||||
requestAllFilesAccess();
|
||||
}
|
||||
} else {
|
||||
allPermissionsGranted = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
|
||||
@NonNull int[] grantResults) {
|
||||
if (requestCode == REQUEST_PERMISSION) {
|
||||
allPermissionsGranted = true;
|
||||
for (int grantRes : grantResults) {
|
||||
if (grantRes != PackageManager.PERMISSION_GRANTED) {
|
||||
allPermissionsGranted = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (allPermissionsGranted) {
|
||||
requestAllFilesAccess();
|
||||
}
|
||||
}
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
}
|
||||
|
||||
/**
|
||||
* Android 11 跳转到设置获取SD卡根目录写入权限
|
||||
*/
|
||||
private void requestAllFilesAccess() {
|
||||
if (!Consts.AUTH_REQUIRE_SDCARD) {
|
||||
return;
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && !Environment.isExternalStorageManager()) {
|
||||
allPermissionsGranted = false;
|
||||
|
||||
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(BaseActivity.this,
|
||||
androidx.appcompat.R.style.Theme_AppCompat_Light_Dialog_Alert);
|
||||
alertBuilder.setMessage("需授权访问SD卡文件");
|
||||
alertBuilder.setCancelable(false);
|
||||
alertBuilder.setPositiveButton("去设置", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Intent intent = new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
alertBuilder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
alertBuilder.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
//package com.navinfo.collect;
|
||||
//
|
||||
//import android.Manifest;
|
||||
//import android.content.DialogInterface;
|
||||
//import android.content.Intent;
|
||||
//import android.content.pm.PackageManager;
|
||||
//import android.os.Build;
|
||||
//import android.os.Bundle;
|
||||
//import android.os.Environment;
|
||||
//import android.provider.Settings;
|
||||
//
|
||||
//import androidx.annotation.NonNull;
|
||||
//import androidx.annotation.Nullable;
|
||||
//import androidx.appcompat.app.AlertDialog;
|
||||
//import androidx.appcompat.app.AppCompatActivity;
|
||||
//import androidx.core.app.ActivityCompat;
|
||||
//import androidx.core.content.PermissionChecker;
|
||||
//
|
||||
//import com.baidu.ai.edge.core.base.Consts;
|
||||
//
|
||||
//
|
||||
///**
|
||||
// * Created by linyiran on 6/16/22.
|
||||
// */
|
||||
//public abstract class BaseActivity extends AppCompatActivity {
|
||||
// private static final int REQUEST_PERMISSION = 1;
|
||||
//
|
||||
// protected boolean allPermissionsGranted;
|
||||
//
|
||||
// @Override
|
||||
// protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
// super.onCreate(savedInstanceState);
|
||||
// setLayout();
|
||||
// requestPermission();
|
||||
// onActivityCreated(savedInstanceState);
|
||||
// }
|
||||
//
|
||||
// protected abstract void setLayout();
|
||||
//
|
||||
// protected abstract void onActivityCreated(Bundle savedInstanceState);
|
||||
//
|
||||
// private void requestPermission() {
|
||||
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
// String[] permissions = new String[]{
|
||||
// Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
// Manifest.permission.INTERNET,
|
||||
// Manifest.permission.ACCESS_NETWORK_STATE,
|
||||
// Manifest.permission.READ_PHONE_STATE,
|
||||
// Manifest.permission.CAMERA
|
||||
// };
|
||||
// allPermissionsGranted = true;
|
||||
// for (String perm : permissions) {
|
||||
// if ((PermissionChecker.checkSelfPermission(this, perm) != PermissionChecker.PERMISSION_GRANTED)) {
|
||||
// allPermissionsGranted = false;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if (!allPermissionsGranted) {
|
||||
// ActivityCompat.requestPermissions(BaseActivity.this, permissions, REQUEST_PERMISSION);
|
||||
// } else {
|
||||
// requestAllFilesAccess();
|
||||
// }
|
||||
// } else {
|
||||
// allPermissionsGranted = true;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
|
||||
// @NonNull int[] grantResults) {
|
||||
// if (requestCode == REQUEST_PERMISSION) {
|
||||
// allPermissionsGranted = true;
|
||||
// for (int grantRes : grantResults) {
|
||||
// if (grantRes != PackageManager.PERMISSION_GRANTED) {
|
||||
// allPermissionsGranted = false;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if (allPermissionsGranted) {
|
||||
// requestAllFilesAccess();
|
||||
// }
|
||||
// }
|
||||
// super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Android 11 跳转到设置获取SD卡根目录写入权限
|
||||
// */
|
||||
// private void requestAllFilesAccess() {
|
||||
// if (!Consts.AUTH_REQUIRE_SDCARD) {
|
||||
// return;
|
||||
// }
|
||||
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && !Environment.isExternalStorageManager()) {
|
||||
// allPermissionsGranted = false;
|
||||
//
|
||||
// AlertDialog.Builder alertBuilder = new AlertDialog.Builder(BaseActivity.this,
|
||||
// androidx.appcompat.R.style.Theme_AppCompat_Light_Dialog_Alert);
|
||||
// alertBuilder.setMessage("需授权访问SD卡文件");
|
||||
// alertBuilder.setCancelable(false);
|
||||
// alertBuilder.setPositiveButton("去设置", new DialogInterface.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(DialogInterface dialog, int which) {
|
||||
// Intent intent = new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
|
||||
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
// startActivity(intent);
|
||||
// }
|
||||
// });
|
||||
// alertBuilder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(DialogInterface dialog, int which) {
|
||||
// dialog.dismiss();
|
||||
// }
|
||||
// });
|
||||
// alertBuilder.show();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -1,43 +1,43 @@
|
||||
package com.navinfo.collect
|
||||
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
import com.baidu.ai.edge.ui.view.model.BasePolygonResultModel
|
||||
import com.navinfo.collect.library.map.flutter.plugin.FlutterMapViewFactory
|
||||
import com.navinfo.collect.library.map.flutter.plugin.FlutterMapViewFlutterPlugin
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.MainScope
|
||||
import kotlinx.coroutines.cancel
|
||||
|
||||
abstract class FlutterBaseActivity : FlutterActivity(), CoroutineScope by MainScope() {
|
||||
lateinit var factory: FlutterMapViewFactory
|
||||
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
||||
super.configureFlutterEngine(flutterEngine)
|
||||
factory = FlutterMapViewFlutterPlugin.registerWith(flutterEngine, this);
|
||||
// FlutterNiMapCopyViewFlutterPlugin.registerWith(flutterEngine, this);
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if (resultCode == 0x10 && data != null) {
|
||||
val path = data.getStringExtra("photo_path")
|
||||
val list = data.getParcelableArrayListExtra<BasePolygonResultModel>("result_list")
|
||||
Log.e("jingo","OCR java 返回的数据:"+ path + list.toString());
|
||||
if (path != null && list != null) {
|
||||
factory.dataController.flutterDataCameraHandler.sendOcrResults(
|
||||
path,
|
||||
list as List<BasePolygonResultModel>
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
//协程销毁
|
||||
cancel()
|
||||
}
|
||||
|
||||
}
|
||||
//package com.navinfo.collect
|
||||
//
|
||||
//import android.content.Intent
|
||||
//import android.util.Log
|
||||
//import com.baidu.ai.edge.ui.view.model.BasePolygonResultModel
|
||||
//import com.navinfo.collect.library.map.flutter.plugin.FlutterMapViewFactory
|
||||
//import com.navinfo.collect.library.map.flutter.plugin.FlutterMapViewFlutterPlugin
|
||||
//import io.flutter.embedding.android.FlutterActivity
|
||||
//import io.flutter.embedding.engine.FlutterEngine
|
||||
//import kotlinx.coroutines.CoroutineScope
|
||||
//import kotlinx.coroutines.MainScope
|
||||
//import kotlinx.coroutines.cancel
|
||||
//
|
||||
//abstract class FlutterBaseActivity : FlutterActivity(), CoroutineScope by MainScope() {
|
||||
// lateinit var factory: FlutterMapViewFactory
|
||||
// override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
||||
// super.configureFlutterEngine(flutterEngine)
|
||||
// factory = FlutterMapViewFlutterPlugin.registerWith(flutterEngine, this);
|
||||
//// FlutterNiMapCopyViewFlutterPlugin.registerWith(flutterEngine, this);
|
||||
// }
|
||||
//
|
||||
// override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
// super.onActivityResult(requestCode, resultCode, data)
|
||||
// if (resultCode == 0x10 && data != null) {
|
||||
// val path = data.getStringExtra("photo_path")
|
||||
// val list = data.getParcelableArrayListExtra<BasePolygonResultModel>("result_list")
|
||||
// Log.e("jingo","OCR java 返回的数据:"+ path + list.toString());
|
||||
// if (path != null && list != null) {
|
||||
// factory.dataController.flutterDataCameraHandler.sendOcrResults(
|
||||
// path,
|
||||
// list as List<BasePolygonResultModel>
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// override fun onDestroy() {
|
||||
// super.onDestroy()
|
||||
// //协程销毁
|
||||
// cancel()
|
||||
// }
|
||||
//
|
||||
//}
|
||||
Reference in New Issue
Block a user