我想为日语应用程序制作一个分享按钮。在此共享按钮上,我想让用户能够打开任何应用程序即。 whatsapp,Line,Hetache,fb,tweeter以及用户设备中的任何共享应用程序。有可能吗?
答案 0 :(得分:2)
尝试使用隐式意图的发送操作,并允许选择从设备共享应用。
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));
同时检查更多选项:http://developer.android.com/training/sharing/send.html
答案 1 :(得分:1)
与
一起使用android.support.v7.app
库,
public class MainActivity extends ActionBarActivity {
ShareActionProvider actionProvider;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
getMenuInflater().inflate(R.menu.main, menu);
MenuItem menuItem = menu.findItem(R.id.action_share);
actionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(menuItem);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "ActionBarCompat is Awesome! Support Lib v7 #Xamarin");
actionProvider.setShareIntent (intent);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case R.id.action_edit:
Toast.makeText(getApplicationContext(), "Editing", Toast.LENGTH_LONG).show();
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
}