I am trying to get the file from email attachment and and get it as content as in URI,
the code written in eclips runs fine and got the file from IOStream class but can not find any solution in Titanium....
Is there any alternate solution is posible for this problem??
var activity = Ti.Android.currentActivity; var intentData = activity.getIntent().getData();Eclips code running file and generate file from intent data....
public class MainActivityTest extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Intent intent = getIntent(); Uri returned_uri = intent.getData(); if (returned_uri == null) { Toast.makeText(getApplicationContext(), "Uri is Null", Toast.LENGTH_LONG).show(); } else { try { if (getIntent().getScheme().equals("file")) { String path = getIntent().getData().getPath(); File fileSource = new File(path); System.out.println("File Path from SDCard >>>>> ***** : "+fileSource.getPath()); System.out.println("File Path from SDCard >>>>> $$$ : "+path); if(fileSource.getPath().contains("/sdcard/com.logistic.demoopenfile/")) { Toast.makeText(getApplicationContext(), "Source and Destination are same", Toast.LENGTH_LONG) .show(); return; } File fileDest = new File("/sdcard/com.logistic.demoopenfile/","Resume.doc"); copy(fileSource,fileDest); Toast.makeText(getApplicationContext(), "File Imported from SDCard", Toast.LENGTH_LONG) .show(); } else if (!getIntent().getScheme().equals("content")) { InputStream attachment = getContentResolver() .openInputStream(getIntent().getData()); File wallpaperDirectory = new File( "/sdcard/com.logistic.demoopenfile/"); wallpaperDirectory.mkdirs(); FileOutputStream f = new FileOutputStream(new File( "/sdcard/com.logistic.demoopenfile/", "resume.doc")); byte[] buffer = new byte[1024]; int len1 = 0; while ((len1 = attachment.read(buffer)) > 0) { f.write(buffer); } f.close(); Toast.makeText(getApplicationContext(), "File Imported from Email Attachment", Toast.LENGTH_LONG).show(); } } catch (Exception e) { e.printStackTrace(); } } } void copy(File src, File dst) throws IOException { InputStream in = new FileInputStream(src); OutputStream out = new FileOutputStream(dst); // Transfer bytes from in to out byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); } public static String getContentName(ContentResolver resolver, Uri uri) { Cursor cursor = resolver.query(uri, null, null, null, null); System.out.println("Cursor count :" + cursor.getColumnCount()); cursor.moveToFirst(); int nameIndex = cursor .getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME); if (nameIndex >= 0) { return cursor.getString(nameIndex); } else { return null; } } }
Your Answer
This question has been locked and cannot accept new answers.