Deleting Inserted ContentValues - java

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.

Related

Camera API android 10

Error showing while capturing image ,I already give the read write storage permission of device
I am using camera intent for taking photo in android 10, But shows following error
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
ContentResolver resolver = getContext().getContentResolver();
ContentValues contentValues = new ContentValues();
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, "temp");
contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "image/png");
contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, "DCIM/" + "TEMP");
Uri imageUri123 = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues);
intent.putExtra(MediaStore.EXTRA_OUTPUT,
imageUri123);
startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
}else {
File photo = new File(Environment.getExternalStorageDirectory(), "temp.jpg");
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Build.VERSION.SDK_INT >= Build.VERSION_CODES.M?getOutputMediaFileUri(getActivity(), photo):Uri.fromFile(photo));
startActivityForResult(cameraIntent, REQUEST_IMAGE_CAPTURE);
}

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]

How Can I add A delete button in chooser Intent

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?

Android - App makes shortcut with App's name, not Intent.EXTRA_SHORTCUT_NAME

This was working fine earlier, but now it apparentally doesn't. Here's my code:
if (options[item].equals("Add to Home Screen")) {
Intent shortcutIntent = new Intent();
shortcutIntent.setClassName("net.dylang.android.system_sounds_pro", "net.dylang.android.system_sounds_pro.SystemSounds");
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
shortcutIntent.putExtra("profileName", SystemSounds.prop.getProperty(((String) button.getText()).replaceAll(" ", "-")));
shortcutIntent.putExtra("profileText", button.getText());
if (SystemSounds.prop.getProperty("vibrated-ringers").contains(((String) button.getText()).replaceAll(" ", "-")))
shortcutIntent.putExtra("vibratedringsi", "true");
else
shortcutIntent.putExtra("vibratedringsi", "false");
if (SystemSounds.prop.getProperty("vibrated-notifications").contains(((String) button.getText()).replaceAll(" ", "-")))
shortcutIntent.putExtra("vibratednotsi", "true");
else
shortcutIntent.putExtra("vibratednotsi", "false");
Intent addIntent = new Intent();
Toast.makeText(getApplicationContext(), shortcutIntent.getStringExtra("profileText"), 0).show();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutIntent.getStringExtra("profileText"));
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(ProfilesPage.this, R.drawable.icon));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
ProfilesPage.this.sendBroadcast(addIntent);
}
My Toast shows the correct shortcut name, but when I add it to the homescreen it's my app's name.
Thanks,
DylanG
try this
public void createShortCut(){
// a Intent to create a shortCut
Intent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
//repeat to create is forbidden
shortcutintent.putExtra("duplicate", false);
//set the name of shortCut
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "SmS ");
//set icon
Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
//set the application to lunch when you click the icon
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(getApplicationContext() , MainActivity.class));
//sendBroadcast,done
sendBroadcast(shortcutintent);
}

Where is a list of available intents in Android?

I'm starting to learn how to develop apps for Android, and I'm having some issues with intents--it just doesn't seem like they're documented at all. All I want to do is send the user to the video recorder, where they record a video, and the video information is returned to my app. I know this is possible, as I've seen it in other apps, but it seems like the intent is undocumented (or I'm just not completely understanding how intents work).
Any thoughts?
Apart from above solutions, here are a list of common intents
//show web page intent:
Uri uri = Uri.parse("http://www.google.com");
Intent it = new Intent(Intent.ACTION_VIEW,uri);
startActivity(it);
//show maps intent:
Uri uri = Uri.parse("geo:38.899533,-77.036476");
Intent it = new Intent(Intent.Action_VIEW,uri);
startActivity(it);
//show ways
Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");
Intent it = new Intent(Intent.ACTION_VIEW,URI);
startActivity(it);
//call dial program
Uri uri = Uri.parse("tel:xxxxxx");
Intent it = new Intent(Intent.ACTION_DIAL, uri);
startActivity(it);
Uri uri = Uri.parse("tel.xxxxxx");
Intent it =new Intent(Intent.ACTION_CALL,uri);
//don't forget add this config:<uses-permission id="android.permission.CALL_PHONE" />
//send sms/mms, call sender program
Intent it = new Intent(Intent.ACTION_VIEW);
it.putExtra("sms_body", "The SMS text");
it.setType("vnd.android-dir/mms-sms");
startActivity(it);
//send sms
Uri uri = Uri.parse("smsto:0800000123");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "The SMS text");
startActivity(it);
//send mms
Uri uri = Uri.parse("content://media/external/images/media/23");
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra("sms_body", "some text");
it.putExtra(Intent.EXTRA_STREAM, uri);
it.setType("image/png");
startActivity(it);
//send email
Uri uri = Uri.parse("mailto:xxx#abc.com");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
startActivity(it);
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_EMAIL, "me#abc.com");
it.putExtra(Intent.EXTRA_TEXT, "The email body text");
it.setType("text/plain");
startActivity(Intent.createChooser(it, "Choose Email Client"));
Intent it=new Intent(Intent.ACTION_SEND);
String[] tos={"me#abc.com"};
String[] ccs={"you#abc.com"};
it.putExtra(Intent.EXTRA_EMAIL, tos);
it.putExtra(Intent.EXTRA_CC, ccs);
it.putExtra(Intent.EXTRA_TEXT, "The email body text");
it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
it.setType("message/rfc822");
startActivity(Intent.createChooser(it, "Choose Email Client"));
//add extra
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mysong.mp3");
sendIntent.setType("audio/mp3");
startActivity(Intent.createChooser(it, "Choose Email Client"));
//play media
Intent it = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("file:///sdcard/song.mp3");
it.setDataAndType(uri, "audio/mp3");
startActivity(it);
Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
//Uninstall
Uri uri = Uri.fromParts("package", strPackageName, null);
Intent it = new Intent(Intent.ACTION_DELETE, uri);
startActivity(it);
//uninstall apk
Uri uninstallUri = Uri.fromParts("package", "xxx", null);
returnIt = new Intent(Intent.ACTION_DELETE, uninstallUri);
//install apk
Uri installUri = Uri.fromParts("package", "xxx", null);
returnIt = new Intent(Intent.ACTION_PACKAGE_ADDED, installUri);
//play audio
Uri playUri = Uri.parse("file:///sdcard/download/everything.mp3");
returnIt = new Intent(Intent.ACTION_VIEW, playUri);
//send extra
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/eoe.mp3");
sendIntent.setType("audio/mp3");
startActivity(Intent.createChooser(it, "Choose Email Client"));
//search
Uri uri = Uri.parse("market://search?q=pname:pkg_name");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
//where pkg_name is the full package path for an application
//show program detail page
Uri uri = Uri.parse("market://details?id=app_id");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
//where app_id is the application ID, find the ID
//by clicking on your application on Market home
//page, and notice the ID from the address bar
//search google
Intent intent = new Intent();
intent.setAction(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY,"searchString")
startActivity(intent);
In general, the Android developer docs are a good place to look for this kind of thing: there's a list of common intent actions in the Intent class reference. For recording video, check out the ACTION_VIDEO_CAPTURE intent action defined by the Media provider.
You might want to check out OpenIntents
This is relatively new from Google (they seem to have updated their old page which just showed Intents for standard Google apps).
Common Intents
It tells you exact Intent specification for performing a wide range of actions with apps for the following:
Alarm Clock
Camera
Calendar
Contacts / People
Email
File Storage
Maps
Music / Video
Phone Dialler
Settings
Text Messaging
Web browsing
It's important now that Google have provided a definitive list of the Intents that should be used for performing a given action, that we use them exactly as provided there. The reasoning behind Intents is all about a standard method of communication between apps (i.e. different developers), so it is important for the sake of your app's compatibility to talk in exactly the same language as the one everyone else will be using.

Categories

Resources