启动Twitter的应用程序应用程序、Twitter

2023-09-05 08:24:50 作者:学会微笑

可能重复:    Android的意图Twitter应用

我想去从我的Andr​​oid应用程序跟踪页,我想这是通过启动本地Twitter的应用程序来完成。

I want to go to follow page from my android app and i want this to be done by starting the native twitter app.

我怎样才能做到这一点,同时,如果Twitter客户端是不存在在用户的移动它应该在叽叽喳喳的手机网站。

How can i do this and also if a twitter client is not there in user's mobile it should go in mobile web site of twitter.

推荐答案

要检查是否有意向存在试试这个:

To check if an Intent exists try this:

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;
}

(源)

有关Twitter检查这个片段:

For twitter check this snippet:

Intent tweetIntent = new Intent(Intent.ACTION_SEND);
tweetIntent.putExtra(Intent.EXTRA_TEXT, "Test tweet");
tweetIntent.setType("application/twitter");

(source)