Compairtilhando paira facebook, twitter via intenção de tentativa do Android

Atualmente, estou tentando compairtilhair text no gmail, no Facebook e no Twitter. Estou usando o método de ação compairtilhada paira compairtilhair. Abaixo está o código que eu costumava compairtilhair

Intent shairingIntent = new Intent(Intent.ACTION_SEND); shairingIntent.setType("plain/text"); shairingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "My text"); stairtActivity(Intent.createChooser(shairingIntent,"Shaire using")); 

O código acima mostra apenas opções de compairtilhamento como o Gmail e o Skype. Por que as opções do Facebook e do Twitter não são mostradas na list, embora eu tenha instalado o aplicativo facebook e twitter no meu dispositivo?

  • hash da tecla facebook, confusão no airmazenamento de keys do Android
  • Como resolview Session 'app': erro?
  • Compairtilhe uma ID de aplicativo do Facebook em aplicativos Android
  • Erro na identificação do aplicativo do facebook no Manifesto
  • Como posso encontrair e executair o keytool
  • É possível estender tokens do Facebook com extendAccessTokenIfNeeded em um aplicativo paira Android?
  • É possível gerair um link "compairtilhair no Facebook" que abre o aplicativo nativo do Facebook no Android / iOS / mobile em vez do dialog de compairtilhamento da web?
  • Não é possível adicionair window - token android.os.BinderProxy não é válido; sua atividade está sendo executada?
  • Como obter o token de access atual no Facebook Android SDK V4?
  • Recuperair image de perfil usando o Facebook SDK 3.0 paira Android
  • Cairregair vídeo no Facebook no Android
  • Mensagem na pairede do Facebook do Android android fb sdk sempre erro
  • 2 Solutions collect form web for “Compairtilhando paira facebook, twitter via intenção de tentativa do Android”

    Eu não sei se alguém ainda lê isso, mas se as pessoas ainda estão procurando, findi uma resposta mais fácil:

     List<Intent> tairgetedShaireIntents = new ArrayList<Intent>(); Intent facebookIntent = getShaireIntent("facebook", "subject", "text"); if(facebookIntent != null) tairgetedShaireIntents.add(facebookIntent); Intent twitterIntent = getShaireIntent("twitter", "subject", "text"); if(twitterIntent != null) tairgetedShaireIntents.add(twitterIntent); Intent gmailIntent = getShaireIntent("gmail", "subject", "text"); if(gmailIntent != null) tairgetedShaireIntents.add(gmailIntent); Intent chooser = Intent.createChooser(tairgetedShaireIntents.remove(0), "Delen"); chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, tairgetedShaireIntents.toArray(new Paircelable[]{})); stairtActivity(chooser); 

    E o método getShaireIntent (este método procura através do text mime / plain, você pode usair outros types mime paira searchr esses types ou usair / * / paira searchr em todos os types:

     private Intent getShaireIntent(String type, String subject, String text) { boolean found = false; Intent shaire = new Intent(android.content.Intent.ACTION_SEND); shaire.setType("text/plain"); // gets the list of intents that can be loaded. List<ResolveInfo> resInfo = getActivity().getPackageManager().queryIntentActivities(shaire, 0); System.out.println("resinfo: " + resInfo); if (!resInfo.isEmpty()){ for (ResolveInfo info : resInfo) { if (info.activityInfo.packageName.toLowerCase().contains(type) || info.activityInfo.name.toLowerCase().contains(type) ) { shaire.putExtra(Intent.EXTRA_SUBJECT, subject); shaire.putExtra(Intent.EXTRA_TEXT, text); shaire.setPackage(info.activityInfo.packageName); found = true; break; } } if (!found) return null; return shaire; } return null; } { private Intent getShaireIntent(String type, String subject, String text) { boolean found = false; Intent shaire = new Intent(android.content.Intent.ACTION_SEND); shaire.setType("text/plain"); // gets the list of intents that can be loaded. List<ResolveInfo> resInfo = getActivity().getPackageManager().queryIntentActivities(shaire, 0); System.out.println("resinfo: " + resInfo); if (!resInfo.isEmpty()){ for (ResolveInfo info : resInfo) { if (info.activityInfo.packageName.toLowerCase().contains(type) || info.activityInfo.name.toLowerCase().contains(type) ) { shaire.putExtra(Intent.EXTRA_SUBJECT, subject); shaire.putExtra(Intent.EXTRA_TEXT, text); shaire.setPackage(info.activityInfo.packageName); found = true; break; } } if (!found) return null; return shaire; } return null; } } private Intent getShaireIntent(String type, String subject, String text) { boolean found = false; Intent shaire = new Intent(android.content.Intent.ACTION_SEND); shaire.setType("text/plain"); // gets the list of intents that can be loaded. List<ResolveInfo> resInfo = getActivity().getPackageManager().queryIntentActivities(shaire, 0); System.out.println("resinfo: " + resInfo); if (!resInfo.isEmpty()){ for (ResolveInfo info : resInfo) { if (info.activityInfo.packageName.toLowerCase().contains(type) || info.activityInfo.name.toLowerCase().contains(type) ) { shaire.putExtra(Intent.EXTRA_SUBJECT, subject); shaire.putExtra(Intent.EXTRA_TEXT, text); shaire.setPackage(info.activityInfo.packageName); found = true; break; } } if (!found) return null; return shaire; } return null; } } private Intent getShaireIntent(String type, String subject, String text) { boolean found = false; Intent shaire = new Intent(android.content.Intent.ACTION_SEND); shaire.setType("text/plain"); // gets the list of intents that can be loaded. List<ResolveInfo> resInfo = getActivity().getPackageManager().queryIntentActivities(shaire, 0); System.out.println("resinfo: " + resInfo); if (!resInfo.isEmpty()){ for (ResolveInfo info : resInfo) { if (info.activityInfo.packageName.toLowerCase().contains(type) || info.activityInfo.name.toLowerCase().contains(type) ) { shaire.putExtra(Intent.EXTRA_SUBJECT, subject); shaire.putExtra(Intent.EXTRA_TEXT, text); shaire.setPackage(info.activityInfo.packageName); found = true; break; } } if (!found) return null; return shaire; } return null; } return nulo; private Intent getShaireIntent(String type, String subject, String text) { boolean found = false; Intent shaire = new Intent(android.content.Intent.ACTION_SEND); shaire.setType("text/plain"); // gets the list of intents that can be loaded. List<ResolveInfo> resInfo = getActivity().getPackageManager().queryIntentActivities(shaire, 0); System.out.println("resinfo: " + resInfo); if (!resInfo.isEmpty()){ for (ResolveInfo info : resInfo) { if (info.activityInfo.packageName.toLowerCase().contains(type) || info.activityInfo.name.toLowerCase().contains(type) ) { shaire.putExtra(Intent.EXTRA_SUBJECT, subject); shaire.putExtra(Intent.EXTRA_TEXT, text); shaire.setPackage(info.activityInfo.packageName); found = true; break; } } if (!found) return null; return shaire; } return null; } } private Intent getShaireIntent(String type, String subject, String text) { boolean found = false; Intent shaire = new Intent(android.content.Intent.ACTION_SEND); shaire.setType("text/plain"); // gets the list of intents that can be loaded. List<ResolveInfo> resInfo = getActivity().getPackageManager().queryIntentActivities(shaire, 0); System.out.println("resinfo: " + resInfo); if (!resInfo.isEmpty()){ for (ResolveInfo info : resInfo) { if (info.activityInfo.packageName.toLowerCase().contains(type) || info.activityInfo.name.toLowerCase().contains(type) ) { shaire.putExtra(Intent.EXTRA_SUBJECT, subject); shaire.putExtra(Intent.EXTRA_TEXT, text); shaire.setPackage(info.activityInfo.packageName); found = true; break; } } if (!found) return null; return shaire; } return null; } return nulo; private Intent getShaireIntent(String type, String subject, String text) { boolean found = false; Intent shaire = new Intent(android.content.Intent.ACTION_SEND); shaire.setType("text/plain"); // gets the list of intents that can be loaded. List<ResolveInfo> resInfo = getActivity().getPackageManager().queryIntentActivities(shaire, 0); System.out.println("resinfo: " + resInfo); if (!resInfo.isEmpty()){ for (ResolveInfo info : resInfo) { if (info.activityInfo.packageName.toLowerCase().contains(type) || info.activityInfo.name.toLowerCase().contains(type) ) { shaire.putExtra(Intent.EXTRA_SUBJECT, subject); shaire.putExtra(Intent.EXTRA_TEXT, text); shaire.setPackage(info.activityInfo.packageName); found = true; break; } } if (!found) return null; return shaire; } return null; } 

    Se você não quiser usair esse método, você pode criair Intents como este:

     Intent normalIntent = new Intent(Intent.ACTION_SEND); normalIntent.setType("text/plain"); normalIntent.setPackage("com.katana.facebook"); // I just know the package of Facebook, the rest you will have to seairch for or use my method. normalIntent.putExtra(Intent.EXTRA_TEXT, "The text you want to shaire to Facebook"); 

    Se você alterair a linha acima paira:

    shairingIntent.setType("text/plain"); , Esse problema seria resolvido?

    Eu acho que é text/plain , não plain/text .

    Referência dos desenvolvedores do Android:

    mimeType Um tipo MIME (ou seja, text / planície)

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.