我有这个错误:E/ViewRootImpl: sendUserActionEvent() mView == null
。
为什么呢?
我的三星Galaxy标签S2的软件版本为6.0.1。
我希望你能帮助我!
先谢谢大家!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! / p>
创建PDF:
public void createPDF() {
Document doc = new Document();
try {
String path = Environment.getExternalStorageDirectory()
.getAbsolutePath() + "/droidText";
File dir = new File(path);
if (!dir.exists())
dir.mkdirs();
Log.d("PDFCreator", "PDF Path: " + path);
//File file = new File(dir, "sample.pdf");
File file = new File(dir, "ciccia.pdf");
FileOutputStream fOut = new FileOutputStream(file);
PdfWriter.getInstance(doc, fOut);
// open the document
doc.open();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Bitmap bitmap = BitmapFactory.decodeResource(getContext()
.getResources(), R.drawable.androtuto);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
Image myImg = Image.getInstance(stream.toByteArray());
myImg.setAlignment(Image.MIDDLE);
// add image to document
doc.add(myImg);
Paragraph spazio = new Paragraph(" ");
Font spazioFont = new Font(Font.COURIER, 14.0f, Color.GREEN);
spazio.setAlignment(Paragraph.ALIGN_CENTER);
spazio.setFont(spazioFont);
Paragraph pTavolo = new Paragraph("numero tavolo: "+numeroTavolo);
Font paraFontTavolo = new Font(Font.COURIER);
pTavolo.setAlignment(Paragraph.ALIGN_CENTER);
pTavolo.setFont(paraFontTavolo);
// add paragraph to document
doc.add(pTavolo);
Paragraph p1 = new Paragraph(string);
System.out.println(string);
Font paraFont = new Font(Font.COURIER);
p1.setAlignment(Paragraph.ALIGN_CENTER);
p1.setFont(paraFont);
doc.add(p1);
Paragraph pizzeOrdinate = new Paragraph("Pizze ordinate: "+string2);
Font paraFontPizzeOrdinate = new Font(Font.COURIER, 14.0f, Color.GREEN);
pizzeOrdinate.setAlignment(Paragraph.ALIGN_CENTER);
pizzeOrdinate.setFont(paraFontPizzeOrdinate);
doc.add(pizzeOrdinate);
// add paragraph to document
Paragraph p3 = new Paragraph("TOTALE Pizze: "+totalepizze);
Font paraFont3 = new Font(Font.COURIER, 14.0f, Color.GREEN);
p3.setAlignment(Paragraph.ALIGN_CENTER);
p3.setFont(paraFont3);
doc.add(p3);
doc.add(spazio);
doc.add(spazio);
Paragraph p2 = new Paragraph("BIBITE ordinate"+string4);
System.out.println(string4);
Font paraFont2 = new Font(Font.COURIER, 14.0f, Color.GREEN);
p2.setAlignment(Paragraph.ALIGN_CENTER);
p2.setFont(paraFont2);
doc.add(p2);
Paragraph p4 = new Paragraph("TOTALE Bibite: "+totalebibite);
Font paraFont4 = new Font(Font.COURIER, 14.0f, Color.GREEN);
p4.setAlignment(Paragraph.ALIGN_CENTER);
p4.setFont(paraFont4);
doc.add(p4);
doc.add(spazio);
doc.add(spazio);
int costoTotale= totalepizze+totalebibite;
Paragraph p5 = new Paragraph("TOTALE : "+costoTotale);
Font paraFont5 = new Font(Font.COURIER, 14.0f, Color.GREEN);
p5.setAlignment(Paragraph.ALIGN_CENTER);
p5.setFont(paraFont5);
doc.add(p5);
/* Paragraph p3 = new Paragraph("TOTALE: "+tot);
Font paraFont3 = new Font(Font.COURIER, 14.0f, Color.GREEN);
p3.setAlignment(Paragraph.ALIGN_CENTER);
p3.setFont(paraFont3);
doc.add(p3);*/
stream = new ByteArrayOutputStream();
bitmap = BitmapFactory.decodeResource(getContext()
.getResources(), R.drawable.android);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
myImg = Image.getInstance(stream.toByteArray());
myImg.setAlignment(Image.MIDDLE);
// add image to document
doc.add(myImg);
// set footer
Phrase footerText = new Phrase("Pied de page ");
HeaderFooter pdfFooter = new HeaderFooter(footerText, false);
doc.setFooter(pdfFooter);
} catch (DocumentException de) {
// Log.e("PDFCreator", "DocumentException:" + de);
/* Log.e("PDFCreator", "DocumentException:" + de.getMessage());*/
Log.e("PDFCreator", "some message", de);
} catch (IOException e) {
// Log.e("PDFCreator", "ioException:" + e);
Log.e("PDFCreator", "DocumentException:" + e.getMessage());
} finally {
doc.close();
}
}
查看PDF:
public void viewPDF() {
String path = "/sdcard/droidText/ciccia.pdf";
try {
File targetFile = new File(path);
Uri targetUri = Uri.fromFile(targetFile);
Intent intent=new Intent();
intent.setPackage("com.hp.android.print");
//intent = new Intent(Intent.ACTION_VIEW);
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(targetUri, "application/pdf");
startActivity(intent);
}catch(ActivityNotFoundException anfe){
final String appPackageName="com.hp.android.print";
try{
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("market://details?id=" +appPackageName)));
}catch(android.content.ActivityNotFoundException anfer){
startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("https://play.google.com/store/apps/details?id=" +appPackageName)));
}
}
}
ANDROID MANIFEST:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />