Android sharing and Android sharing
1/** 2 * share the information to a friend 3*4 * @ param file. If the path of the fake part is path, file = new File (path ); 5 */6 private void shareToFriend (File file) {7 Intent intent = new Intent (); 8 ComponentName componentName = new ComponentName ("com. tencent. mm "," com. tencent. mm. ui. tools. required imgui "); 9 intent. setComponent (componentName); 10 intent. setAction (Intent. ACTION_SEND); 11 intent. setType ("image/*"); 12 intent. putExtra (Intent. EXTRA_TEXT, "test"); 13 intent. putExtra (Intent. EXTRA_STREAM, Uri. fromFile (file); 14 startActivity (intent); 15}
1/** 2 * share the information to the circle of friends 3*4 * @ param file. If the path of the fake image is path, file = new File (path ); 5 */6 private void shareToTimeLine (File file) {7 Intent intent = new Intent (); 8 ComponentName componentName = new ComponentName ("com. tencent. mm "," com. tencent. mm. ui. tools. shareToTimeLineUI "); 9 intent. setComponent (componentName); 10 11 intent. setAction (Intent. ACTION_SEND); 12 intent. putExtra (Intent. EXTRA_STREAM, Uri. fromFile (file); 13 14 // intent. setAction (android. content. intent. ACTION_SEND_MULTIPLE); 15 // ArrayList <Uri> uris = new ArrayList <Uri> (); 16 // for (int I = 0; I <images. size (); I ++) {17 // Uri data = Uri. fromFile (new File (thumbPaths. get (I); 18 // uris. add (data); 19 //} 20 // intent. putParcelableArrayListExtra (Intent. EXTRA_STREAM, uris); 21 22 intent. setType ("image/*"); 23 24 startActivity (intent); 25}
(Note: the disadvantage of the above two examples is that the "back to third-party tool" is identified after the sharing. The third-party tool displayed here is actually the demo of sharesdk. You need to register your application in sharesdk, then change your key to display the application name)
1. Download the official sdk demo.
: Http://open.weixin.qq.com/download? Lang = zh_CN
2. decompress the package and import the project to eclipse.
When extracting the file, we found a debug. keystore file under the root directory. This file is critical.
Then let's run and see, you will find that sharing is not successful at all, is it the reason, of course not.
Third: There is a debug under the root directory of the project mentioned above. keystore file, because when we compile and sign the apk, we use the debug that we bring. keystore, each computer is a different signature file, and the APP_ID has been signed file debug. the keystore is bound, so why cannot we run it directly.
The solution is to copy the debug. keystore to the default debug. keystore location on our computer and overwrite it (backup is recommended ).
In the window system, the signature file is in the c: \ User \ your USERNAME \. android directory (note that the. android folder is hidden by default ).
Run the command again and the sharing succeeds.
If it is our application, 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. We don't need to provide the sdk api to directly call related activities, which is more convenient, for example, "sharing information to friends ".
(