I want to select one or more images in application (Activity) and use them in Service. I receive Uris using Intent like this:
Intent galleryIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
galleryIntent.setType("image/*");
galleryIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(galleryIntent, "Select Picture"), RESULT_LOAD_IMG);
Uris I get work but only for some time. From what I understand Uris are temporary. In my case I need permanent links to image files.
Is there a simple way to receive usable (in this situation) link to an image file?
Is there a simple way to receive usable (in this situation) link to an image file?
Copy the image to your app's internal storage.
On Android 4.4+, you could use ACTION_OPEN_DOCUMENT and the Storage Access Framework, instead of ACTION_GET_CONTENT (or, worse, ACTION_PICK). With the Storage Access Framework, you can request to take persistent permissions for the Uri, which increases the odds that you will be able to access the content in the future. However, even in that case, the user can always get rid of the image in question, eliminating your access to it.
Related
I'm making a galley app and I have created a background service with an IntentService that classifies images so I want to send them to an activity that will show them whenever the user wants, for this reason, I don't want to open the activity right after the service finished the task. I have read that you can use SharedPreferences to share data between activities but according to the Android documentation you can only pass a relatively small collection of key-values. In my case, I want to send an ArrayList of files.
Instead of sending list of files, you can just send the absolute path or files. So it would be only a list of strings
I am creating an application that allows the user to store information about food recipes that they can share on social media. I have an activity that allows the user to upload an image, write ingredients and directions for the recipe. In the past I have worked with shared preferences for saving user information, however, I know that the information stored is unordered. So I want to know what type of storage I should use to achieve this outcome....
My activity that saves user data:
From this I want to load the information into a previous activities list view that will have this type of list element layout:
From this what type of storage approach should I take? if I use shared preferences can I just place the parts I need into the elements of the list manually, for example, extracting the image saved from the user and placing that inside the image section of the listviews? or will the limitations of shared get in the way and maybe use internal storage? what would be the best approach?
Form a structured JSON object out of your data and you can use REALM. It is a new and easy alternative to SQLite.
It is very fast, easy to learn and integrate in your app.
Also, it is scalable means if you decide that you will be taking the same data to your backend then it will be easy for you to handle large amount of data.
I'm trying to let the user choose any image that they want on their device to use as a wallpaper in this wallpaper application I'm building. For some reason when I write:
Intent myIntent = new Intent(Intent.ACTION_PICK);
myIntent.setType("image/*");
startActivityForResult(myIntent, 100);
I go straight into the gallery, but when I write:
Intent myIntent = new Intent(Intent.ACTION_GET_CONTENT, null);
myIntent.setType("image/*");
startActivityForResult(myIntent, 100);
I get to choose from Gallery, or Google Drive. What is the best way to let the user choose what app to retrieve the picture from every time? Or why do those two different intent constants make a difference?
Your first Intent is invalid. The protocol for ACTION_PICK requires you to supply a Uri indicating the collection you are picking from.
What is the best way to let the user choose what app to retrieve the picture from every time?
If you want the user to choose something based on MIME type, use ACTION_GET_CONTENT.
If you have some specific collection (identified by a Uri) that you want the user to pick from, use ACTION_PICK.
In case of a tie, go with ACTION_GET_CONTENT. While ACTION_PICK is not formally deprecated, Dianne Hackborn recommends ACTION_GET_CONTENT.
The modern action is ACTION_GET_CONTENT, which is much better supported,
ACTION_PICK :
Activity Action: Pick an item from the data, returning what was selected.
Input: getData() is URI containing a directory of data (vnd.android.cursor.dir/*) from which to pick an item.
Output: The URI of the item that was picked.
Constant Value: "android.intent.action.PICK"
Difference :-
Activity Action: Allow the user to select a particular kind of data and return it.
This is different than ACTION_PICK in that here we just say what kind of data is desired, not a URI of existing data from which the user can pick.
A ACTION_GET_CONTENT could allow the user to create the data as it runs (for example taking a picture or recording a sound), let them browse over the web and download the desired data, etc.
Reference http://developer.android.com/reference/android/content/Intent.html#ACTION_GET_CONTENT
public static final String ACTION_GET_CONTENT
Added in API level 1
Activity Action: Allow the user to select a
particular kind of data and return it. This is different than
ACTION_PICK in that here we just say what kind of data is desired, not
a URI of existing data from which the user can pick. A
ACTION_GET_CONTENT could allow the user to create the data as it runs
(for example taking a picture or recording a sound), let them browse
over the web and download the desired data, etc.
via http://developer.android.com/reference/android/content/Intent.html#ACTION_GET_CONTENT
I am making my first android app. I want to save an array of strings in one activity and then in second activity i want to show those strings as a list. I am using android platform 2.2 with API 8 So i can not use putStringSet(). Is there any way to save my data as a text file in my app? Then may be i can just add a new line in that file whenever user adds a new string. And while making list view i can parse it on basis of new line and make string array.
Thanks for your help.
Use File Handling.
Easy to use for beginners and efficient for your purpose.
http://developer.android.com/guide/topics/data/data-storage.html#filesInternal
There is a method putStringArrayListExtra("id", ArrayList list) in Intent to use before starting it. Then in the launched Activity from the Intent, use getStringArrayList("id").
For example:
Intent intent = new Intent(MainActivity.this.getApplicationContext(), NewActivity.class);
intent.putStringArrayListExtra("id", yourArrayList)
MainActivity.this.startActivity(intent);
Then on NewActivity onCreate() method
ArrayList<String> list = getIntent().getExtras().getStringArrayList("id");
But you can use putStringArray, or putStringArrayList wrapped into a Bundle.
Bundle are passed via Intents.
-> http://developer.android.com/reference/android/os/Bundle.html#putStringArray(java.lang.String, java.lang.String[])
Then, if you want to save it as a file, then you have to use this method : http://www.java-forums.org/advanced-java/13852-saving-arraylist-file.html
But i think you prefer pass the String list directly.
Why are you using files for that?
Just check sharedPreferences and sqliteDb
It may work for you..shared preferences are easy to handle
I need to send images over a very low-bandwidth connection from an android phone (down to 10kByte/s) and would like to send them in progressive (interlaced) mode so that the user at the other end starts seeing the image already during the lengthy transfer. Right now, I am creating the image with the regular photo app:
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
But this creates non-progressive photos and I have not been able to discover how to convince it to do otherwise. The second option I explored (reading and re-compressing the taken image) got foiled because the Bitmap's compress method does not allow any encoding parameters besides format name and compression factor as far as I could determine:
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, out);
My preferred solution would be to instruct the photo app to save in progressive mode.
The next best option would be a Java algorithm that losslessly converts the stored jpeg to progressive (jpegtran does this on Linux, but it is in C and relies on libjepeg).
The next best would a method to specify the relevant encoding parameters to android allowing me to re-compress it, or an alternative Java library that does the same.
Further research revealed that the algorithms are already there (/system/lib/libjpeg.so) with the sources in ~/android-sdk-linux/source-tree/external/jpeg -- but there do not seem to be JNI wrappers readily available.
Have you seen this document?
http://docs.oracle.com/javase/6/docs/api/javax/imageio/plugins/jpeg/JPEGImageWriteParam.html
It seems to have write progressive support.
Alternatively, you could use e.g. OpenJPEG through JNI. See http://www.linux-mag.com/id/7697/ as a start.