I stored url with id in firebase. I am using viewpager2 in xml. I want to share image or want to add share option in that. How can I do this.
public void onApplyImage(int position, Bitmap bitmap) {
WallpaperManager manager = WallpaperManager.getInstance(getApplicationContext());
try {
manager.setBitmap(bitmap);
Toast.makeText(SwiperActivity.this, "Wallpaper successfully set ", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(SwiperActivity.this, "Failed to set as wallpaper", Toast.LENGTH_SHORT).show();
}
}
#Override
public void onShareImage(int position, Bitmap bitmap) {
}
});
Simple way to share is that first set you image to a ImageView and then use the following code to share you image.
ImageView content = (ImageView)mView.findViewById(R.id.imageViewy);
content.setDrawingCacheEnabled(true);
Uri imageUri= Uri.parse(MediaStore.Images.Media.insertImage(getContentResolver(),
content, "title", "discription"));
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));
Related
I am making a framer app which can be used to frame your image. And i Want to save that image in gallery after framing and for this i have set a button to perform this but in the button by below code i am unable to save my image. After clicking on button it crashes the app activity. please Someone Give me Solution. I am using api level >29.
``` dlbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
OutputStream outputStream;
BitmapDrawable drawable = (BitmapDrawable) mainimg.getDrawable();
Bitmap bitmap = drawable.getBitmap();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
{
ContentResolver resolver = MainActivity2.this.getContentResolver();
ContentValues contentValues = new ContentValues();
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME,"Image_"+".jpg");
contentValues.put(MediaStore.MediaColumns.MIME_TYPE,"image/jpeg");
contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH,Environment.DIRECTORY_PICTURES + File.separator+"TestFolder");
Uri imageUri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,contentValues);
try {
outputStream = resolver.openOutputStream(Objects.requireNonNull(imageUri) );
bitmap.compress(Bitmap.CompressFormat.JPEG,100,outputStream);
Objects.requireNonNull(outputStream);
Toast.makeText(MainActivity2.this, "Image Saved", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(MainActivity2.this, "Image Not Not Saved: \n "+e, Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
}
});
} ``
Hi guys I am totally new in android app development and need some helped. Actually I am working on project i.e. WhatsApp Status Saver.
I did some basic coding.
But Now I want to share video from VideoView.
I done the code for sending Images.
I used the following code.
public class Picture extends AppCompatActivity {
ImageView mparticularimage,
share;
BitmapDrawable drawable;
Bitmap bitmap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_picture);
getSupportActionBar().setTitle("Picture");
mparticularimage=findViewById(R.id.particularImage);
share=findViewById(R.id.share);
share.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//shareoption coding
shareImage();
}
});
private void shareImage() {
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
drawable = (BitmapDrawable) mparticularimage.getDrawable();
bitmap = drawable.getBitmap();
File file = new File(getExternalCacheDir()+"/"+"Status downloaded by - Status saver"+".png");
Intent intent;
try {
FileOutputStream outputStream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG,100, outputStream);
outputStream.flush();
outputStream.close();
intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/+");
intent.putExtra(intent.EXTRA_STREAM, Uri.fromFile(file));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}catch (Exception e){
throw new RuntimeException(e);
}
startActivity(Intent.createChooser(intent,"Share this image via: "));
}
}
The above code perfectly work for Images now how to do the same thing in terms of VideoView and .mp4 files.
Here is my code
Glide.with(getContext())
.asBitmap().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE)
.load(url)
.into(new SimpleTarget<Bitmap>(250, 250) {
#Override
public void onResourceReady(Bitmap resource, #Nullable Transition<? super Bitmap> transition) {
progressBar.setVisibility(View.GONE);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "Share");
String path = MediaStore.Images.Media.insertImage(getContext().getContentResolver(), resource, "", null);
Uri screenshotUri = Uri.parse(path);
intent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
intent.setType("*/*");
startActivity(Intent.createChooser(intent, "Send to"));
}
#Override
public void onLoadFailed(Drawable errorDrawable) {
progressBar.setVisibility(View.GONE);
Toast.makeText(getContext(), "Something went wrong", Toast.LENGTH_SHORT).show();
super.onLoadFailed(errorDrawable);
}
#Override
public void onLoadStarted(Drawable placeholder) {
progressBar.setVisibility(View.VISIBLE);
Toast.makeText(getContext(), "Sharing", Toast.LENGTH_SHORT).show();
super.onLoadStarted(placeholder);
}
});
I am implementing share option in my Android application using URL. The URL contains all types of files like PDF, PNG, DOC, DOCX, etc. I tried to share PNG file among other apps and it's working fine.
The issue is I cannot able to share PDF and other format files except image. How can I share all the MIME type files?
May this example help you, I used this code for Sending PDF files, you can send mutiple by using array and Intent.ACTION_SEND_MULTIPLE:
public void shareFile(File file) {
Uri uri = FileProvider.getUriForFile(mContext, com.example.app, file);
shareFile(uri);
}
Call shareFile function and pass URI
private void shareFile(Uri uri) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, mContext.getString(R.string.file_with_message));
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setType("application/pdf");
mContext.startActivity(Intent.createChooser(intent,"Select app to send file");
}
I tried a code to take screenshot of an Activity then share it , which is works very well but just in Android lower than 6.0 , from 6.0 and higher when i click share button then choose social network a short dialog tell me " unable to load image "
Please i need your help my friends
This the code that i used it :
share.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Bitmap bitmap = takeScreenshot();
saveBitmap(bitmap);
shareIt();
}
public Bitmap takeScreenshot() {
View rootView = findViewById(android.R.id.content).getRootView();
rootView.setDrawingCacheEnabled(true);
return rootView.getDrawingCache();
}
public void saveBitmap(Bitmap bitmap) {
imagePath = new File(Environment.getExternalStorageDirectory() + "/screenshot.png");
FileOutputStream fos;
try {
fos = new FileOutputStream(imagePath);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
Log.e("GREC", e.getMessage(), e);
} catch (IOException e) {
Log.e("GREC", e.getMessage(), e);
}
}
private void shareIt() {
Uri uri = Uri.fromFile(imagePath);
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("image/*");
String shareBody = "In Tweecher, My highest score with screen shot";
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "My Tweecher score");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(sharingIntent, "Share via"));
}
});
displayResults();
}
EDIT :
I try to replace Uri uri = Uri.fromFile(imagePath); by Uri uri = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".my.package.name.provider", imagePath);
But it says app was stopped when i click Share button
Any help pleaaaase
If FileUriExposedException is the exception that is the cause for the issue:-
This exception is thrown when an application exposes a file:// Uri to another app.
This is only thrown for applications targeting Build.VERSION_CODES.N or higher. Applications targeting earlier SDK versions are allowed to share file:// Uri, but it's strongly discouraged.
These links might give a detailed answer to the above problem:-
https://developer.android.com/reference/android/os/FileUriExposedException
android.os.FileUriExposedException: file:///storage/emulated/0/test.txt exposed beyond app through Intent.getData()
Hope this helps.
I am creating a photo application where the user selects and image from the gallery and it displays in an imageview in the center of the app. How would I go about creating a share intent for the ImageView?
UPDATE
Share intent is working, however, the image can not be shared because I can not save it to the path I have selected. Below is my code. Any help?
public void taptoshare(View v)
{
View content = findViewById(R.id.myimage);
content.setDrawingCacheEnabled(true);
Bitmap bitmap = content.getDrawingCache();
File file = new File("/DCIM/Camera/image.jpg");
try
{
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(CompressFormat.JPEG, 100, ostream);
ostream.close();
}
catch (Exception e)
{
e.printStackTrace();
}
Intent shareIntent = new Intent(Intent.ACTION_SEND);
Uri phototUri = Uri.parse("/DCIM/Camera/image.jpg");
shareIntent.setData(phototUri);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, phototUri);
startActivity(Intent.createChooser(shareIntent, "Share Via"));
}
}
Try this
Intent shareIntent = new Intent(Intent.ACTION_SEND);
Uri phototUri = Uri.parse(path);
shareIntent.setData(photootUri);
shareIntent.setType("image/png");
shareIntent.putExtra(Intent.EXTRA_STREAM, photootUri);
getContext().startActivity(Intent.createChooser(shareIntent, "Use this for sharing"));
See the below link. it will very helpful for u. I think it satisfied your requirement.
http://www.technotalkative.com/android-pick-image-from-native-gallery/