Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is the solution posted.</p> <p>I use PackageManager and queryIntentActivities() to indicate whether the specified action can be used as an intent. The method queries the package manager for installed packages on the phone that can respond to an intent with the specified action. If no packages is found , the method returns false.</p> <pre><code>public static boolean isIntentAvailable(Context context, String action) { final PackageManager packageManager = context.getPackageManager(); final Intent intent = new Intent(action); List&lt;ResolveInfo&gt; list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return list.size() &gt; 0; } </code></pre> <p>Here is the complete code. I connect to Twitter with a Twitter client. So I'm using</p> <pre><code>public void ConnectTwitter(){ String msg = getResources().getString(R.string.partager_twitter).toString(); Intent intentTwitter = new Intent(Intent.ACTION_SEND); intentTwitter.putExtra(Intent.EXTRA_TEXT,msg); intentTwitter.setType("application/twitter"); if (isIntentAvailable(this,"application/twitter")){ startActivity(Intent.createChooser(intentTwitter,getResources().getString(R.string.partager_sel_tweet))); } else{ /* Handle Exception if no suitable apps installed */ Log.d("twitter", "Catch exception"); new AlertDialog.Builder(PartagerActivity.this) .setTitle(getResources().getString(R.string.partager_sel_tweet)) .setMessage(getResources().getString(R.string.partager_app_download)) .setNegativeButton("Non", null) .setPositiveButton("Oui", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { intentMarket("market://search?q=twitter"); } }) .show(); } } </code></pre> <p>with intentMarket method.Just enter the url ="market://search?q=twitter" BTW the market is not installed in the emulator.</p> <pre><code>public void intentMarket (String url){ Intent i = new Intent(Intent.ACTION_VIEW); Uri u = Uri.parse(url); i.setData(u); try{ startActivity(i); } catch(ActivityNotFoundException e){ Toast.makeText(this, "Pas d'applications twitter trouvé.", Toast.LENGTH_SHORT).show(); } } </code></pre> <p>More about PackageManager <a href="http://android-developers.blogspot.com/2009/01/can-i-use-this-intent.html" rel="nofollow">http://android-developers.blogspot.com/2009/01/can-i-use-this-intent.html</a></p> <p>Thumbs up if you find this useful !</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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