Note that there are some explanatory texts on larger screens.

plurals
  1. POPackageManager does not work on Android 2.3.4
    primarykey
    data
    text
    <p>I am launching the default Youtube App installed on device to play a video. First, I want to check if the app exists on the device using PackageManager.</p> <p>If the app does not exists, I want to redirect the user to the Google Play to download the app.</p> <p>Below is the code snippet:</p> <pre><code> String appName = "com.google.android.youtube"; Boolean existFlg = false; Context context = getApplicationContext(); PackageManager packageManager = context.getPackageManager(); // get all installed app's info List&lt;PackageInfo&gt; pinfo = packageManager.getInstalledPackages(PackageManager.GET_ACTIVITIES); for (int i = 0; i &lt; pinfo.size(); i++) { String name = pinfo.get(i).packageName; if (name.equalsIgnoreCase(appName)) { existFlg = true; break; } } if (existFlg) { // start Youtube Native App Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:"+video_id)); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(i); } // not installed else { // goto the market to download Youtube App Uri uri = Uri.parse("market://details?id=com.google.android.youtube"); Intent market = new Intent(Intent.ACTION_VIEW, uri); market.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { context.startActivity(market); } catch (android.content.ActivityNotFoundException ex) { // if market app not exist, goto the web of Google Play to download the Facebook App String googleURL = "https://play.google.com/store/apps/details?id=com.google.android.youtube"; Uri googleplay_webpage = Uri.parse(googleURL); Intent marketIntent = new Intent(Intent.ACTION_VIEW, googleplay_webpage); marketIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(marketIntent); } } </code></pre> <p>This code works perfectly well on <strong>Android 4.0.4</strong> and above. But when I am trying to run it on <strong>Android 2.3.4</strong> it ALWAYS redirects the user to the Google Play irrespective of whether the App is installed or not.</p> <p>Any idea as to how to make this compatible with Android 2.3.4 too ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload