David PHAM-VAN

Fix Android compilation issues

# Changelog
## 3.6.3
- Fix Android compilation issues
## 3.6.2
- Added theme color to dropdown item in pageFormat selector in page preview
... ...
... ... @@ -35,16 +35,6 @@ for documentation.
use_frameworks! # <-- Add this line
```
4. Set minimum Android version in `android/app/build.gradle`:
```java
defaultConfig {
...
minSdkVersion 21 // <-- Change this line to 21 or more
...
}
```
## Examples
```dart
... ...
... ... @@ -17,16 +17,20 @@
package android.print;
import android.content.Context;
import android.os.Build;
import android.os.CancellationSignal;
import android.os.ParcelFileDescriptor;
import android.util.Log;
import androidx.annotation.RequiresApi;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public class PdfConvert {
public static void print(final Context context, final PrintDocumentAdapter adapter,
final PrintAttributes attributes, final Result result) {
... ...
package net.nfet.flutter.printing;
import android.app.Activity;
import android.os.Build;
import android.print.PrintAttributes;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import java.util.HashMap;
... ... @@ -21,15 +23,10 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler {
@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
switch (call.method) {
case "printPdf": {
final String name = call.argument("name");
final Double width = call.argument("width");
final Double height = call.argument("height");
final Double marginLeft = call.argument("marginLeft");
final Double marginTop = call.argument("marginTop");
final Double marginRight = call.argument("marginRight");
final Double marginBottom = call.argument("marginBottom");
final PrintingJob printJob =
new PrintingJob(activity, this, (int) call.argument("job"));
... ... @@ -70,14 +67,15 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler {
assert marginRight != null;
assert marginBottom != null;
PrintAttributes.Margins margins =
new PrintAttributes.Margins(Double.valueOf(marginLeft * 1000.0).intValue(),
PrintAttributes.Margins margins = new PrintAttributes.Margins(
Double.valueOf(marginLeft * 1000.0).intValue(),
Double.valueOf(marginTop * 1000.0 / 72.0).intValue(),
Double.valueOf(marginRight * 1000.0 / 72.0).intValue(),
Double.valueOf(marginBottom * 1000.0 / 72.0).intValue());
PrintAttributes.MediaSize size = new PrintAttributes.MediaSize("flutter_printing",
"Provided size", Double.valueOf(width * 1000.0 / 72.0).intValue(),
PrintAttributes.MediaSize size =
new PrintAttributes.MediaSize("flutter_printing", "Provided size",
Double.valueOf(width * 1000.0 / 72.0).intValue(),
Double.valueOf(height * 1000.0 / 72.0).intValue());
printJob.convertHtml((String) call.argument("html"), size, margins,
... ... @@ -103,9 +101,13 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler {
result.notImplemented();
break;
}
} else {
result.notImplemented();
}
}
/// Request the Pdf document from flutter
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
void onLayout(final PrintingJob printJob, Double width, double height, double marginLeft,
double marginTop, double marginRight, double marginBottom) {
HashMap<String, Object> args = new HashMap<>();
... ... @@ -141,6 +143,7 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler {
}
/// send completion status to flutter
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
void onCompleted(PrintingJob printJob, boolean completed, String error) {
HashMap<String, Object> args = new HashMap<>();
args.put("completed", completed);
... ... @@ -152,6 +155,7 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler {
}
/// send html to pdf data result to flutter
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
void onHtmlRendered(PrintingJob printJob, byte[] pdfData) {
HashMap<String, Object> args = new HashMap<>();
args.put("doc", pdfData);
... ... @@ -161,6 +165,7 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler {
}
/// send html to pdf conversion error to flutter
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
void onHtmlError(PrintingJob printJob, String error) {
HashMap<String, Object> args = new HashMap<>();
args.put("error", error);
... ... @@ -170,6 +175,7 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler {
}
/// send pdf to raster data result to flutter
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
void onPageRasterized(PrintingJob printJob, byte[] imageData, int width, int height) {
HashMap<String, Object> args = new HashMap<>();
args.put("image", imageData);
... ... @@ -180,6 +186,8 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler {
channel.invokeMethod("onPageRasterized", args);
}
/// The page has been converted to an image
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
void onPageRasterEnd(PrintingJob printJob) {
HashMap<String, Object> args = new HashMap<>();
args.put("job", printJob.index);
... ...
... ... @@ -18,20 +18,35 @@ package net.nfet.flutter.printing;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.pdf.PdfRenderer;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.Handler;
import android.os.Looper;
import android.os.ParcelFileDescriptor;
import android.print.PageRange;
import android.print.PdfConvert;
import android.print.PrintAttributes;
import android.print.PrintDocumentAdapter;
import android.print.PrintDocumentInfo;
import android.print.PrintJob;
import android.print.PrintJobInfo;
import android.print.PrintManager;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.core.content.FileProvider;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
... ... @@ -39,16 +54,12 @@ import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.util.HashMap;
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
import android.content.pm.ResolveInfo;
import java.util.List;
/**
* PrintJob
*/
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public class PrintingJob extends PrintDocumentAdapter {
private static PrintManager printManager;
private final Context context;
... ... @@ -216,11 +227,14 @@ public class PrintingJob extends PrintDocumentAdapter {
shareIntent.putExtra(Intent.EXTRA_STREAM, apkURI);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Intent chooserIntent = Intent.createChooser(shareIntent, null);
List<ResolveInfo> resInfoList = context.getPackageManager().queryIntentActivities(chooserIntent, PackageManager.MATCH_DEFAULT_ONLY);
List<ResolveInfo> resInfoList = context.getPackageManager().queryIntentActivities(
chooserIntent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
context.grantUriPermission(packageName, apkURI, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.grantUriPermission(packageName, apkURI,
Intent.FLAG_GRANT_WRITE_URI_PERMISSION
| Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
context.startActivity(chooserIntent);
shareFile.deleteOnExit();
... ...
... ... @@ -4,7 +4,7 @@ description: Plugin that allows Flutter apps to generate and print documents to
homepage: https://github.com/DavBfr/dart_pdf/tree/master/printing
repository: https://github.com/DavBfr/dart_pdf
issue_tracker: https://github.com/DavBfr/dart_pdf/issues
version: 3.6.2
version: 3.6.3
environment:
sdk: ">=2.3.0 <3.0.0"
... ...