2012-03-28 20 views
6

के माध्यम से प्रिंटिंग मैं एक .txt फ़ाइल मुद्रित करने का प्रयास कर रहा हूं जो मेरा एप्लिकेशन FileWriter के माध्यम से सहेजता है।Google क्लाउड प्रिंट

फ़ाइल में सहेजता है /sdcard/StudentLatePass.txt

जब प्रिंट बटन क्लिक किया जाता है, एसडी फ़ाइल सहेजा जाता है और फिर इसे मुद्रित करने के लिए की जरूरत है। मैं google cloud print tutorial का पालन कर रहा हूं।

package com.android.upgrayeddapps.latepass; 



import java.io.File; 
import java.io.FileOutputStream; 
import java.io.OutputStreamWriter; 

import android.app.Activity; 
import android.app.AlertDialog; 
import android.content.Context; 
import android.content.Intent; 
import android.net.Uri; 
import android.os.Bundle; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.EditText; 
import android.widget.Button; 
import android.widget.Toast; 



public class StudentActivity extends Activity 
{ 
    EditText txtData; 
    Button btnPrintTardy; 

    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.student); 

     //Displays the Custom dialog for student login 
     AlertDialog.Builder builder; 
     AlertDialog alertDialog; 

     Context mContext = this; 
     LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE) ; 
     View layout = inflater.inflate(R.layout.studentlogin, null); 

     builder = new AlertDialog.Builder(mContext); 
     builder.setView(layout);    

     alertDialog = builder.create(); 
     alertDialog.show(); 

     txtData = (EditText) findViewById(R.id.editText1); 

     btnPrintTardy = (Button) findViewById(R.id.btnPrintTardy); 
     btnPrintTardy.setOnClickListener(new OnClickListener() { 

     public void onClick(View v) { 
      // write on SD card file data in the text box 
      try { 
       File myFile = new File("/sdcard/StudentLatePass.txt"); 
       myFile.createNewFile(); 
       FileOutputStream fOut = new FileOutputStream(myFile); 
       OutputStreamWriter myOutWriter = 
             new OutputStreamWriter(fOut); 
       myOutWriter.append(txtData.getText()); 
       myOutWriter.close(); 
       fOut.close(); 
       Toast.makeText(getBaseContext(), 
         "Done writing SD 'StudentLatePass.txt'", 
         Toast.LENGTH_SHORT).show(); 
      } catch (Exception e) { 
       Toast.makeText(getBaseContext(), e.getMessage(), 
         Toast.LENGTH_SHORT).show(); 
      } 


     }// onClick 
     }); // btnWriteSDFile 


     btnPrintTardy.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      //Print using Google Cloud Print 
      Intent printIntent = new Intent(this, PrintDialogActivity.class); 
       printIntent.setDataAndType(docUri, "text/plain"); 
       printIntent.putExtra("title", "Student Late Pass"); 
       startActivity(printIntent); 

      }// onClick 
    });// btnPrintSDFile 




    } 

    // Clear all activities on the top of the stack and deliver the intent to (on top now) MainActivity with a new Intent 
    public void onGotoLatePassActiviy(View View) 
    { 
     Intent intent = new Intent(View.getContext(), LatePassActivity.class); 
     intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     StudentActivity.this.finish(); 
    } 
} 

मुझे के जीवन के लिए मैं सूर्य के नीचे सब कुछ करने के लिए docUri, docMimeType और docTitle बदलने के लिए इस फ़ाइल को मुद्रित करने के लिए कोशिश की है।

मेरे वर्तमान संशोधित कोड

btnPrintTardy.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      //Print using Google Cloud Print 
      Intent printIntent = new Intent(this, PrintDialogActivity.class); 
       printIntent.setDataAndType(docUri, "text/plain"); 
       printIntent.putExtra("title", "Student Late Pass"); 
       startActivity(printIntent); 

      }// onClick 
    });// btnPrintSDFile 

मैं अभी भी docUri के तहत लाल squigglies हो रही है, और जब मैं Print

+0

"लाल squigglies" पर होवर और यह क्या कहता है? – prolink007

+0

http://i.imgur.com/9RBOr.jpg – UPGRAYEDD

उत्तर

6

के इरादे से पारित इस कोशिश करो और देखो क्या होता है:

Intent printIntent = new Intent(StudentActivity.this, PrintDialogActivity.class);

जो पहले "लाल squigglies" को हल करना चाहिए।


यहां यूआरआई समस्या के लिए आप कोशिश कर सकते हैं।

File file = new File("/sdcard/StudentLatePass.txt"); 
intent.setDataAndType(Uri.fromFile(file), "text/*"); 
+0

vwola, अब क्या आप जानते हैं कि मुझे docuri को बदलने की क्या ज़रूरत है? यह फ़ाइल सहेजती है /sdcard/StudentLatePass.txt – UPGRAYEDD

+0

पर मैंने कुछ और जानकारी जोड़ दी है, अगर यह काम करता है तो मुझे बताएं। अगर यह काम करता है तो मुझे एक +1 दें। =) – prolink007

+1

मुझे लगता है कि आप दोनों ने अभी अपना दिन बनाया है। – wHiTeHaT

संबंधित मुद्दे