Check if an app is installed, and get it's version in Sketchware

We can check if an app is installed or not by using it's package name in simple codes in Sketchware.

Check if an app is installed or not

We can get information about any installed app from it's package name, by using PackageManager and PackageInfo methods. PackageInfo provides Overall information about the contents of a package. This corresponds to all the information collected from AndroidManifest.xml.

In onCreate event in LOGIC of your app, use an add source directly block and add following code:

boolean isAppInstalled = appInstalledOrNot("com.besome.sketch");
if(isAppInstalled) {
showMessage("Sketchware app is installed");
} else {showMessage("Sketchware is not installed");}


Create a More Block extra.

In the more block extra, use an add source directly block and put following codes:
}

private boolean appInstalledOrNot(String uri) { android.content.pm.PackageManager pm = getPackageManager(); try { pm.getPackageInfo(uri, android.content.pm.PackageManager.GET_ACTIVITIES); return true; } catch (android.content.pm.PackageManager.NameNotFoundException e) { } return false;

The code above will check if Sketchware App is installed or not. And show message if it is installed or not on activity create.

Note that underlined text com.besome.sketch is package name of Sketchware. To check for any other app, use it's package name in that place.

To perform ant other action instead of showing message, replace the code in italics with codes or blocks for action you want to perform.

For more understanding, watch the video below:

Find version of an installed app

To find version of an installed app and display it in a textview, add two TextView (textview1 and textview 2) in VIEW area of your project. In one of the TextViews (textview1) write the name of app for which you want to find the version.

In LOGIC area of project, in onCreate event, add following code:

String uri = "com.besome.sketch";
android.content.pm.PackageManager pm = getPackageManager(); try { android.content.pm.PackageInfo pInfo = pm.getPackageInfo(uri, android.content.pm.PackageManager.GET_ACTIVITIES); String version = pInfo.versionName;textview2.setText(version); } catch (android.content.pm.PackageManager.NameNotFoundException e) { }
In the code above replace com.besome.sketch with package name of the app whose version is to be obtained. Replace textview2 with the textview in which the version is to be displayed.

For more information watch this video.

Comments

  1. good article bro, and i have a question, how to check more than 1 app, (but not using list) ?

    i mean like using 2 if for same condition (isAppInstalled).

    because i want to put it to seperate textview.

    thanks 😁

    ReplyDelete
  2. Hi, how do I make sure that when something is uploaded to the list, it is at the top of the list, not the end of the list?

    ReplyDelete
  3. collection.reverse(list1);
    //list1 is your list map

    ReplyDelete

Post a Comment

Popular posts from this blog

Simple car racing android game in Sketchware

Creating a Drawing View in Sketchware

Enable Fullscreen for Youtube videos in WebView

How to enable upload from webview in Sketchware?

List of Calendar Format symbols valid in Sketchware