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 Device phone call ability

if (((TelephonyManager)getContext().getSystemService(Context.TELEPHONY_SERVICE)).getPhoneType() == TelephonyManager.PHONE_TYPE_NONE) { // no phone } EDIT I’m surprised it comes back PHONE_TYPE_CDMA. Here’s another possibility: if (((TelephonyManager)getContext().getSystemService(Context.TELEPHONY_SERVICE)).getLine1Number() == null) { // no phone } This will require the READ_PHONE_STATE permission.

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 get results from an IntentService back into an Activity?

You should look at creating your own ResultReceiver subclass in your activity. ResultReceiver implements Parcelable so can be passed from your Activity to your Service as an extra on the Intent. You’ll need to do something like this: Implement a subclass of ResultReceiver within your activity class. The key method to implement is onReceiveResult(). This … Read more

Using a broadcast intent/broadcast receiver to send messages from a service to an activity

EDITED Corrected code examples for registering/unregistering the BroadcastReceiver and also removed manifest declaration. Define ReceiveMessages as an inner class within the Activity which needs to listen for messages from the Service. Then, declare class variables such as… ReceiveMessages myReceiver = null; Boolean myReceiverIsRegistered = false; In onCreate() use myReceiver = new ReceiveMessages(); Then in onResume()… … Read more

Android, How to read QR code in my application?

try { Intent intent = new Intent(“com.google.zxing.client.android.SCAN”); intent.putExtra(“SCAN_MODE”, “QR_CODE_MODE”); // “PRODUCT_MODE for bar codes startActivityForResult(intent, 0); } catch (Exception e) { Uri marketUri = Uri.parse(“market://details?id=com.google.zxing.client.android”); Intent marketIntent = new Intent(Intent.ACTION_VIEW,marketUri); startActivity(marketIntent); } and in onActivityResult(): @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 0) { if (resultCode … Read more

Reasons that the passed Intent would be NULL in onStartCommand

I’m surprised there’s no discussion of the incoming flags. I’m going to monitor this in the logs with the following: if (null == intent || null == intent.getAction ()) { String source = null == intent ? “intent” : “action”; Log.e (TAG, source + ” was null, flags=” + flags + ” bits=” + Integer.toBinaryString … Read more