Share images to android Projects
MOOC Learning Project
Share images to android Projects
AlertDialog dialog box settings
Edit and use .9.png
Sdk-> tools-> draw9patch. bat
API call
Package com. dongni. wxshare; import com. tencent. mm. sdk. modelmsg. sendMessageToWX; import com. tencent. mm. sdk. modelmsg. WXImageObject; import com. tencent. mm. sdk. modelmsg. WXMediaMessage; import com. tencent. mm. sdk. modelmsg. WXWebpageObject; import com. tencent. mm. sdk. openapi. IWXAPI; import com. tencent. mm. sdk. openapi. wxapifacloud; import android. support. v7.app. actionBarActivity; import android. app. alertDialog; import Android. content. dialogInterface; import android. content. intent; import android. graphics. bitmap; import android. graphics. typeface; import android. OS. bundle; import android. provider. mediaStore; import android. view. menu; import android. view. menuItem; import android. view. view; import android. view. window; import android. view. windowManager; import android. widget. *; public class MainActivity extends ActionBarActivi Ty {private ImageView mPhoto; private EditText mWord; private Button shareBtn; private int flag =-1; private IWXAPI iwxapi; private Bitmap getPic () {shareBtn. setVisibility (View. INVISIBLE); View view = getWindow (). getDecorView (); view. setDrawingCacheEnabled (true); view. buildDrawingCache (); return view. getDrawingCache ();} private void wxshare (int flag) {// TODO Auto-generated method stub WXWebpage Object webpage = new WXWebpageObject (); WXMediaMessage msg = new WXMediaMessage (); msg. mediaObject = new WXImageObject (getPic (); SendMessageToWX. req req = new SendMessageToWX. req (); req. transaction = String. valueOf (System. currentTimeMillis (); req. message = msg; req. scene = flag = 0? SendMessageToWX. req. WXSceneSession: SendMessageToWX. req. WXSceneTimeline; // req. scene = SendMessageToWX. req. WXSceneSession; iwxapi. sendReq (req) ;}@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); this. requestWindowFeature (Window. FEATURE_NO_TITLE); // remove the title bar // this. getWindow (). setFlags (WindowManager. layoutParams. FLAG_FULLSCREEN, WindowManager. layoutParams. FLAG_FULLSCREEN); // remove the Information bar setContentView (R. layout. activity_main); iwxapi = wxapifacloud. createWXAPI (this, "wx3507afc2c2b49ccf"); // appId iwxapi. registerApp ("wx3507afc2c2b49ccf"); mPhoto = (ImageView) findViewById (R. id. pic); mWord = (EditText) findViewById (R. id. word); shareBtn = (Button) findViewById (R. id. fxbtn); mPhoto. setOnClickListener (new View. onClickListener () {@ Override public void onClick (View arg0 ){ // TODO Auto-generated method stub Intent intent = new Intent (Intent. ACTION_PICK, null); intent. setDataAndType (MediaStore. images. media. EXTERNAL_CONTENT_URI, "image/*"); startActivityForResult (intent, 100) ;}}); shareBtn. setOnClickListener (new View. onClickListener () {@ Override public void onClick (View arg0) {// TODO Auto-generated method stub final String [] item = new String [] {"share with friends ", "Share to friends"}; new AlertDialog. Builder (MainActivity. this). setTitle ("share to") //. setMessage ("share to where? "). SetItems (item, new DialogInterface. onClickListener () {@ Override public void onClick (DialogInterface arg0, int witch) {// TODO Auto-generated method stub flag = witch ;}}). setNegativeButton ("cancel", new DialogInterface. onClickListener () {@ Override public void onClick (DialogInterface arg0, int arg1) {// TODO Auto-generated method stub flag =-1 ;}}). show (); if (flag> = 0) {wxshare (flag); shareBtn. s EtVisibility (View. VISIBLE) ;}}); mWord. setTypeface (Typeface. createFromAsset (getAssets (), "fonts/hksn. ttf ") ;}@ Override protected void onActivityResult (int requestCode, int resultCode, Intent data) {super. onActivityResult (requestCode, resultCode, data); if (resultCode = RESULT_ OK & requestCode = 100) {if (data! = Null) {mPhoto. setImageURI (data. getData () ;}}@ Override public 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 ;}@ Override public boolean onOptionsItemSelected (MenuItem item) {// Handle action bar item clicks here. the action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest. xml. int id = item. getItemId (); if (id = R. id. action_settings) {return true;} return super. onOptionsItemSelected (item );}}