2013-06-20 8 views
2

Google 클라우드 프린트를 Android 프로젝트와 함께 사용하여 PDF 파일을 인쇄하고 있습니다. 프로젝트의 assets 폴더에 파일을 저장할 때 인쇄 할 때 "Document Missing"이라고 말합니다.Android 클라우드 프린트 사용

여기에 내 코드 어떤 도움에 감사드립니다

public void stevePrint(View view) { 
    Intent printIntent = new Intent(this, PrintDialogActivity.class); 
    //Cant find file, why? 
    File file = new File("/assets/steve.pdf"); 
    printIntent.setDataAndType(Uri.fromFile(file), "document/pdf"); 
    printIntent.putExtra("title", "Steve"); 
    startActivity(printIntent); 

    Context context = getApplicationContext(); 
    CharSequence text = "Sending to Google Cloud Print"; 
    int duration = Toast.LENGTH_LONG; 

    Toast toast = Toast.makeText(context, text, duration); 
    toast.show(); 
} 

입니다!

+0

file.exists()가 true를 반환합니까? – flumpb

답변

9

잘못된 MIME 형식을 사용하고있는 것으로 보입니다. 읽어야 당신이 PrintDialogActivity, from the Google Cloud Print documentation를 사용하는 것처럼

printIntent.setDataAndType(Uri.fromFile(file), "application/pdf"); 

것 같습니다. PrintDialogJavaScriptInterface 안의 각 메소드에 @JavascriptInterface 주석을 추가해야합니다.

+2

답변으로 표시해야합니다. 또한 누군가 클라우드 프린트를 실행할 수 있지만 프린트 버튼이 작동하지 않으면 android.webkit.JavascriptInterface;를 가져와야합니다. Paul이 말한대로 @JavascriptInterface를 추가하십시오. 나는 몇 주 동안 그것을 해결하는 방법을 모색 해왔다. 간과하기 쉽습니다. Paul 대단히 감사합니다! – ChallengeAccepted

+0

위의 모든 것을 시도해보십시오. 여전히 Document Missing과 같은 문제가 발생합니다. 이 몸에 어떤 도움을받을 수 있습니까? – Gaurang