2014-10-29 63 views
1

有沒有辦法限制Android應用程序中的共享選項?我嘗試過使用ShareActionProvider或者只是簡單地使用意向選項啓動意圖。基本上我希望能夠通過電子郵件限制分享或類似的東西。限制共享選項

回答

1

你可以使用這樣的事情,但不是Facebook上尋找一個不同的名稱

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); 
shareIntent.setType("text/plain"); 
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,"this is a string"); 
shareIntent.setType("image/png"); 
shareIntent.putExtra(android.content.Intent.EXTRA_STREAM,uri); //Share the image on Facebook 
PackageManager pm = getApplicationContext().getPackageManager(); 
List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0); 
        for (final ResolveInfo app : activityList) { 
         if ((app.activityInfo.name).contains("facebook")) { 
          final ActivityInfo activity = app.activityInfo; 
          final ComponentName name = new ComponentName(
             activity.applicationInfo.packageName, 
             activity.name); 
          shareIntent.addCategory(Intent.CATEGORY_LAUNCHER); 
          shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 
           | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 
          shareIntent.setComponent(name); 
          startActivity(shareIntent); 
          break; 
           } 
          } 
+0

非常感謝:) – AmaJayJB 2014-10-29 09:27:38

+0

你的歡迎:) – JRowan 2014-10-29 09:28:35

1

您可以自定義意圖選擇器根據自己的需要這樣的 -

List<Intent> targetedShareIntents = new ArrayList<Intent>(); 
     Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); 
     shareIntent.setType("text/plain"); 
     List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(shareIntent, 0); 
     if (!resInfo.isEmpty()){ 
      for (ResolveInfo resolveInfo : resInfo) { 
       String packageName = resolveInfo.activityInfo.packageName; 
       Intent targetedShareIntent = new Intent(android.content.Intent.ACTION_SEND); 
       targetedShareIntent.setType("text/plain"); 
       targetedShareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "subject to be shared"); 
       if (StringUtils.equals(packageName, "com.facebook.katana")){ 
        targetedShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "http://link-to-be-shared.com"); 
       }else{ 
        targetedShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "text message to shared"); 
       } 

       targetedShareIntent.setPackage(packageName); 
       targetedShareIntents.add(targetedShareIntent); 


      } 
      Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Select app to share"); 

      chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{})); 

      startActivity(chooserIntent); 
     } 

希望這有助於你。

+0

非常感謝:) – AmaJayJB 2014-10-29 09:27:00