How Can I add A delete button in chooser Intent - java

I have an activity that include an Imageview, when clicked this Image view, this chooser start to set image in Image view. It works well but I want to add delete button to this chooser intent
for example, if Imageview in the activity has an image, I want to delete that image from this chooser by delete button
and also this is my codes for this chooser(this codes is part of my activity) :
final List<Intent> cameraIntents = new ArrayList<Intent>();
final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
final PackageManager packageManager = getPackageManager();
final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
for (ResolveInfo res : listCam) {
final String packageName = res.activityInfo.packageName;
final Intent intent = new Intent(captureIntent);
intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
intent.setPackage(packageName);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
cameraIntents.add(intent);
}
// Filesystem.
final Intent galleryIntent = new Intent();
galleryIntent.setType("image/*");
galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
// Chooser of filesystem options.
final Intent chooserIntent = Intent.createChooser(galleryIntent, getString(R.string.select_source));
// Add the camera options.
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[cameraIntents.size()]));
chooserIntent.putExtra(Intent.EXTRA_DATA_REMOVED,del);
startActivityForResult(chooserIntent, 12312);
would you please help me to add a delete button for deleting image from imageview in this chooser?

Related

How to share image through inten

Bundle intent = getIntent().getExtras();`
cardView=(CardView)findViewById(R.id.card);
final String query = intent.getString("Query1");
db = new DataBaseHelper(Image.this);
Cursor c = db.getData(query);
if (c.getCount() != 0) {
c.moveToFirst();
do {
image = c.getString(5);
title=c.getString(3);
} while (c.moveToNext());
}
txt.setText(title);
img.setImageDrawable(getResources().getDrawable(getResources().getIdentifier(image, "drawable", getPackageName())));
To create an Share Intent for image, you can use following code.
uriToImage is Uri of your image file.
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
shareIntent.setType("image/jpeg");
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));
EDIT - To get URI of drawable image
Uri uri = Uri.parse("android.resource://your.package.here/drawable/image_name");
Use Content Provider(FileProvider) To Share Data as it is Good Practice.
Intent intent = new Intent(Intent.ACTION_SEND);
final String path = "Your File Path";
Uri uri = FileProvider.getUriForFile(YourActivity.this, "com.abc.xy.appname.fileprovider", new File(path));
intent.setDataAndType(uri, "image/*");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(intent);
For Multiple File Sharing
ArrayList<Uri> files = new ArrayList<Uri>();
for (int i = 0; i < mfileList.size(); i++) {
File file = new File(mfileList.get(i).get_path());
Uri uri = FileProvider.getUriForFile(YourActivity.this, "com.abc.xy.appname.fileprovider", file);
files.add(uri);
}
Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.setType("image/jpeg");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(Intent.EXTRA_STREAM, files);
startActivity(intent);
To Share an Image Stored in Your Drawable.Put this Uri in your Share Intent Extras.
Uri uri = Uri.parse("android.resource://your.package/drawable/image_name");
Check this Link out For Content Provider Setup.
[https://developer.android.com/reference/android/support/v4/content/FileProvider][1]

Capturing, saving and displaying pictures in activity

I have 3 buttons and a toggle in my activity. When toggled, the buttons should open the camera to capture an image or prompt to select one from gallery and 'save' it. When not-toggled, the buttons should display the image it was used to take in a main ImageView.
Three buttons:
//buttons 1,2,3 are the same
Button button1 = (Button) findViewById(R.id.some_button);
button1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if(toggled == true){
takePictureIntent();
}
else {
//display the picture
}
}
});
My camera/gallery code is from a tutorial/forum online:
private void takePictureIntent() {
final List<Intent> cameraIntents = new ArrayList<Intent>();
final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
final PackageManager packageManager = getPackageManager();
final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
for (ResolveInfo res : listCam) {
final String packageName = res.activityInfo.packageName;
final Intent intent = new Intent(captureIntent);
intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
intent.setPackage(packageName);
cameraIntents.add(intent);
}
// Filesystem.
final Intent galleryIntent = new Intent();
galleryIntent.setType("image/*");
galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
// Chooser of filesystem options.
final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source");
// Add the camera options.
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[cameraIntents.size()]));
startActivityForResult(chooserIntent, 1);
//}
}
Can somebody please guide me towards how to have the button "remember" the picture taken through it so that, when the toggle is off, it will display it?
I've been trying to figure this out for hours, any help is appreciated.

User select image from gallery or from custom Camera and not Camera app for image

I would like the user to be able to click on a button and have the option of selecting the gallery or similar apps or a camera activity I have in my app not the build-in one . I read the related answers here and here . However, I don't want to include the build-in camera app, but I want to include my Camera Activity.
I have the following set up so far, taken from the two links I posted:
Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
Intent gallIntent = new Intent(Intent.ACTION_GET_CONTENT);
gallIntent.setType("image/*");
Intent camIntent = new Intent(UserEventsActivity.this,CameraActivity.class);
camIntent.setComponent(new ComponentName("MCamera", "Camera"));
List<Intent> yourIntentsList = new ArrayList<Intent>();
yourIntentsList.add(camIntent);
List<ResolveInfo> listGall = getApplicationContext().getPackageManager().queryIntentActivities(gallIntent, 0);
for (ResolveInfo res : listGall) {
final Intent finalIntent = new Intent(gallIntent);
finalIntent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
yourIntentsList.add(finalIntent);
}
pickIntent.putExtra(Intent.EXTRA_INTENT, yourIntentsList.toArray(new Parcelable[]{}));
pickIntent.putExtra(Intent.EXTRA_TITLE, "Select Source");
startActivityForResult(pickIntent, 1);
What results from this, is a large list of unrelated apps and services, most of which are actually repeated several times in the list. In addition, my camera activity is not among them. When I just do pickIntent.putExtra(Intent.EXTRA_INTENT,gallIntent) I do get the related gallery apps I want, but I can't add my activity.
Any ideas as to what I am doing wrong?
In addition, no service opens when I click on it. However, this may be related to the '1' arg in startActivityOnResult as I'm not exactly sure what to put for that arg.
I came up with a possible solution, that seemed to work for me. I used a custom Dialog:
final Dialog choosePicContent = new Dialog(UserEventsActivity.this);
ScrollView scrollContent = new ScrollView(UserEventsActivity.this);
choosePicContent.addContentView(scrollContent, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
LinearLayout scrollLayout = new LinearLayout(UserEventsActivity.this);
scrollContent.addView(scrollLayout);
scrollLayout.setOrientation(LinearLayout.VERTICAL);
TextView title = new TextView(UserEventsActivity.this);
title.setText(R.string.selectsource);
scrollLayout.addView(title);
Intent gallIntent = new Intent(Intent.ACTION_GET_CONTENT);
gallIntent.setType("image/*");
final Intent camIntent = new Intent(UserEventsActivity.this,CameraActivity.class);
ImageButton camButton = new ImageButton(UserEventsActivity.this);
camButton.setImageDrawable(getApplicationContext().getDrawable(R.drawable.ic_menu_camera));
camButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
camIntent.putExtra("User",current_user);
startActivity(camIntent);
}
});
scrollLayout.addView(camButton);
List<ResolveInfo> listGall = getApplicationContext().getPackageManager().queryIntentActivities(gallIntent, 0);
for (ResolveInfo res : listGall) {
final Intent finalIntent = new Intent(gallIntent);
finalIntent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
ImageButton iconButton = new ImageButton(UserEventsActivity.this);
iconButton.setImageDrawable(res.activityInfo.loadIcon(getPackageManager()));
iconButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivityForResult(finalIntent,1);
}
});
scrollLayout.addView(iconButton);
}
choosePicContent.show();

Cannot share via bluetooth....file not sent error

Here is my code:
List<Intent> targetedShareIntents = new ArrayList<Intent>();
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
PackageManager pm =getApplicationContext().getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(sharingIntent, 0);
for(final ResolveInfo app : activityList) {
String packageName = app.activityInfo.packageName;
Intent targetedShareIntent = new Intent(android.content.Intent.ACTION_SEND);
targetedShareIntent.setType("text/plain");
targetedShareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "share");
if(TextUtils.equals(packageName, "com.facebook.katana")){
targetedShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "http:your link");
} else {
targetedShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, Fragmentactivity.songpaths.get(indexfordelete));
targetedShareIntent.putExtra(Intent.EXTRA_SUBJECT, " Thirukural Version 1.7.2 !");
}
targetedShareIntent.setPackage(packageName);
targetedShareIntents.add(targetedShareIntent);
}
Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Share Application your app name ");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{}));
startActivity(chooserIntent);
I am trying to share it via bluetooth firstly but it is not working. I am getting the error ~File not sent. Fragmentactivity.songpaths.get(indexfordelete) is the path to file i want to share.
try this code here i sharing a text ,u can share what do you want:
List<Intent> targetedShareIntents = new ArrayList<Intent>();
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
PackageManager pm =v.getContext().getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(sharingIntent, 0);
for(final ResolveInfo app : activityList) {
String packageName = app.activityInfo.packageName;
Intent targetedShareIntent = new Intent(android.content.Intent.ACTION_SEND);
targetedShareIntent.setType("text/plain");
targetedShareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "share");
if(TextUtils.equals(packageName, "com.facebook.katana")){
targetedShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "http:your link");
} else {
targetedShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, strLink);
targetedShareIntent.putExtra(Intent.EXTRA_SUBJECT, " app version");
}
targetedShareIntent.setPackage(packageName);
targetedShareIntents.add(targetedShareIntent);
}
Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Share Application your app name ");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{}));
startActivity(chooserIntent);

Deleting Inserted ContentValues

I have created custom intents for the user to choose photos or take a picture.
Here's my Code:
Intent pickIntent = new Intent(Intent.ACTION_PICK,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
pickIntent.setType("image/*");
values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "new image");
values.put(MediaStore.Images.Media.DESCRIPTION, "saved today");
Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraPhotoUri = getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, cameraPhotoUri);
String pickTitle = "Select or take a new Picture"; // Or get from strings.xml
Intent chooserIntent = Intent.createChooser(pickIntent, pickTitle);
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
new Intent[]{takePhotoIntent});
startActivityForResult(chooserIntent, REQUEST_CODE_ADD_PHOTO);
now the getContentResolver().insert(...) part creates an empty file on the image directory.How do I delete all of them (empty files) after using the intents. Please help.

Categories

Resources