Detailed explanation of Android programming method to implement WeChat sharing information

高洛峰
Release: 2017-03-28 14:46:38
Original
2426 people have browsed it

The example of this article tells the story of AndroidProgramming to realize WeChat sharing information The method is shared with everyone for your reference, as follows:

As WeChat becomes more and more popular, more and more applications require the function of sharing to WeChat. Although many platforms have integrated sharing. Functions, such as Umeng. However, I personally feel that Umeng integrates too many things and encapsulates them too much. Many resource files have to be brought in, so it doesn’t feel very good, so I also studied WeChat’s SDK. Share.

First: Download the official sdk demo

Download address: open.weixin.qq.com/download/?lang=zh_CN

Second: Unzip and import the project into eclipse

When decompressed, I found a debug.keystore file in the root directory. This file is very The key is.
Then let’s run it and see. You will find that the sharing is not successful at all. Is it because of WeChat? Of course not.

Third: There is one in the root directory of the project mentioned above. debug.keystore file, because when we compile and sign the apk, we use the debug.keystore that comes with us. Each computer has a different signature file, and the WeChat APP_ID has been bound to the signature file debug.keystore , so why is it unsuccessful when we run it directly?

The solution is to copy the debug.keystore of WeChat to the default debug.keystore location of our computer and overwrite it (it is recommended to back it up first).

In the window system, this signature file is in the c:\user\your username\.android directory (note that the .android folder is hidden by default)

Run it again and share it. It's successful.

If it's our application, just replace the APP_ID with the APP_ID we applied for on the official website.

In fact, there is a simpler way for us to share information on WeChat. , without using the provided SDK API, it is easier to directly call WeChat related activities, for example:

/** 
* 分享信息到朋友 
* 
* @param file,假如图片的路径为path,那么file = new File(path); 
*/
private void shareToFriend(File file) { 
    Intent intent = new Intent(); 
    ComponentName componentName = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareImgUI"); 
    intent.setComponent(componentName); 
    intent.setAction(Intent.ACTION_SEND); 
    intent.setType("image/*"); 
    intent.putExtra(Intent.EXTRA_TEXT, "测试微信"); 
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); 
    startActivity(intent); 
}
Copy after login
/** 
* 分享信息到朋友圈 
* 
* @param file,假如图片的路径为path,那么file = new File(path); 
*/
private void shareToTimeLine(File file) { 
    Intent intent = new Intent(); 
    ComponentName componentName = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareToTimeLineUI"); 
    intent.setComponent(componentName); 
    intent.setAction(Intent.ACTION_SEND); 
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); 
//   intent.setAction(android.content.Intent.ACTION_SEND_MULTIPLE); 
//   ArrayList<Uri> uris = new ArrayList<Uri>(); 
//   for (int i = 0; i < images.size(); i++) { 
//     Uri data = Uri.fromFile(new File(thumbPaths.get(i))); 
//     uris.add(data); 
//   } 
//   intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); 
    intent.setType("image/*"); 
    startActivity(intent); 
}
Copy after login

I hope this article will be helpful to everyone in Android programming

.

The above is the detailed content of Detailed explanation of Android programming method to implement WeChat sharing information. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template