android---(分享操作)
来源:互联网 发布:野蛮人升级数据 编辑:程序博客网 时间:2024/06/05 19:30
//当单击按钮时,触发:public class share extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_share); }//当单击按钮时,触发,自动调用系统分享程序列表 public void sharedSimple(View view) { Intent sendIntent = new Intent(); //作用 sendIntent.setAction(Intent.ACTION_SEND); //类型 sendIntent.setType("text/plain"); //分享的内容 sendIntent.putExtra(Intent.EXTRA_TEXT,"你是谁啊"); //启动系统的分享程序 startActivity(sendIntent); }}
public class share extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_share); } public void sharedSimple(View view) { Intent sendIntent = new Intent(); //作用 sendIntent.setAction(Intent.ACTION_SEND); //类型 sendIntent.setType("text/plain"); //分享的内容 sendIntent.putExtra(Intent.EXTRA_TEXT, "你是谁啊"); //指定选择器:参数:intent ,分享列标题 startActivity(Intent.createChooser(sendIntent, "您好啊")); }}
//分享图片: public void sharedImage(View view){ //图片路径 Uri uriImage = Uri.parse("./sdcard/4.jpg"); Intent sendIntent = new Intent(); //作用 sendIntent.setAction(Intent.ACTION_SEND); //类型 sendIntent.setType("image/*"); //分享的内容 sendIntent.putExtra(Intent.EXTRA_STREAM, uriImage); startActivity(Intent.createChooser(sendIntent,"分享图片到")); }
//分享多个内容 public void multImage(View view){ //图片路径 Uri uriImage1 = Uri.parse("./sdcard/1.jpg"); Uri uriImage2 = Uri.parse("./sdcard/4.jpg"); ArrayList<Uri> list = new ArrayList<Uri>(); list.add(uriImage1); list.add(uriImage2); Intent sendIntent = new Intent(); //作用 sendIntent.setAction(Intent.ACTION_SEND_MULTIPLE); //类型 sendIntent.setType("image/*"); //分享的内容 sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,list); startActivity(Intent.createChooser(sendIntent, "分享图片到")); }
//自已的app接收数据:会自动在分享列表程序中显示自已的app,public class ReceiverShared extends AppCompatActivity { TextView textView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_receiver_shared); textView = (TextView) findViewById(R.id.content); handlerContent(); } private void handlerContent() { Intent intent = getIntent(); String type = intent.getType(); String action = intent.getAction(); if(Intent.ACTION_SEND.equals(action)){ if("text/plain".equals(type)){ //获取内容: String info = intent.getStringExtra(Intent.EXTRA_TEXT); textView.setText(info); } } }}清单配置: //接收数据的activity: <activity android:name=".ReceiverShared" android:label="@string/title_activity_receiver_shared" > <intent-filter> <action android:name="android.intent.action.SEND"></action> <category android:name="android.intent.category.DEFAULT"></category> <data android:mimeType="text/plain"/> </intent-filter> </activity>
在标题栏上显示像qq 一样的分享图标功能://菜单项: <item android:id="@+id/shares" android:orderInCategory="200" android:title="分享" app:actionProviderClass="android.support.v7.widget.ShareActionProvider" app:showAsAction="ifRoom"/>//activity类:public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); MenuItem item = menu.findItem(R.id.shares);//一定是V7下的包 ShareActionProvider sp = (ShareActionProvider) MenuItemCompat.getActionProvider(item); Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.setType("text/plain");//分享的内容 intent.putExtra(Intent.EXTRA_TEXT, "你好啊1"); sp.setShareIntent(intent); return super.onCreateOptionsMenu(menu); }
0 0
- Android分享操作
- android---(分享操作)
- Android分享操作
- Android的分享操作 一
- Android设置来电铃声和分享操作
- android使用intent实现分享操作
- android training 学习笔记002-Android分享操作
- android的sqlite导出及数据操作经验分享
- android 分享到QQ空间的所有操作
- Android代码方式操作应用程序安装、卸载、分享、启动
- 【Android】分享
- android分享
- android 分享
- android 分享
- android 分享
- Android分享
- Android分享
- Android 分享
- Android Adapter详解
- PHP实现归并排序(合并排序)--算法原理分析
- Android Studio 真正国内SDK在线更新说明
- 如何访问到静态的文件,如jpg,js,css?
- 用C++实现二叉树
- android---(分享操作)
- leetcode系列(36)Container With Most Water
- 8大排序算法图文讲解
- 离散化泛做
- 被忽视的预处理命令
- iOS 键盘通知 与 键盘上方工具条设置
- 【DWR】学习笔记(一):基本配置&&前后台的数据传输与处理
- LeetCode 6: ZigZag Conversion
- POJ 2262 Goldbach's Conjecture(素数表分解质数)