is there any hope to get file from intent URI receive outside of the application

You must Login before you can answer or comment on any questions.

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;
        }
    }
 
}

— asked 3 years ago by Gaurang Chhatbar
2 Comments
  • Hi Gaurang,

    did you find a solution for this?

    would be great if you could share it here!

    — commented 3 years ago by Roeland P

  • hi,

    if you see the AndroidManifest.custom.xml file part displayed in the given link, it will helpful for you and you can also get reference by developers.android.com for more customize settings, link is included at the last.

    just few things you have to remember that Android just include one intent for activity that you have to register first in AndroidManifest.xml. for that you can directly edit AndroidManifest.xml or make new AndroidManifest.custom.xml file place in root folder with resource folder.

    http://developer.appcelerator.com/question/121939/doc-file-does-not-open-in-android

    http://developer.android.com/guide/topics/intents/intents-filters.html

    Note

    Its an advice to write new AndroidManifest.custom.xml rather than edit AndroidManifest.xml. just copy paste all AndroidManifest.xml in to new AndroidManifest.custom.xml and edit it directly. AndroidManifest.xml change causses the crash in application.

    — commented 3 years ago by Gaurang Chhatbar

Your Answer

This question has been locked and cannot accept new answers.