6

I downloaded apk file from url(my server) and save it in sdcard. If user install it from sdcard, I want to know, whether is any notification that app is installed successfully or is app istalled in device. Is there any callback on installed app

kumar_android
  • 2,273
  • 1
  • 21
  • 30

4 Answers4

15

try this code :

protected boolean isAppInstalled(String packageName) {
        Intent mIntent = getPackageManager().getLaunchIntentForPackage(packageName);
        if (mIntent != null) {
            return true;
        }
        else {
            return false;
        }
    }

to get the package name of the app easily : just search your app in the google play website , and then you will take the id parameter ( it is the package name of the app) . Example : you will search on Youtube app on google play , and you will find it in this url :

https://play.google.com/store/apps/details?id=com.google.android.youtube&feature=search_result#?t=W251bGwsMSwxLDEsImNvbS5nb29nbGUuYW5kcm9pZC55b3V0dWJlIl0.

the package name is the id param, so it is : com.google.android.youtube

And then when you want to test , you will just have :

String packageName = "com.google.android.youtube";
boolean isYoutubeInstalled = isAppInstalled(packageName);

PLUS : if you want to get the list of all installed apps in you device , you can find your answer in this tutorial

Houcine
  • 24,001
  • 13
  • 56
  • 83
  • I dont know the package name, i will get url from server and download it and save it in sdcard, how do i get package name to check – kumar_android Nov 27 '12 at 03:52
  • Thanks, I requesting my server url to get apk, for that scenario, how can i get get package name, if there is any way to get package name from apk file? – kumar_android Nov 28 '12 at 04:53
  • you can't get it from the apk file, you will get it from the packageManager after you install it . – Houcine Nov 28 '12 at 09:26
  • No doubt your post is really helpful , but i am getting a exception "java.lang.RuntimeException: Adding window failed" and " E/AndroidRuntime(7554): Caused by: android.os.TransactionTooLargeException 05-14 11:37:25.305: E/AndroidRuntime(7554): at android.os.BinderProxy.transact(Native Method) 05-14 11:37:25.305: E/AndroidRuntime(7554): at android.view.IWindowSession$Stub$Proxy.add(IWindowSession.java:516) 05-14 11:37:25.305: E/AndroidRuntime(7554): at android.view.ViewRootImpl.setView(ViewRootImpl.java:494) " – DJhon May 14 '14 at 06:59
  • to solve this issue i got a link http://stackoverflow.com/questions/11451393/what-to-do-on-transactiontoolargeexception – DJhon May 14 '14 at 07:01
  • but still i have one query.... Suppose i am checking my .apk is installed or nor ? at time of installation... I am getting same exception while checking my package com.test.installedornot.My .apk size is more than 9MB then in that case how i will manage this exception? – DJhon May 14 '14 at 07:01
1
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = context.getPackageManager().queryIntentActivities( mainIntent, 0);

You'll get the list of all installed applications on Android.

SVS
  • 200
  • 9
1

Use this to check if an application is installed

PackageManager pm = context.getPackageManager();

        List<ApplicationInfo> list = pm.getInstalledApplications(0);

        for (int i = 0; i < list.size(); i++) {         
            if(list.get(i).packageName.equals("com.my package")){
                    //do what you want
                    }

        }
jaumard
  • 8,202
  • 3
  • 40
  • 63
1

In Youtube Player API, you can access YoutubeIntents class and use isYoutubeInstalled to verify if device has the Android app or not.

Wahib Ul Haq
  • 4,185
  • 3
  • 44
  • 41