Bas*_*rif 0 android shareactionprovider
有什么方法可以检测到在使用共享操作提供程序时选择了哪个共享应用程序,以便我可以为不同的应用程序发送不同的消息?我正在使用以下方法进行共享操作提供程序,
mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.menu_item_share).getActionProvider();
mShareActionProvider.setShareIntent(getDefaultShareIntent());
Run Code Online (Sandbox Code Playgroud)
和意图,
public Intent getDefaultShareIntent(){
String message = Fname + Mobileno + Homeno + Workmail + Homemail
+ Gtalk + Skype + Address + Company + Title + Website;
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, message);
return shareIntent;
}
Run Code Online (Sandbox Code Playgroud)
更新:
最简单的解决方案是:
@Override
public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) {
String shareTarget = intent.getComponent().getPackageName();
...
}
Run Code Online (Sandbox Code Playgroud)
无需复制文件或任何东西.
如果您碰巧使用后者,请从Android源或ActionBarSherlock复制一些文件:
确保您引用这些文件,而不是您应用中的原始文件.
在ActivityChooserModel.java中,修改:
if (mActivityChoserModelPolicy != null) {
ResolveInfo info = getActivity(index);
choiceIntent.putExtra("user_selected_activity", (info.activityInfo != null) ? info.activityInfo.packageName : info.serviceInfo.packageName);
final boolean handled = mActivityChoserModelPolicy.onChooseActivity(this, choiceIntent);
if (handled)
return null;
}
Run Code Online (Sandbox Code Playgroud)
它会将所选活动的包名称存储到intent中.然后,您可以在处理程序中阅读它:
@Override
public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) {
String shareTarget = intent.getStringExtra("user_selected_activity");
...
}
Run Code Online (Sandbox Code Playgroud)
并根据所选活动决定处理方式.
| 归档时间: |
|
| 查看次数: |
1688 次 |
| 最近记录: |