第一种方法:特点–简单
package com.example.share; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } /* 创建菜单 */ public boolean onCreateOptionsMenu(Menu menu) { menu.add(0, 0, 0, "分享"); return true; } public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case 0: // intent.setType("text/plain"); //纯文本 /* * 图片分享 it.setType("image/png"); //添加图片 File f = new * File(Environment.getExternalStorageDirectory()+"/name.png"); * * Uri uri = Uri.fromFile(f); intent.putExtra(Intent.EXTRA_STREAM, * uri); */ Intent intent=new Intent(Intent.ACTION_SEND); intent.setType("image/*"); intent.putExtra(Intent.EXTRA_SUBJECT, "Share"); intent.putExtra(Intent.EXTRA_TEXT, "I have successfully share my message through my app"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(Intent.createChooser(intent, getTitle())); return true; } return false; } }
第二种方法:特点–全面
在SHARESDK官网中下载 shareSDK for android 功能开发包
http://share.sharesdk.cn/Download
参考链接:http://www.mikel.cn/%E5%BC%80%E5%8F%91%E7%AC%94%E8%AE%B0/%E8%BD%AC%E8%BD%BDandroid-%E5%AE%9E%E7%8E%B0%E5%88%86%E4%BA%AB%E5%8A%9F%E8%83%BD%E4%B8%A4%E7%A7%8D%E6%96%B9%E6%B3%95-%E5%B0%8F%E9%A3%92-%E5%8D%9A%E5%AE%A2%E5%9B%AD.htmlintent=new
Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "分享");
intent.putExtra(Intent.EXTRA_TEXT, text);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(Intent.createChooser(intent, getTitle()));
上面是很多网站说的分享功能,但是我写了却不能够分享到腾讯微博还有开心网。怎么解决把内容分享到这个两个平台上去。
上面的代码是能够分享到人人网,新浪微博,短信上的
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "分享");
intent.putExtra(Intent.EXTRA_TEXT, text);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(Intent.createChooser(intent, getTitle()));
上面是很多网站说的分享功能,但是我写了却不能够分享到腾讯微博还有开心网。怎么解决把内容分享到这个两个平台上去。
上面的代码是能够分享到人人网,新浪微博,短信上的
- public void onClickShare(View view) {
- Intent intent=new Intent(Intent.ACTION_SEND);
- intent.setType("image/*");
- intent.putExtra(Intent.EXTRA_SUBJECT, "分享");
- intent.putExtra(Intent.EXTRA_TEXT, "终于可以了!!!");
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- startActivity(Intent.createChooser(intent, getTitle()));
- }
send的activity
的配置为
<activity android:name=".activity.MicroBlogInput" android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation" android:windowSoftInputMode="stateAlwaysVisible|adjustResize">
<intent-filter android:label="@string/albums_sendbyWBlog">
<action android:name="android.intent.action.SEND" />
<data android:mimeType="image/*" />
<activity android:name=".activity.MicroBlogInput" android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation" android:windowSoftInputMode="stateAlwaysVisible|adjustResize">
<intent-filter android:label="@string/albums_sendbyWBlog">
<action android:name="android.intent.action.SEND" />
<data android:mimeType="image/*" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
它并没有定义date mimetype=("text/plain");
所以intent.setType("text/plain");
这个条件就把它过滤掉了
所以你的代码要把intent.setType("text/plain");
这句改为
intent.setType("imge/*");
</intent-filter>
</activity>
它并没有定义date mimetype=("text/plain");
所以intent.setType("text/plain");
这个条件就把它过滤掉了
所以你的代码要把intent.setType("text/plain");
这句改为
intent.setType("imge/*");