2014-01-23 32 views
0

我试图从应用程序的我想要调用共享方法,而不仅仅是调用允许共享的所有应用程序的列表。我使用这个代码来调用Twitter共享:如何直接调用Facebook和VK的共享方法

String tweetUrl = 
      String.format("https://twitter.com/intent/tweet?text=%s&url=%s", 
      "Tweet text", "https://www.google.fi/"); 
     Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(tweetUrl)); 

     // Narrow down to official Twitter app, if available: 
     List<ResolveInfo> matches = getPackageManager().queryIntentActivities(intent, 0); 
     for (ResolveInfo info : matches) { 
      if (info.activityInfo.packageName.toLowerCase().startsWith("com.facebook")) { 
       intent.setPackage(info.activityInfo.packageName); 
      } 
     } 

     startActivity(intent); 

这对于Facebook:

String fullUrl = "https://m.facebook.com/sharer.php?u=.."; 
    try { 
     Intent sharingIntent = new Intent(Intent.ACTION_SEND); 
     sharingIntent.setClassName("com.facebook.katana", 
       "com.facebook.katana.ShareLinkActivity"); 
     sharingIntent.putExtra(Intent.EXTRA_TEXT, "your title text"); 
     startActivity(sharingIntent); 

    } catch (Exception e) { 
     Intent i = new Intent(Intent.ACTION_VIEW); 
     i.setData(Uri.parse(fullUrl)); 
     startActivity(i); 

    } 

但它调用只是打开浏览器,不是Facebook所安装在手机

和唐应用'不知道如何去做Vk

回答

0

对于Facebook我知道只有与这个Facebook供稿对话框共享

https://developers.facebook.com/docs/android/share

与此代码为浏览器

Session.openActiveSession(this, true, new Session.StatusCallback() 
    { 

     @Override 
     public void call(Session session, SessionState state, Exception exception) { 
      if (session.isOpened()) { 

       share(session); 
      } 
     } 
    }); 

} 

private void share(Session mySession) { 

    String message = "bla"; 

Bundle bundle = new Bundle(); 
bundle.putString("caption", "caption"); 
bundle.putString("description", message); 
bundle.putString("link", "link"); 
bundle.putString("name", "title"); 
bundle.putString("picture", ""); 
new WebDialog.FeedDialogBuilder(this, mySession, bundle).build().show(); 
} 

希望这将有助于你