Abrir página en la aplicación de Twitter desde otra aplicación-Android


Estaba buscando alguna manera de iniciar la aplicación de Twitter y abrir una página específica desde mi aplicación, sin webview. He encontrado la solución para Facebook aquí: Apertura de la aplicación de Facebook en la página de perfil especificada

Necesito algo similar.

EDITAR Acabo de encontrar una solución:

try {
    Intent intent = new Intent(Intent.ACTION_VIEW,
    Uri.parse("twitter://user?screen_name=[user_name]"));
    startActivity(intent);
} catch (Exception e) {
    startActivity(new Intent(Intent.ACTION_VIEW,
    Uri.parse("https://twitter.com/#!/[user_name]"))); 
}
Author: ROMANIA_engineer, 2012-06-19

5 answers

Esto funcionó para mí: twitter://user?user_id=id_num

Para conocer el ID: http://www.idfromuser.com /

 40
Author: fg.radigales,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-09-21 11:57:32

Basado en fg.respuesta radigales, esto es lo que usé para iniciar la aplicación si es posible, pero volver al navegador de lo contrario:

Intent intent = null;
try {
    // get the Twitter app if possible
    this.getPackageManager().getPackageInfo("com.twitter.android", 0);
    intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=USERID"));
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
} catch (Exception e) {
    // no Twitter app, revert to browser
    intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/PROFILENAME"));
}
this.startActivity(intent);

ACTUALIZACIÓN

Se agregó intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); para solucionar un problema por el que twitter se abría dentro de mi aplicación en lugar de como una actividad nueva.

 40
Author: Harry,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-09-30 10:53:02

Mi respuesta se basa en las respuestas ampliamente aceptadas de fg.radigales y Harry. Si el usuario tiene Twitter instalado pero deshabilitado (por ejemplo, mediante la cuarentena de aplicaciones), este método no funcionará. Se seleccionará la intent para la aplicación de Twitter, pero no podrá procesarla porque está desactivada.

En lugar de:

getPackageManager().getPackageInfo("com.twitter.android", 0);
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=2343965036"));

Puedes usar lo siguiente para decidir qué hacer:

PackageInfo info = getPackageManager().getPackageInfo("com.twitter.android", 0);
if(info.applicationInfo.enabled)
    intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=2343965036"));
else
    intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/wrkoutapp"));
 4
Author: igordcard,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-02-18 16:43:14

Abra la página en la aplicación de Twitter desde otra aplicación que usa Android en 2 Pasos:

1.Simplemente pegue el siguiente código (en el botón haga clic o en cualquier lugar que necesite)

Intent intent = null;
try{
   // Get Twitter app
   this.getPackageManager().getPackageInfo("com.twitter.android", 0);
   intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=USER_ID"));
   intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
} catch () {
   // If no Twitter app found, open on browser
   intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/USERNAME"));
}

2.intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=USER_ID"));

Para obtener USER_ID simplemente escriba username http://gettwitterid.com / y obtener el ID de usuario de Twitter allí

Referencia: https://solutionspirit.com/open-page-twitter-application-android/

Espero que ayude:)

 3
Author: SHUJAT MUNAWAR,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-06-21 12:36:46

Simplemente pruebe este fragmento de código. Te ayudará.

//Checking If the app is installed, according to the package name
        Intent intent = new Intent();
        intent.setType("text/plain");
        intent.setAction(Intent.ACTION_SEND);
        final PackageManager packageManager = getPackageManager();
        List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);

        for (ResolveInfo resolveInfo : list) 
        {
            String packageName = resolveInfo.activityInfo.packageName;

            //In case that the app is installed, lunch it.
            if (packageName != null && packageName.equals("com.twitter.android")) 
            {
                try
                {
                    String formattedTwitterAddress = "twitter://user/" ;
                    Intent browseTwitter = new Intent(Intent.ACTION_VIEW, Uri.parse(formattedTwitterAddress));
                                    long twitterId = <Here is the place for the twitter id>
                    browseTwitter.putExtra("user_id", twitterId);
                    startActivity(browseTwitter);

                    return;
                }
                catch (Exception e) 
                {

                }
            }
        }

        //If it gets here it means that the twitter app is not installed. Therefor, lunch the browser.
        try
        { 
                            String twitterName = <Put the twitter name here>
            String formattedTwitterAddress = "http://twitter.com/" + twitterName;
            Intent browseTwitter = new Intent(Intent.ACTION_VIEW, Uri.parse(formattedTwitterAddress)); 
            startActivity(browseTwitter);
        }
        catch (Exception e) 
        {

        }
 1
Author: Akilan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-06-19 16:40:21