Using intent share text with multiple image in android - java

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.

Related

Android to Objective-c translate

I am working on some project have a problem that ios app doesn't play video when opened the page. So I found some source code that didn't have in StandartPlug.m
but issue is that I can not add those codes in Obj-c language from java. Please help me translation.
else if(mServiceId.equals("movFilePlay")) { //hband 이상연대표 요청 220415
String filePath = mParamData.getString( "filePath" );
Intent intent = new Intent( Intent.ACTION_VIEW );
intent.setData( Uri.parse( filePath ) );
startActivity( intent );
break;
I need to translate to Objective-c language ro add required places
I tried to translate it but couldn't

Expected Parcelable for result for camera Intent

I am making a camera intent and storing the snapshot using the activity result, this is my code:
File imageFolder=new File(context.getExternalCacheDir(),"Cam/" + form);
imageFolder.mkdirs();
String random= UUID.randomUUID().toString();
String filename = random + ".jpg";
TakenImage = imageFolder + "/" + filename;
Intent camera=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
camera.putExtra(MediaStore.EXTRA_OUTPUT,TakenImage);
activityResultCamera.launch(camera);
But I get this error on the last line:
Key output expected Parcelable but value was a java.lang.String. The default value was returned.
Attempt to cast generated internal exception:
java.lang.ClassCastException: java.lang.String cannot be cast to android.os.Parcelable
Camera is an Intent, I also declared ActivityResultLauncher as Intent
ActivityResultLauncher<Intent> activityResultCamera = registerForActivityResult(...
So, what I am doing wrong?
EXTRA_OUTPUT needs to be:
A Uri...
With a scheme of content
You have:
A String...
That is a filesystem path that other apps cannot access on Android 10+
Use FileProvider to get a Uri that points to your desired location, and use that Uri in EXTRA_OUTPUT.

android Uri to Java URI

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

Passing File with intent, how do i retrieve it

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"));

Android - Compare strings from Intent

This has to be a really easy answer. I've been searching and searching on how to compare a variable to a string in Java. I have an Intent and only want to declare some vars if data from the intent matches. Surely this can't be that hard. Java is frustrating to me. :)
I know that type will equal message at some point but it doesn't work.
e.g.
String type = intent.getStringExtra("type");
if(type.equals("message")){
String msg = intent.getStringExtra("message");
String avatar = intent.getStringExtra("photo");
count = Integer.parseInt(intent.getStringExtra("count"));
Bitmap photo = getBitmapFromURL(avatar);
String theMessage = Html.fromHtml(msg).toString().replace("\\", "");
}
EDIT:
I did output type to log as suggested and it does show message like it should. I am trying to us the same variable theMessage and photo but it complains that its not declared so it prompts a fix and puts this at the top. Is this what's causing it not to work? This is a notification by the way.
private static String theMessage = null;
private static Bitmap photo = null;
I try to do this later in the code but it complains about not being declared.
if(type.equals("message")){
notification.setSubText(theMessage);
notification.setLargeIcon(photo);
}
So that is what I have and with the static vars it doesn't work at all even after the error of not being declared goes away.
Try instead
Bundle extras = intent.getExtras();
String type = extras.getString("type");
Log.i("type", type);
if(type.equals("message")){
String msg = extras.getString("message");
String avatar = extras.getString("photo");
count = Integer.parseInt(extras.getString("count"));
Bitmap photo = getBitmapFromURL(avatar);
String theMessage = Html.fromHtml(msg).toString().replace("\\", "");
}
and see the logCat what comes against type.
Hope it helps.

Categories