• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Filter specific apps in android

krishnaveni

Well-Known Member
Dec 16, 2011
158
0
chennai
I have to filter the android application using intent.action_send.
If in my device having twitter app means go to twitter application.otherwise have to display the toast message.


In my device twitter application is available.

But am getting the toast message and also its going to twitter application.


In these situation my app going to twitter application.but don't display the toast message.


please check my code and give me a solution.what's wrong in my code ???

Here i have using following code:


final CharSequence[] items = { "Twitter", "Facebook", "Gmail" };
AlertDialog.Builder builder = new AlertDialog.Builder( HomePage.this);
builder.setTitle("Share Via:");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
if (items[item] == "Twitter") {
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "www.dfdfdf.com");
PackageManager pm = getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo app : activityList) {
if ("com.twitter.android.PostActivity".equals(app.activityInfo.name)) {
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name); shareIntent.addCategory(Intent.CATEGORY_LAUNCHER); shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
shareIntent.setComponent(name);
startActivity(shareIntent);
break;
}
else {
Toast.makeText(getApplicationContext(), "Install the twitter application/Try again later", Toast.LENGTH_LONG).show();
}
}
}
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones