分享功能
2016-03-15 18:24
225 查看
className:
com.example.android.supportv4/.app.SharingSupport
实现:
public class SharingSupport extends Activity {
@Override
protected void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.sharing_support);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
ShareCompat.IntentBuilder b = ShareCompat.IntentBuilder.from(this);
b.setType("text/plain").setText("Share from menu");
MenuItem item = menu.add("Share");
ShareCompat.configureMenuItem(item, b);
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
return true;
}
public void onShareTextClick(View v) {
ShareCompat.IntentBuilder.from(this)
.setType("text/plain")
.setText("I'm sharing!")
.startChooser();
}
public void onShareFileClick(View v) {
try {
// This file will be accessed by the target of the share through
// the ContentProvider SharingSupportProvider.
FileWriter fw = new FileWriter(getFilesDir() + "/foo.txt");
fw.write("This is a file share");
fw.close();
ShareCompat.IntentBuilder.from(this)
.setType("text/plain")
.setStream(Uri.parse(SharingSupportProvider.CONTENT_URI + "/foo.txt"))
.startChooser();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public void onShareMultipleFileClick(View v) {
try {
// These files will be accessed by the target of the share through
// the ContentProvider SharingSupportProvider.
FileWriter fw = new FileWriter(getFilesDir() + "/foo.txt");
fw.write("This is a file share");
fw.close();
fw = new FileWriter(getFilesDir() + "/bar.txt");
fw.write("This is another file share");
fw.close();
ShareCompat.IntentBuilder.from(this)
.setType("text/plain")
.addStream(Uri.parse(SharingSupportProvider.CONTENT_URI + "/foo.txt"))
.addStream(Uri.parse(SharingSupportProvider.CONTENT_URI + "/bar.txt"))
.startChooser();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
界面:
com.example.android.supportv4/.app.SharingSupport
实现:
public class SharingSupport extends Activity {
@Override
protected void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.sharing_support);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
ShareCompat.IntentBuilder b = ShareCompat.IntentBuilder.from(this);
b.setType("text/plain").setText("Share from menu");
MenuItem item = menu.add("Share");
ShareCompat.configureMenuItem(item, b);
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
return true;
}
public void onShareTextClick(View v) {
ShareCompat.IntentBuilder.from(this)
.setType("text/plain")
.setText("I'm sharing!")
.startChooser();
}
public void onShareFileClick(View v) {
try {
// This file will be accessed by the target of the share through
// the ContentProvider SharingSupportProvider.
FileWriter fw = new FileWriter(getFilesDir() + "/foo.txt");
fw.write("This is a file share");
fw.close();
ShareCompat.IntentBuilder.from(this)
.setType("text/plain")
.setStream(Uri.parse(SharingSupportProvider.CONTENT_URI + "/foo.txt"))
.startChooser();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public void onShareMultipleFileClick(View v) {
try {
// These files will be accessed by the target of the share through
// the ContentProvider SharingSupportProvider.
FileWriter fw = new FileWriter(getFilesDir() + "/foo.txt");
fw.write("This is a file share");
fw.close();
fw = new FileWriter(getFilesDir() + "/bar.txt");
fw.write("This is another file share");
fw.close();
ShareCompat.IntentBuilder.from(this)
.setType("text/plain")
.addStream(Uri.parse(SharingSupportProvider.CONTENT_URI + "/foo.txt"))
.addStream(Uri.parse(SharingSupportProvider.CONTENT_URI + "/bar.txt"))
.startChooser();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
界面:
相关文章推荐
- 【CF 应用开发大赛】IT Share(IT分享网)
- 站长有福了-让网址一键添加百度首页导航
- RHEL 6.3 LAMP环境配置 ncurses 出错及解决
- exchange online share mailbox senditem
- 分享到朋友圈和发送给好友
- Solaris11添加swap方法
- 在CentOS上安装7zip和使用
- mount
- vbox share file between guest with host
- nginx新手配置$document_root
- MySQL 编码设置
- 关于Metasploit-学习笔记-基础命令以及参数
- 教你轻松实现用SCOM监控Linux主机
- 在window下与linux虚拟机建立共享文件夹
- Android studio 集成 shareSDK
- 新的开始,想着梦想前进
- linux 共享文件夹
- 解决引用单个Library因android-support-v4.jar版本不同而导致的冲突
- MTK-android编译错误
- 共享型智能指针的实现share_pointer