Android 微信分享Api使用详解

来源:互联网 发布:mac抹掉磁盘格式选哪个 编辑:程序博客网 时间:2024/06/04 23:32
最近研究微信分享功能,查阅了N多资料,官网demo可以运行但是自己写的却运行不了,经过多方查证以及本人亲测,需要提交审核且通过才能成功调用微信API。

现将查阅资料罗列一下,方便遇到同样问题的同学查看。

研究资料:
1:android 微信sdk api example调用不成功解决方案      URL:http://www.jb51.net/article/32076.htm

2:Android 第三方应用接入微信平台研究情况分享(一)      URL:http://www.jb51.net/article/33048.htm

3:Android 第三方应用接入微信平台研究情况分享(二)      URL:http://www.jb51.net/article/33050.htm

4: Android微信SDK API调用教程          URL: http://blog.csdn.net/jiahui524/article/details/8211451


5:微信的分享及其注意事项     

                                       URL:http://www.eoeandroid.com/forum.php?mod=viewthread&tid=283111 



另外:在手机装有微信的情况下,可以不使用微信分享API也能通过应用间的通信使用intent传递数据实现分享图片和文字的功能,如下

界面Activity代码如下:

import java.io.File;import android.app.Activity;import android.content.ComponentName;import android.content.Intent;import android.content.res.AssetManager;import android.net.Uri;import android.os.Bundle;import android.os.Environment;import android.view.Menu;import android.view.MenuItem;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}@Overridepublic boolean onOptionsItemSelected(MenuItem item) {File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);File file = new File(dir, "1.jpg");switch (item.getItemId()) {case R.id.action_share1:shareToFriend(file);return true;case R.id.action_share2:shareToTimeLine(file);return true;default:return super.onOptionsItemSelected(item);}}private void shareToFriend(File file) {Intent intent = new Intent();ComponentName comp = new ComponentName("com.tencent.mm","com.tencent.mm.ui.tools.ShareImgUI");intent.setComponent(comp);intent.setAction("android.intent.action.SEND");intent.setType("image/*");//intent.setFlags(0x3000001);intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));startActivity(intent);}private void shareToTimeLine(File file) {Intent intent = new Intent();ComponentName comp = new ComponentName("com.tencent.mm","com.tencent.mm.ui.tools.ShareToTimeLineUI");intent.setComponent(comp);intent.setAction("android.intent.action.SEND");intent.setType("image/*");//intent.setFlags(0x3000001);intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));startActivity(intent);}}


res资源menu文件夹下的menu.xml代码如下:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >   <item        android:id="@+id/action_share1"        android:orderInCategory="100"        android:showAsAction="never"        android:title="@string/action_share1"/>    <item        android:id="@+id/action_share2"        android:orderInCategory="100"        android:showAsAction="never"        android:title="@string/action_share2"/></menu>
附上:界面截图


注意这里分享的是SDcard中Pictures目录中的1.png图片,使用中请自行修改一下:
          File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
          File file = new File(dir, "1.png");

0 0
原创粉丝点击