Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8742335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:28:57+00:00 2026-06-13T11:28:57+00:00

I have the following code to tweet something from my app: try { Intent

  • 0

I have the following code to tweet something from my app:

try {
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT,
                    "Blah blah blah");
            final PackageManager pm = getPackageManager();
            final List<?> activityList = pm
                    .queryIntentActivities(intent, 0);
            int len = activityList.size();
            for (int i = 0; i < len; i++) {
                final ResolveInfo app = (ResolveInfo) activityList.get(i);
                if ("com.twitter.android.PostActivity"
                        .equals(app.activityInfo.name)) {
                    intent.addCategory(Intent.CATEGORY_LAUNCHER);
                    intent.setClassName("com.twitter.android",
                            "com.twitter.android.PostActivity");

                    startActivity(intent);
                    break;
                }
            }
        } catch (final ActivityNotFoundException e) {
            onCreateDialog(NO_APP);
        }

protected Dialog onCreateDialog(int id) {
    Dialog dialog;
    switch (id) {

    case NO_APP: {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setIcon(R.drawable.icon_small);
        builder.setTitle("Twitter");
        builder.setMessage("No Twitter app found");
        builder.setCancelable(false);
        builder.setPositiveButton("OK", new Dialog.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
                finish();
            }
        });

        dialog = builder.create();
        return dialog;
    }
    default:
        return super.onCreateDialog(id);
    }
}

If twitter is installed on my phone, then the app works fine and a new tweet is generated. If the app does not exist, I want a dialog to appear stating that there is no app. However, as of now nothing happens when there is no twitter app in the phone. When I press the tweet button on my app, nothing happens. What do I need to do to make the dialog appear in this case?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:28:58+00:00Added an answer on June 13, 2026 at 11:28 am

    There is no exception if the twitter Application is not found.
    Change you code to:

    try {
    boolean found = false;
                Intent intent = new Intent(Intent.ACTION_SEND);
                intent.setType("text/plain");
                intent.putExtra(Intent.EXTRA_TEXT,
                        "Blah blah blah");
                final PackageManager pm = getPackageManager();
                final List<?> activityList = pm
                        .queryIntentActivities(intent, 0);
                int len = activityList.size();
                for (int i = 0; i < len; i++) {
                    final ResolveInfo app = (ResolveInfo) activityList.get(i);
                    if ("com.twitter.android.PostActivity"
                            .equals(app.activityInfo.name)) {
    found = true;
                        intent.addCategory(Intent.CATEGORY_LAUNCHER);
                        intent.setClassName("com.twitter.android",
                                "com.twitter.android.PostActivity");
    
                        startActivity(intent);
                        break;
                    }
                }
    if(!found)  onCreateDialog(NO_APP);
            } catch (final ActivityNotFoundException e) {
                onCreateDialog(NO_APP);
            }
    

    Or Try to start the twitter application and handle the not found exception.

    try {
    
                Intent intent = new Intent();
                intent.addCategory(Intent.CATEGORY_LAUNCHER);
                intent.setClassName("com.twitter.android", "com.twitter.android.PostActivity");
                startActivity(intent);
    
            } catch (final ActivityNotFoundException e) {
                onCreateDialog(NO_APP);
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following code for loading image from url in xml parsing endElement method
I have following code working nicely on all browsers but IE 7... <script type=text/javascript>
The following code extracts #hashtags from a tweet and puts them in the variable
Currently I have the following code: XmlDocument xDoc = new XmlDocument(); xDoc.Load(http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=twitter); XmlNodeList tweets
I have the following code (AS3 & CS 5.5): var regEx:RegExp = new RegExp(/(?:^|\s)(\#[^\s$]+)/g);
I have the following code: <script type=text/javascript> var ops = { slideshow: { slices:
All, I have the following code to retrieve some Tweets: if( ! $tweet )
I'm using the following code to send a tweet through the Twitter.app: NSPerformService(@Tweet, [NSPasteboard
I have following code in initialization im = imread('Image02.tif'); figure(); imagesc(im); colormap(gray); [hImage hfig
I have following code <div id=main> <div id=one> </div> <div id=two> </div> <div id=three>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.