Android Intent Chooser to only show E-mail option

To solve this issue simply follow the official documentation. The most important consideration are: The flag is ACTION_SENDTO, and not ACTION_SEND. The setData of method of the intent, intent.setData(Uri.parse(“mailto:”)); // only email apps should handle this If you send an empty Extra, the if() at the end won’t work and the app won’t launch the … Read more

Open a selected file (image, pdf, …) programmatically from my Android Application?

Try the below code. I am using this code for opening a PDF file. You can use it for other files also. File file = new File(Environment.getExternalStorageDirectory(), “Report.pdf”); Uri path = Uri.fromFile(file); Intent pdfOpenintent = new Intent(Intent.ACTION_VIEW); pdfOpenintent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); pdfOpenintent.setDataAndType(path, “application/pdf”); try { startActivity(pdfOpenintent); } catch (ActivityNotFoundException e) { } If you want to open files, … Read more

Android share intent for facebook- share text AND link

I just built this code and it’s working for me: private void shareAppLinkViaFacebook(String urlToShare) { try { Intent intent1 = new Intent(); intent1.setClassName(“com.facebook.katana”, “com.facebook.katana.activity.composer.ImplicitShareIntentHandler”); intent1.setAction(“android.intent.action.SEND”); intent1.setType(“text/plain”); intent1.putExtra(“android.intent.extra.TEXT”, urlToShare); startActivity(intent1); } catch (Exception e) { // If we failed (not native FB app installed), try share through SEND String sharerUrl = “https://www.facebook.com/sharer/sharer.php?u=” + urlToShare; Intent intent … Read more

Android 11 (R) return empty list when querying intent for ACTION_IMAGE_CAPTURE

Android 11 changes how apps can query and interact with other apps. From the docs: The PackageManager methods that return results about other apps, such as queryIntentActivities(), are filtered based on the calling app’s <queries> declaration. So you need to declare <queries> in your AndroidManifest.xml: <manifest package=”com.example”> <queries> <intent> <action android:name=”android.media.action.IMAGE_CAPTURE” /> </intent> </queries> … … Read more

How to implement onBackPressed() & intents in fragment?

You can interact with the fragment using a callback interface. In your activity add the following: public class MyActivity extends Activity { protected OnBackPressedListener onBackPressedListener; public interface OnBackPressedListener { void doBack(); } public void setOnBackPressedListener(OnBackPressedListener onBackPressedListener) { this.onBackPressedListener = onBackPressedListener; } @Override public void onBackPressed() { if (onBackPressedListener != null) onBackPressedListener.doBack(); else super.onBackPressed(); } @Override … Read more