I need a quick help on how to convert android Uri to Java URI. My requirement is to capture images and store them in External storage. To pass these images across activities, I decided to use an Arraylist that holds Uris of images and pass on this arraylist as an intent-extra to next activity. But, Arraylist accepts only JavaURI.
String image = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
File photo=new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),image);
selectedImageA=Uri.fromFile(photo);
imageIndex++;
selectedImageJ= <Looking for code here>;
imagesUriArray.add(imageIndex,selectedImageJ);
Intent i = new Intent(getApplicationContext(),ScanActivity.class);
startActivity(i);
Try to declare:
ArrayList<Uri> imagesUriArray = new ArrayList<Uri>;
If this doesn't work, declare your ArrayList as String list and convert the uri to String. And later, initialize the uri from the Uri string
Related
HI can anyone please help me i am trying to share text with multiple image but i am getting this error Key android.intent.extra.TEXT expected ArrayList but value was a java.lang.String. The default value was returned.
Here is my code-
String text = "Share text.";
Uri pictureUri = getLocalBitmapUri(shareImg_imvw);
uriList.clear();
for(int i=0;i<5;i++)
{
uriList.add(pictureUri);
}
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
shareIntent.setType("*/*");
// shareIntent.putExtra(Intent.EXTRA_TEXT, text);
// new code
ArrayList<String> extra_text = new ArrayList<String>();
extra_text.add(text);
shareIntent.putStringArrayListExtra(Intent.EXTRA_TEXT, extra_text);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriList);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, getString(R.string.send_intent_title)));
First, ACTION_SEND and ACTION_SEND_MULTIPLE support either EXTRA_TEXT or EXTRA_STREAM. Apps do not have to support both. Do not expect both to be used by all apps.
Second, ACTION_SEND_MULTIPLE requires that EXTRA_TEXT and EXTRA_STREAM be ArrayList extras. Replace putExtra() with putStringArrayListExtra(), passing in an ArrayList<String> of the multiple strings that you want to share.
i have a file that i got back from parse.com and i am trying to get the string stored in that file to a textView. At the moment all i am getting is a url in my text view and not the string i need.
getting the parse file:
ParseFile file = message.getParseFile("file");
Uri fileUri = Uri.parse(file.getUrl());
//passing it to another class
intent.setData(fileUri);
getting the file to display in textview
mDisplay = (TextView)findViewById(R.id.messageDisplay);
Uri textUri = getIntent().getData();
// i have tried this also [ File string = new File(textUri.toString()); ]
String filePath = textUri.getEncodedPath();
mDisplay.setText(filePath);
i have tried:-
1] to get the string bytes before passing string via intent
2] getting url and then converting to string
and 1 or 2 more methods. all are displaying the url and not the string, i feel the issue may lie in this line
Uri fileUri = Uri.parse(file.getUrl());
but i am not sure.
I am new to java.
I have a directory with a txt file (R.raw). I want to get access with a command
InputStream in_s = res.openRawResource(R.raw.itemname);
where itemname is a dynamic string with a filename from a previous activity.
How do I can get open file in R.raw by a string "n0.txt"?
In javascript I can implement it like R.raw["n0.txt"] or R.raw.itemname.
Thanks in advance.
You need to use method getIdentifier().
Context context;
Resources res;
int itemId = res.getIdentifier("itemname", "raw", context.getPackageName());
InputStream is = res.openRawResource(itemId);
Original post here.
Here is what I am passing. pictureFile is a File
Intent intent = new Intent (context, ShowPicActivity.class);
intent.putExtra("picture", pictureFile);
In the next activity which one of the getters do I use to get it?
Intent intent = getIntent(); .....?
File implements serializable ( first thing to check to send an object through an intent. )
( source )
so you can do it, just cast the resulting object to File like this :
File pictureFile = (File)getIntent.getExtras().get("picture");
It should be fine.
(it use the getter for 'object' which needs a serializable object and return it. The cast should be enough.)
Try the following:
YourPictureClass picture = (YourPictureClass)getIntent().getExtras().get("picture");
By calling getExtras() in your Intent you get an instance of Bundle.
With the normal get() in class Bundle you can read every Object you pass to the calling Intent. The only thing you have to do is to parse it back to the class your object is an instance of.
You can send it like this:
intent.putExtra("MY_FILE", myFile);
and retrieve it like this:
File myFile = (File)intent.getSerializableExtra("MY_FILE");
However, it may be better (anyone?) to send the file as a string reference, in which case you could send as:
intent.putExtra("MY_FILE_STRING", myFile.toString());
and retrieve/reconstruct like this:
File myFile = new File(intent.getStringExtra("MY_FILE_STRING"));
I just cannot seem to figure this one out: how do I respond to the ACTION_VIEW and ACTION_SEND intents? I have them in my Manifest file (and they appear in the drop down list of apps). What I need to do is respond to these intents and retrieve a bitmap of the corresponding image.
Right now here is what works:
Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
Bitmap mBitmap = BitmapFactory.decodeStream(cr.openInputStream(uri));
Then I take that uri and fetch a bitmap. However, if I respond when the email app downloads and image getExtras() is null and I get an error.
Basically I need to know what to put in here to fill a variable, mBitmap:
if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_VIEW.equals(action))
{
Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
Bitmap mBitmap = (getExtras() == null) ? what goes here :
BitmapFactory.decodeStream(cr.openInputStream(uri))
}
getIntent().getData() will contain the Uri for which the Intent is targeted.