<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: daisy1754</title>
    <description>The latest articles on DEV Community by daisy1754 (@daisy1754).</description>
    <link>https://dev.to/daisy1754</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F58716%2F19b4b638-fa9c-4fd6-ad3a-94c608b5a5a1.png</url>
      <title>DEV Community: daisy1754</title>
      <link>https://dev.to/daisy1754</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/daisy1754"/>
    <language>en</language>
    <item>
      <title>Removing self from Android implicit intent</title>
      <dc:creator>daisy1754</dc:creator>
      <pubDate>Thu, 22 Feb 2018 04:54:07 +0000</pubDate>
      <link>https://dev.to/daisy1754/removing-self-from-android-implicit-intent--4880</link>
      <guid>https://dev.to/daisy1754/removing-self-from-android-implicit-intent--4880</guid>
      <description>&lt;p&gt;Android provides an &lt;a href="https://developer.android.com/guide/components/intents-common.html"&gt;implicit intent&lt;/a&gt; to open apps based on user's intent (eg., I want to take a picture). It is simple yet very useful feature for users.&lt;/p&gt;

&lt;p&gt;It may however be tricky when app can handle multiple implicit intent. For instance, if you develop a photo sharing app, your app can be a both receiver and sender of 'export an image' intent at the same time. When your users try to export an image from your app, it'd be awkward if your app is also in the receiver list.&lt;/p&gt;

&lt;p&gt;To avoid situation like this, you can &lt;code&gt;queryIntentActivities&lt;/code&gt; and explicitly filter intent as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static Intent createChooser(Context context, Intent target, CharSequence title) {
  List&amp;lt;ResolveInfo&amp;gt; resolveInfoList = context.getPackageManager().queryIntentActivities(
      target, PackageManager.MATCH_DEFAULT_ONLY);
  if (resolveInfoList.isEmpty()) {
    return Intent.createChooser(target, title);
  }

  Collections.sort(
      resolveInfoList, 
      new ResolveInfo.DisplayNameComparator(context.getPackageManager()));
  List&amp;lt;Intent&amp;gt; targetIntents = new ArrayList&amp;lt;Intent&amp;gt;();
  for (ResolveInfo resolveInfo : resolveInfoList) {
    if (context.getApplicationContext().getPackageName().equals(
        resolveInfo.activityInfo.packageName)) {
      continue;
    }
    Intent intent = new Intent(target);
    intent.setPackage(resolveInfo.activityInfo.packageName);
    intent.setClassName(
        resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
    targetIntents.add(intent);
  }

  Intent chooserIntent = Intent.createChooser(targetIntents.remove(0), title);
  chooserIntent.putExtra(
      Intent.EXTRA_INITIAL_INTENTS, 
      targetIntents.toArray(new Parcelable[]{}));
  return chooserIntent;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>android</category>
    </item>
  </channel>
</rss>
