//华为开发1加x(高级)
//融合定位 ,判断Build.sdk
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) {
Log.i(TAG, "Reply: ");
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) ;
String[] strings = {
Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION
};
ActivityCompat.requestPermissions(this, strings, 1);
} else {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)
!= PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_BACKGROUND_LOCATION)
!= PackageManager.PERMISSION_GRANTED) ;
String[] strings = {
Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_BACKGROUND_LOCATION
};
ActivityCompat.requestPermissions(this, strings, 2);
}
}
//检查设备
private void Check() {
SettingsClient settingsClient = new SettingsClient(this);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
LocationRequest locationRequest = new LocationRequest();
LocationSettingsRequest build = builder.build();
builder.addLocationRequest(locationRequest);
settingsClient.checkLocationSettings(build).addOnSuccessListener(new OnSuccessListener<LocationSettingsResponse>() {
@Override
public void onSuccess(LocationSettingsResponse locationSettingsResponse) {
LocationSettingsStates locationSettingsStates = locationSettingsResponse.getLocationSettingsStates();
System.out.println(locationSettingsStates.isHMSLocationUsable());
System.out.println(locationSettingsStates.isLocationUsable());
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
}
});
}
//开启设备
private void Start() {
FusedLocationProviderClient inifo = new FusedLocationProviderClient(this);
LocationRequest locationRequest = new LocationRequest();
locationRequest.setInterval(5000);
locationRequest.setPriority(100);
LocationCallback locationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
Location lastLocation = locationResult.getLastLocation();
System.out.println(lastLocation.getLatitude());
System.out.println(lastLocation.getLongitude());
}
};
Task<Void> voidTask = inifo.requestLocationUpdates(locationRequest, locationCallback, Looper.getMainLooper());
voidTask.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.i(TAG, "onSuccess: ");
}
});
}
//活动识别
@SuppressLint("WrongConstant")
private PendingIntent getPeningIntent() {
Intent intent = new Intent(this, LocationBroadcastReceiver.class);
intent.setAction(LocationBroadcastReceiver.ACTION_PROCESS_LOCATION);
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) {
return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
} else {
return PendingIntent.getBroadcast(this, 0, intent, 1 << 25);
}
}
private void Function() {
ActivityIdentificationService service = ActivityIdentification.getService(this);
PendingIntent peningIntent = getPeningIntent();
service.createActivityIdentificationUpdates(5000, peningIntent)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
}
});
}
//地理围栏
@SuppressLint("WrongConstant")
private PendingIntent GetPeng() {
Intent intent = new Intent(this, GeoFenceBroadcastReceiver.class);
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) {
return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
} else {
return PendingIntent.getBroadcast(this, 0, intent, 1 << 25);
}
}
private void Geofen() {
GeofenceService geofenceService = LocationServices.getGeofenceService(this);
PendingIntent pendingIntent = GetPeng();
GeofenceRequest.Builder builder = new GeofenceRequest.Builder();
Geofence.Builder builder1 = new Geofence.Builder();
builder1.setConversions(1 | 2)
.setRoundArea(30, 114, 500)
.setValidContinueTime(5000)
.setUniqueId("nn")
.build();
builder.setInitConversions(1);
geofenceService.createGeofenceList(builder.build(), pendingIntent).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
}
});
}
//广告
private void ad() {
HwAds.init(this);
BannerView bannerView = findViewById(R.id.hw_banner_view);
bannerView.setBannerAdSize(BannerAdSize.BANNER_SIZE_360_57);
bannerView.setAdId("testw6vs28auh3");
AdParam build = new AdParam.Builder().build();
bannerView.loadAd(build);
}
//OID
private void getoid() {
new Thread() {
@Override
public void run() {
try {
AdvertisingIdClient.Info advertisingIdInfo = AdvertisingIdClient.getAdvertisingIdInfo(getApplicationContext());
if (advertisingIdInfo != null) {
Log.i(TAG, "run: " + getId());
}
} catch (IOException e) {
e.printStackTrace();
}
}
}.start();
}
//安全检测
private void safetydetect() {
SafetyDetectClient client = SafetyDetect.getClient(this);
byte[] bytes = new byte[24];
try {
SecureRandom.getInstance("SHA1PRNG").nextBytes(bytes);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
client.sysIntegrity(bytes,"").addOnSuccessListener(new OnSuccessListener<SysIntegrityResp>() {
@Override
public void onSuccess(SysIntegrityResp sysIntegrityResp) {
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
}
});
//文本矫正
private void document(){
MLDocumentSkewCorrectionAnalyzer documentSkewCorrectionAnalyzer = MLDocumentSkewCorrectionAnalyzerFactory.getInstance().getDocumentSkewCorrectionAnalyzer();
Bitmap bitmap = BitmapFactory.decodeResource(Main6Activity.this.getResources(), R.drawable.document);
MLFrame mlFrame = MLFrame.fromBitmap(bitmap);
documentSkewCorrectionAnalyzer.asyncDocumentSkewDetect(mlFrame).addOnSuccessListener(new OnSuccessListener<MLDocumentSkewDetectResult>() {
@Override
public void onSuccess(MLDocumentSkewDetectResult result) {
Point leftBottomPosition = result.getLeftBottomPosition();
Point leftTopPosition = result.getLeftTopPosition();
Point rightBottomPosition = result.getRightBottomPosition();
Point rightTopPosition = result.getRightTopPosition();
List<Point> points = new ArrayList<>();
points.add(leftBottomPosition);
points.add(leftTopPosition);
points.add(rightBottomPosition);
points.add(rightTopPosition);
MLDocumentSkewCorrectionCoordinateInput mlDocumentSkewCorrectionCoordinateInput = new MLDocumentSkewCorrectionCoordinateInput(points);
documentSkewCorrectionAnalyzer.asyncDocumentSkewCorrect(mlFrame,mlDocumentSkewCorrectionCoordinateInput).addOnSuccessListener(new OnSuccessListener<MLDocumentSkewCorrectionResult>() {
@Override
public void onSuccess(MLDocumentSkewCorrectionResult mlDocumentSkewCorrectionResult) {
Bitmap corrected = mlDocumentSkewCorrectionResult.getCorrected();
btn_img.setImageBitmap(corrected);
}
});
}
});
}
private void imageclassify() {
MLImageClassificationAnalyzer localImageClassificationAnalyzer = MLAnalyzerFactory.getInstance().getLocalImageClassificationAnalyzer();
Bitmap bitmap = BitmapFactory.decodeResource(Main6Activity.this.getResources(), R.id.divider.furit);
MLFrame mlFrame = MLFrame.fromBitmap();
localImageClassificationAnalyzer.analyseFrame()
MLImageClassificationAnalyzer localImageClassificationAnalyzer = MLAnalyzerFactory.getInstance().getLocalImageClassificationAnalyzer();
Bitmap bitmap = BitmapFactory.decodeResource(Main6Activity.this.getResources(), R.drawable.friut);
MLFrame mlFrame = MLFrame.fromBitmap(bitmap);
localImageClassificationAnalyzer.asyncAnalyseFrame(mlFrame).addOnSuccessListener(new OnSuccessListener<List<MLImageClassification>>() {
@Override
public void onSuccess(List<MLImageClassification> mlImageClassifications) {
for (MLImageClassification mlImageClassification : mlImageClassifications) {
System.out.println(mlImageClassification.getName());
}
}
});
}
//文本识别
private void textrecongition() {
MLLocalTextSetting zh = new MLLocalTextSetting.Factory().setLanguage("zh").setOCRMode(MLLocalTextSetting.OCR_DETECT_MODE).create();
MLTextAnalyzer localTextAnalyzer = MLAnalyzerFactory.getInstance().getLocalTextAnalyzer(zh);
Bitmap bitmap = BitmapFactory.decodeResource(Main6Activity.this.getResources(), R.drawable.text);
MLFrame mlFrame = MLFrame.fromBitmap(bitmap);
localTextAnalyzer.asyncAnalyseFrame(mlFrame).addOnSuccessListener(new OnSuccessListener<MLText>() {
@Override
public void onSuccess(MLText mlText) {
System.out.println(mlText.getStringValue());
}
});
}
}
具体浏览华为开发文档:文档中心https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides/introduction-0000001050706106