FileChannel channel = escPosEmulator.randomAccessFile.getChannel();
MappedByteBuffer map = channel.map(FileChannel.MapMode.READ_WRITE, buf.getRowBytes()* escPosEmulator.output_height , buf.getRowBytes()*height);
buf.copyPixelsToBuffer(map);
escPosEmulator.output_height += buf.getHeight();
if (escPosEmulator.output_height > 0) {
Bitmap out = Bitmap.createBitmap(escPosEmulator.max_dots, escPosEmulator.output_height, Bitmap.Config.ARGB_8888);
FileChannel channel = escPosEmulator.randomAccessFile.getChannel();
MappedByteBuffer map = channel.map(FileChannel.MapMode.READ_WRITE, 0, out.getRowBytes() * out.getHeight());
out.copyPixelsFromBuffer(map);
channel.close();
}
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
mContext.getContentResolver().insert(Images.Media.EXTERNAL_CONTENT_URI, values);
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="29" />
static public @Nullable
Uri cacheUri(Uri uri, Context context) throws IOException {
InputStream inputStream = context.getContentResolver().openInputStream(uri);
if (inputStream != null) {
java.io.File outputDir = Objects.requireNonNull(context).getCacheDir(); // context being the Activity pointer
java.io.File outputFile = java.io.File.createTempFile("spool_job_", "",outputDir);
BufferedInputStream input = new BufferedInputStream(inputStream);
BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(outputFile));
// read and write into the cache directory
byte[] bArr = new byte[8192];
while (true) {
int read = input.read(bArr);
if (read < 0) {
break;
} else {
output.write(bArr, 0, read);
}
}
// close the streams
input.close();
output.close();
return Uri.fromFile(outputFile);
}
return null;
}
<SwitchPreferenceCompat
app:defaultValue="false"
android:persistent="false"
app:key="openLink"
app:title="Ссылки на чек"
app:summaryOn="обрабатываются этим приложением"
app:summaryOff="действие по умолчанию в Android">
</SwitchPreferenceCompat>
<Preference
android:key="pref_static_field_key"
android:selectable="false"
android:persistent="false"
android:summary="Чтобы вместо перехода на сайт налоговой, происходила обработка приложением, потребуется подтвердить выбор в системных настройках.\nОткрывать по умолчанию - Добавить ссылку - Поставить галочку"/>
@RequiresApi(api = Build.VERSION_CODES.S)
private boolean checkLinkAssociation() {
Context context = requireActivity();
DomainVerificationManager manager;
manager = context.getSystemService(DomainVerificationManager.class);
DomainVerificationUserState userState;
try {
userState = manager.getDomainVerificationUserState(context.getPackageName());
} catch (PackageManager.NameNotFoundException e) {
return false;
}
Map<String, Integer> hostToStateMap = userState.getHostToStateMap();
for (String key : hostToStateMap.keySet()) {
Integer stateValue = hostToStateMap.get(key);
if (stateValue != null && stateValue != DomainVerificationUserState.DOMAIN_STATE_VERIFIED && stateValue != DomainVerificationUserState.DOMAIN_STATE_SELECTED) {
return false;
}
}
return true;
}
prefOpenLink = findPreference( "openLink");
if (prefOpenLink != null) {
final Intent i = new Intent();
i.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
i.addCategory(Intent.CATEGORY_DEFAULT);
i.setData(Uri.parse("package:" + requireActivity().getPackageName()));
prefOpenLink.setIntent(i);
}
@Override
public void onResume() {
super.onResume();
if (prefOpenLink != null) {
boolean status = true;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
status = checkLinkAssociation();
}
prefOpenLink.setChecked(status);
}
}