Is Intent Available : Intent « Core Class « Android






Is Intent Available

    
//package org.elsewhat.reddit;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;

class AndroidUtil {

  
  /**
   * From http://android-developers.blogspot.com/2009/01/can-i-use-this-intent.html
   * Indicates whether the specified action can be used as an intent. This
   * method queries the package manager for installed packages that can
   * respond to an intent with the specified action. If no suitable package is
   * found, this method returns false.
   *
   * @param context The application's environment.
   * @param action The Intent action to check for availability.
   *
   * @return True if an Intent with the specified action can be sent and
   *         responded to, false otherwise.
   */
  public static boolean isIntentAvailable(Context context, String action) {
      final PackageManager packageManager = context.getPackageManager();
      final Intent intent = new Intent(action);
      List<ResolveInfo> list =
              packageManager.queryIntentActivities(intent,
                      PackageManager.MATCH_DEFAULT_ONLY);
      return list.size() > 0;
  }
  
  public static boolean isIntentAvailable(Context context, Intent intent) {
    final PackageManager packageManager = context.getPackageManager();
      List<ResolveInfo> list =
              packageManager.queryIntentActivities(intent,
                      PackageManager.MATCH_DEFAULT_ONLY);
      return list.size() > 0;
  }
}

   
    
    
    
  








Related examples in the same category

1.Using Intent to open other Activity
2.Create Intent to open a Uri
3.extends IntentService
4.Phone Intent
5.Map Intent
6.Market Intent
7.Load Activity with Intent
8.Using Intent to make another phone call
9.extends IntentService to create your own Intent
10.Adding data bundle to Intent
11.Using Intent to show other Activities
12.Start Intent with Utility class
13.Load library Activity with Intent
14.Capture Image with Intent
15.Intent.ACTION_MEDIA_MOUNTED
16.Using Intent to record audio
17.Video Player Intent
18.Video Capture Intent
19.Implementing an application service that will run in response to an alarm, allowing us to move long duration work out of an intent receiver.
20.Example of various Intent flags to modify the activity stack.
21.Sample code that invokes the speech recognition intent API.
22.extends IntentService to upload a file
23.factory class for generating various intents
24.Open Web Page Intent
25.start MMS Intent
26.Access the Internet
27.Pdf viewer
28.Rotation One Demo
29.Media activity