How to share image from recyclerView arraylist? - java

I am trying to share an images from arraylist,when I click on share button app list appears to share but when I select an app to share,it shows null in another app.
please help me to find out the solution :(
here is my recycler onBindViewHolder code.
holder.send.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
final String image_path = fileslist.get(position).getUri().toString();
File share = new File(image_path);
Uri uri = Uri.fromFile(share);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("image/");
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
context.startActivity(Intent.createChooser(shareIntent, "Share to....."));
}
});
and here how my app is sharing

Related

Intent passing variable malfunction

In my app I am trying to provide two functions to the users. One is uploading a post with an image and the other is to upload post without an image. To do so I created Strings nonselected_image and selected_image (or selected_bitmap). In case of pressing one of the TextViews by user one of the strings will be passed within the intent consequently. It works great when user wishes to create non photo post but when he wants to create one with a photo there are two posts emerging, one with photo and the other without. What did I wrong? Here is my code.
Sending an intent and strings to the next activity
TextView nextScreen = (TextView) view.findViewById(R.id.tvNext);
nextScreen.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d(TAG, "onClick: navigating to the final share screen.");
if (isRootTask()) {
Intent intent = new Intent(getActivity(), NextActivity.class);
intent.putExtra(getString(R.string.selected_image), mSelectedImage);
startActivity(intent);
} else {
Intent intent = new Intent(getActivity(), AccountSettingsActivity.class);
intent.putExtra(getString(R.string.selected_image), mSelectedImage);
intent.putExtra(getString(R.string.return_to_fragment), getString(R.string.edit_profile_fragment));
startActivity(intent);
getActivity().finish();
}
}
});
noPhoto.setOnClickListener(new View.OnClickListener(){
public void onClick (View v) {
mSelectedImage = null;
Intent intent = new Intent(getActivity(), NextActivity.class);
intent.putExtra(getString(R.string.nonselected_image), nonSelectedImage);
startActivity(intent);
}
});
receiving an intent and taking actions accordingly to passed variable
public void onClick(View v) {
Log.d(TAG, "onClick: navigating to the final share screen.");
//upload the image to firebase
// Toast.makeText(NextActivity.this, "Attempting to upload new photo", Toast.LENGTH_SHORT).show();
String caption = mCaption.getText().toString();
if(intent.hasExtra(getString(R.string.selected_image))){
imgUrl = intent.getStringExtra(getString(R.string.selected_image));
Toast.makeText(NextActivity.this, "Attempting to upload a normal photo", Toast.LENGTH_SHORT).show();
mFirebaseMethods.uploadNewPhoto(getString(R.string.new_photo), caption, imageCount, imgUrl,null);
}
else if(intent.hasExtra(getString(R.string.selected_bitmap))){
bitmap = (Bitmap) intent.getParcelableExtra(getString(R.string.selected_bitmap));
Toast.makeText(NextActivity.this, "Attempting to upload a new bitmap", Toast.LENGTH_SHORT).show();
mFirebaseMethods.uploadNewPhoto(getString(R.string.new_photo), caption, imageCount, null,bitmap);
}
else if(intent.hasExtra(getString(R.string.nonselected_image)));{
Toast.makeText(NextActivity.this, "Attempting to upload new photo", Toast.LENGTH_SHORT).show();
imgUrl = intent.getStringExtra(getString(R.string.nonselected_image));
mFirebaseMethods.uploadNoPhoto(getString(R.string.new_photo), caption, imageCount, imgUrl, null); // HERE IS THE ERROR
}

Open a URL when click on ImageView on Android

I get the following error below
startActivity (android.content.intent) in activity cannot be applied to (intent)
For this code - I have tried many different things - is there anything I need to add to the manifest? Thank you so much for your help!
img = (ImageView) findViewById(R.id.Fb);
img.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
intent browserintent = new intent("android.intent.action.VIEW", Uri.parse("www.yahoo.com"));
startActivity(browserintent);
}
}
Change your code to this
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.yahoo.com"));
startActivity(browserIntent);
You are missing a scheme http or https in your Uri:
Intent browserintent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.yahoo.com"));
startActivity(browserintent);
Try this code
Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse("http://www.yahoo.com"));
startActivity(intent);

Save drawables in local storage as cache and then read them for a Share_Intent?

I have drawables in my project that i have declared as seperate resource array
public Integer[] mThumbIds = {
R.drawable.ic_bl1,
R.drawable.ic_bl2,
R.drawable.ic_bl3,
R.drawable.ic_bl4,
R.drawable.ic_bl5,
R.drawable.ic_ca1,
R.drawable.ic_ca2,
R.drawable.ic_ch}
I want to save them all in a temp folder on local storage of android(not SD Card)so that I can retrieve them later and send them via a share intent.I have code for share Intent completed
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("image/*");
sharingIntent.putExtra(Intent.EXTRA_STREAM, path);
// sharingIntent.setPackage("com.facebook.orca");
sharingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Intent chooserIntent = Intent.createChooser(sharingIntent, "Send Via");
chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sContext.startActivity(chooserIntent);
// sContext.startActivity(sharingIntent);
}
});
I need to pass a Uri of a particular file to be sent,and best way to get it is through saving images in local storage and then retrieving there Uri.I know how to save a single image in cache and then retrieving it.
I can't figure out how to save a list of drawables in a particular folder on local storage and then retrieving there Uris for a use in share intent later.
You could use this code.
But add read and write storage permission.
public void onClick(View view) {
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("image/png");
ImageView imageView = (ImageView) view;
Drawable mDrawable = imageView.getDrawable();
Bitmap mBitmap = ((BitmapDrawable) mDrawable).getBitmap();
String path = MediaStore.Images.Media.insertImage(mContext.getContentResolver(), mBitmap, "Image Description", null);
Uri uri = Uri.parse(path);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(shareIntent, "Share Content!!"));
}

How to share text from android app to facebook?

I try to implement share button in my android app to share in facebook
The code:
facebook.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_SUBJECT,desc.getText().toString());
startActivity(Intent.createChooser(share, "Share description using"));
}
});
The problem is, in the post dialog of the facebook not display the text which i need to share from my app which it is (desc.getText().toString()) . There empty message !! why the text didn't appear !!!
Thanks in advance
Try with this. Hope it help
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "Share Something");
startActivity(Intent.createChooser(intent, "Share with"));

Android - How to open a specific folder in a gallery using an implicit intent?

We are building a camera app that saves photos in a specific folder in the gallery. And we have to open the folder of our app in the gallery using an intent. We are using this code however it shows all folders.
View.OnClickListener goToGallery = new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setType("image/*");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
};
To open gallery I use this intent.
public static final int RESULT_GALLERY = 0;
Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent , RESULT_GALLERY );
Try this code.
It will retrieve view pictures under storage/emulated/0/Pictures/MyAppPics
You can change the file path according to your directory path.
File sdDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File f = new File(sdDir, "MyAppPics");
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setDataAndType(Uri.withAppendedPath(Uri.fromFile(f), "/MyAppPics"), "image/*");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);

Categories