I want to add image in email, if I add the file from sdcard then its working fine as given below.
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file///sdcard/Images/thumb.jpg)"));
But I want to add the image from assest. I have tried so many pernutation and combination with uri.parse and uri.fromfile but nothing works, can anyone tel how exactly the path should be to add the file from assets. Its very urgent.
isnt it?:
file:/// instead of file///
... you missed the ":"
Refer http://developer.android.com/reference/android/content/res/AssetManager.html
Related
I have an Android app that displays a comic book. To make use of the built-in zoom controls, I am loading the pictures in a WebView like so:
webView.loadUrl("file:///android_asset/page1.jpg");
This is working just fine, however, since the images are in the assets folder, they are not being compressed which makes my .apk enormous. I was wondering how to reference resource files (from the res/drawable folder) with a file path like I did above with the assets. Does anyone know what that path would look like? I've tried things like "file:///res/drawable/pagetitle.jpg" with no success. Thanks for the help.
Update:
I found that "file:///android_res/drawable/page1.jpg" was the path that I was looking for.
from this site
Using the resource id, the format is:
"android.resource://[package]/[res id]"
Uri path = Uri.parse("android.resource://com.androidbook.samplevideo/" + R.raw.myvideo);
or, using the resource subdirectory (type) and resource name (filename without extension), the format is:
"android.resource://[package]/[res type]/[res name]"
Uri path = Uri.parse("android.resource://com.androidbook.samplevideo/raw/myvideo");
I also had to use loadDataWithBaseURL instead of just plain loadData to get the file:///android_res/drawable/page1.jpg to work.
As i need to load a file from SDCard when i am using Environment.getExternalStorageDirectory() or Environment.getExternalStorageDirectory().getAbsolutePath() but it is not working, well it works great with the "file:///sdcard/Avalon/assets/www/filename.html". I don't know what is happening with my path
cwv.loadUrl(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Avalon/assets/www/filename.html", map);
I want make my path generic that's why i need to work it with any generic term...
Great it works... Actually i forgot to add "file://"
So actual path should be
cwv.loadUrl("file://"+Environment.getExternalStorageDirectory().getAbsolutePath()+"/Avalon/assets/www/filename.html", map);
This is my mistake thanks
I want to send a text file in an email letter.
But the thing is that I want this file to be private for my application, and I want to give read permission only for the email app.
So, i use code:
for getting file path:
logFilePath = activity.getDir("my_logs", Context.MODE_PRIVATE) + "/log.txt";
for adding file to the email:
Uri logUri = Uri.fromFile(new File(logFilePath));
mail.putExtra(android.content.Intent.EXTRA_STREAM, logUri);
mail.setType("text/plain");
The file is created, I can see that it is attached to the letter, when I send it, but when I receive the letter there is no attachment.
I tried this options:
mail.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
activity.grantUriPermission("com.google.android.gm", logUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
But the result is the same. I tried to
mail.setData(logUri);
Because I thought that may be the intent world read flag affects only the Data field, but the result was the same.
Then I tried to change the directory permission:
activity.getDir("my_logs", Context.MODE_WORLD_READABLE) + "/log.txt";
But it gave no effect.
The
activity.getCacheDir() + "/log.txt";
is not working too.
The only option that is working is
activity.getExternalCacheDir() + "/log.txt";
So, as I can see, the file in the internal memory is not readable for the email application no matter how I try.
Is there a way to make it readable?
Or may be there is a way to make private directory/file in the external memory?
We should use a content provider in that case. There is a pre-defined content provider for sharing files, very easy to implement: http://developer.android.com/reference/android/support/v4/content/FileProvider.html
I need to build a Uri object from a file path, but using Uri.fromFile(new File(path)) is too slow, so I want to build it manually.
First of all, Uri.parse("file://" + path) does not work, since it does not path-encode the path.
I tried Uri.Builder().scheme("file").path(orgPath).build(), but the result is: file:path instead of file://path.
How can I build a Uri as same as Uri.fromFile() does, in a faster way?
Thank you!
try Uri.encode()
"file://"+Uri.encode(path)
or if you want to allow the string like / or any other than pass it as second parameter
like :
"file://" + Uri.encode(path,"/")
OK I find out I just need to add .auth().
Uri.Builder().scheme("file").auth("").path(orgPath).build() is working fine.
In my application I need to store the images in assets folder and should display them. I have tried all ways but still the image is not displaying. I have tried using Asset Manager, InputStream and Uri but no result finally. Please help me with this issue. I am struugling a lot ...Can u please tell how to give the path....for example I saved my images in assets folder then I am giving as
InputStream val=getAssets().open("/assets/62.gif");
Is that path correct? Please tell me where I went wrong..
Thanks in Advance
Asset file is accessible through following URI:
file:///android_asset/62.gif
Just open it and use
Use
InputStream val=getAssets().open("62.gif");