2

I was trying to check whether facebook app is installed on a device or not.

while searching i found this link How to check if Facebook is installed Android

based on the above link my method is as below

PackageManager pm = getPackageManager();
    PackageInfo pinfo=null;
    try {
        pinfo=pm.getPackageInfo("com.facebook.katana",
                PackageManager.GET_ACTIVITIES);
        return ((pinfo!=null)?true:false);
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }

i checked the device facebook is not in installed app list,but the flag is always true and even package manager didn`t throw the NameNotFoundException.

when i try to launch fb activity like this nothing happens

File file = new File(imagePath);
final Intent fbIntent = new Intent(Intent.ACTION_SEND);
fbIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri fileUri = FileProvider.getUriForFile(this, "com.test.provider", file);
fbIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
fbIntent.putExtra(Intent.EXTRA_TEXT,"gudmorning");
fbIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
fbIntent.setType("image/*");
fbIntent.setPackage("com.facebook.katana");
startActivity(fbIntent);

I also checked the code for package name "com.facebook.orca" also which is package name for messenger app.

what could be the possible reason or any other method to perform this check.

Community
  • 1
  • 1
Ravikant Tiwari
  • 371
  • 3
  • 11

1 Answers1

3

Is is not at all possible that android system show wrong information about an app as installed in device. In your case I have checked the code and it is completely ok, so the only reason why you are not being able to see facebook app in your device while the above code shows that package "com.facebook.katana" is -

Your facebook app is in disabled state

Yes, it seems that you were having facebook app as system app (pre installed to device) and now it is disabled. To check, you may go into your settings and find something like "Manage Applications". Go to the very bottom of the list in All Applications and you should find all the disabled apps there.

Adarsh Sharma
  • 472
  • 2
  • 15
  • is there any way so that we can check programmatically whether app is in disabled state.Thanks for your answer – Ravikant Tiwari Mar 01 '17 at 07:08
  • @RavikantTiwari you can check the status of the app using flag. you can do like this ApplicationInfo ai = getActivity().getPackageManager().getApplicationInfo("your_package",0); boolean appStatus = ai.enabled; then this boolean value of appStatus could be used to check whether app is enabled/disabled. – Adarsh Sharma Mar 01 '17 at 07:12
  • In some cases it'll be on an enabled state, so even if I check the `enabled` flag it won't work. – Mauker Jan 21 '19 at 13:05