实例介绍
【实例简介】
【实例截图】
【实例截图】
【核心代码】
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 | package skyseraph.easytagwrite; import skyseraph.android.util.CustomDialog; import skyseraph.android.util.LogUtil; import skyseraph.android.util.MyConstant; import skyseraph.android.util.nfc.BobNdefMessage; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.app.PendingIntent; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.graphics.Color; import android.nfc.NdefMessage; import android.nfc.NfcAdapter; import android.nfc.Tag; import android.nfc.tech.Ndef; import android.nfc.tech.NdefFormatable; import android.os.AsyncTask; import android.os.Bundle; import android.provider.Settings; import android.util.DisplayMetrics; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.WindowManager; import android.widget.AdapterView; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; import java.io.IOException; public class MainActivity extends Activity { private static final String TAG_ASSIST = "[MainActivity]-" ; // NFC Declarations private NfcAdapter mNfcAdapter = null ; private IntentFilter[] mFilters = null ; private PendingIntent mPendingIntent = null ; private String[][] mTechLists = null ; private Context mContext; private NdefMessage NDEFMsg2Write = null ; // UI private EditText mEditText1 = null ; private EditText mEditText2 = null ; private TextView mTextView1 = null ; private TextView mTextView2 = null ; private Spinner mSpinner = null ; private ArrayAdapter mAdapter = null ; private Button writeUrlButton, saveUrlButton, exitButton; private static final String[] spinnerStr = { "TNF_ABSOLUTE_URI" , "TNF_MIME_MEDIA" , "TNF_WELL_KNOWN RTD-TEXT" , "TNF_WELL_KNOWN RTD-URI" , "TNF_EXTERNAL_TYPE" , }; private String payloadStr = "" ; private String typeStr = "" ; private int tagTypeFlag = 0 ; // private AlertDialog alertDialog = null ; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_main); mContext = this ; checkNFCFunction(); // NFC Check initUI(); // Init UI initNFC(); // Init NFC } @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) { // TODO Auto-generated method stub super .onOptionsItemSelected(item); switch (item.getItemId()) // item clicked { case R.id.action_settings: // Intent setnfc = new Intent(Settings.ACTION_WIRELESS_SETTINGS); Intent setnfc = new Intent(Settings.ACTION_NFC_SETTINGS); startActivity(setnfc); break ; case R.id.action_about: dialog(); break ; } return true ; } protected void dialog() { AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setTitle(getString(R.string.dialog_notice)); alertDialog = builder.create(); builder.setCancelable( true ); // back alertDialog.setCanceledOnTouchOutside( true ); alertDialog.show(); } @Override public void onResume() { super .onResume(); // get NFC object Tag detectTag = getIntent().getParcelableExtra(NfcAdapter.EXTRA_TAG); // validate that this tag can be written if (supportedTechs(detectTag.getTechList())) { switch (tagTypeFlag) { case 0 : // ABSOLUTE_URI NDEFMsg2Write = BobNdefMessage.getNdefMsg_from_ABSOLUTE_URI(payloadStr, false ); // writeNdefMessageToTag(NDEFMsg2Write, detectTag); // By Function new WriteTask( this , NDEFMsg2Write, detectTag).execute(); // By // AsyncTask // Class break ; case 1 : // MIME_MEDIA NDEFMsg2Write = BobNdefMessage.getNdefMsg_from_MIME_MEDIA(payloadStr, "application/skyseraph.nfc_demo" , false ); // writeNdefMessageToTag(NDEFMsg2Write, detectTag); new WriteTask( this , NDEFMsg2Write, detectTag).execute(); break ; case 2 : // RTD_TEXT NDEFMsg2Write = BobNdefMessage.getNdefMsg_from_RTD_TEXT(payloadStr, false , false ); // writeNdefMessageToTag(NDEFMsg2Write, detectTag); new WriteTask( this , NDEFMsg2Write, detectTag).execute(); break ; case 3 : // RTD_URI NDEFMsg2Write = BobNdefMessage.getNdefMsg_from_RTD_URI(payloadStr, ( byte ) 0x01 , false ); // writeNdefMessageToTag(NDEFMsg2Write, detectTag); new WriteTask( this , NDEFMsg2Write, detectTag).execute(); break ; case 4 : // EXTERNAL_TYPE NDEFMsg2Write = BobNdefMessage.getNdefMsg_from_EXTERNAL_TYPE(payloadStr, false ); // writeNdefMessageToTag(NDEFMsg2Write, detectTag); new WriteTask( this , NDEFMsg2Write, detectTag).execute(); break ; default : // RTD_URI NDEFMsg2Write = BobNdefMessage.getNdefMsg_from_RTD_URI(payloadStr, ( byte ) 0x01 , false ); // writeNdefMessageToTag(NDEFMsg2Write, detectTag); new WriteTask( this , NDEFMsg2Write, detectTag).execute(); break ; } } else { Toast.makeText(mContext, "This tag type is not supported" , Toast.LENGTH_SHORT).show(); } } @Override public void onNewIntent(Intent intent) { LogUtil.i(MyConstant.TAG, TAG_ASSIST "Discovered tag with intent: " intent); setIntent(intent); } @Override public void onPause() { super .onPause(); if (alertDialog != null ) alertDialog.cancel(); disableForegroundDispatch(); } private void initUI() { LogUtil.i(MyConstant.TAG, TAG_ASSIST "into initUI" ); // TODO Auto-generated method stub mEditText1 = (EditText) this .findViewById(R.id.write_ndef_tag_et1); mEditText2 = (EditText) this .findViewById(R.id.write_ndef_tag_et2); mTextView1 = (TextView)findViewById(R.id.write_ndef_tag_tv1); mTextView2 = (TextView)findViewById(R.id.write_ndef_tag_tv2); saveUrlButton = (Button)findViewById(R.id.write_ndef_tag_saveBtn); saveUrlButton.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { writeUrlButton.setEnabled( true ); switch (tagTypeFlag) { case 0 : // ABSOLUTE_URI payloadStr = mEditText1.getText().toString(); LogUtil.i(MyConstant.TAG, TAG_ASSIST "payloadStr=" payloadStr); mTextView1.setText( "(Touch NFC Tag to write-ABSOLUTE_URI): " payloadStr); mTextView1.setTextColor(Color.BLUE); break ; case 1 : // MIME_MEDIA payloadStr = mEditText2.getText().toString(); typeStr = mEditText1.getText().toString(); LogUtil.i(MyConstant.TAG, TAG_ASSIST "payloadStr=" payloadStr ",typeStr=" typeStr); mTextView1.setText( "Touch NFC Tag to write-MIME_MEDIA): " typeStr); mTextView1.setTextColor(Color.BLUE); mTextView2 .setText( "Touch NFC Tag to write-MIME_MEDIA,Data): " payloadStr); mTextView2.setTextColor(Color.BLUE); break ; case 2 : // RTD_TEXT payloadStr = mEditText1.getText().toString(); LogUtil.i(MyConstant.TAG, TAG_ASSIST "payloadStr=" payloadStr); mTextView1.setText( "(Touch NFC Tag to write-RTD_TEXT): " payloadStr); mTextView1.setTextColor(Color.BLUE); break ; case 3 : // RTD_URI payloadStr = mEditText1.getText().toString(); LogUtil.i(MyConstant.TAG, TAG_ASSIST "payloadStr=" payloadStr); payloadStr); mTextView1.setTextColor(Color.BLUE); break ; case 4 : // EXTERNAL_TYPE_SMS typeStr = "skyseraph.nfc_demo:externalType" ; payloadStr = mEditText2.getText().toString(); LogUtil.i(MyConstant.TAG, TAG_ASSIST "payloadStr=" payloadStr); mTextView1.setText( "Touch NFC Tag to write-EXTERNAL_TYPE): " payloadStr); mTextView1.setTextColor(Color.BLUE); break ; default : // RTD_URI payloadStr = mEditText1.getText().toString(); LogUtil.i(MyConstant.TAG, TAG_ASSIST "payloadStr=" payloadStr); mTextView1.setTextColor(Color.BLUE); break ; } } }); writeUrlButton = (Button) this .findViewById(R.id.write_ndef_tag_writeBtn); writeUrlButton.setEnabled( false ); writeUrlButton.setOnClickListener( new View.OnClickListener() { public void onClick(View view) { // Write to a tag for as long as the dialog is shown. enableForegroundDispatch(); AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setTitle( "Touch tag to write" ).setOnCancelListener( new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { LogUtil.i(MyConstant.TAG, TAG_ASSIST "mTagWriter - onCancel" ); disableForegroundDispatch(); } }); alertDialog = builder.create(); alertDialog.setCanceledOnTouchOutside( false ); alertDialog.show(); } }); exitButton = (Button)findViewById(R.id.write_ndef_tag_exitBtn); exitButton.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { finish(); } }); mSpinner = (Spinner)findViewById(R.id.write_ndef_tag_sp); mAdapter = new ArrayAdapter<String>( this , android.R.layout.simple_spinner_item, spinnerStr); mAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mSpinner.setAdapter(mAdapter); mSpinner.setOnItemSelectedListener( new SpinnerXMLSelectedListener()); mSpinner.setVisibility(View.VISIBLE); mSpinner.setSelection( 0 , true ); } class SpinnerXMLSelectedListener implements OnItemSelectedListener { public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { LogUtil.i(MyConstant.TAG, TAG_ASSIST "What you have selected=" mAdapter.getItem(arg2) ",position=" arg2); saveUrlButton.setEnabled( true ); writeUrlButton.setEnabled( false ); switch (arg2) { case 0 : // ABSOLUTE_URI tagTypeFlag = 0 ; mTextView1 mTextView1.setTextColor(Color.RED); mEditText2.setVisibility(View.GONE); mTextView2.setVisibility(View.GONE); break ; case 1 : // MIME_MEDIA tagTypeFlag = 1 ; mTextView2 .setText( "Please input a mime_media, exp: application/skyseraph.nfc_demo" ); mTextView1.setTextColor(Color.RED); mEditText2.setVisibility(View.VISIBLE); mTextView2.setVisibility(View.VISIBLE); mTextView1 .setText( "Please input your mime_media data, exp: This is a MIME_MEDIA" ); mTextView2.setTextColor(Color.RED); break ; case 2 : // RTD TEXT tagTypeFlag = 2 ; mTextView1.setText( "Please input a RTD TEXT,exp: This is an RTD-TEXT" ); mTextView1.setTextColor(Color.RED); mEditText2.setVisibility(View.GONE); mTextView2.setVisibility(View.GONE); break ; case 3 : // RTD URI tagTypeFlag = 3 ; mTextView1.setText( "Please input a RTD uri,exp: baidu.com" ); mTextView1.setTextColor(Color.RED); mEditText2.setVisibility(View.GONE); mTextView2.setVisibility(View.GONE); break ; case 4 : // EXTERNAL_TYPE tagTypeFlag = 4 ; mTextView1 .setText( "Please input a EXTERNAL_TYPE, exp: This is an EXTERNAL_TYPE" ); mTextView1.setTextColor(Color.RED); mEditText2.setVisibility(View.GONE); mTextView2.setVisibility(View.GONE); break ; default : // RTD_URI tagTypeFlag = 3 ; mTextView1.setText( "Please input a RTD uri,exp: baidu.com" ); mTextView1.setTextColor(Color.RED); mEditText2.setVisibility(View.GONE); mTextView2.setVisibility(View.GONE); break ; } } public void onNothingSelected(AdapterView<?> arg0) { } } /** * Init NFC */ private void initNFC() { LogUtil.i(MyConstant.TAG, TAG_ASSIST "into initNFC" ); mPendingIntent = PendingIntent.getActivity( this , 0 , new Intent( this , getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0 ); // FLAG_ACTIVITY_SINGLE_TOP: not creating multiple instances of the same // application. IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED); IntentFilter ndefDetected = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); IntentFilter techDetected = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED); // ndef.addDataScheme("http"); // Intent filters for writing to a tag mFilters = new IntentFilter[] { ndefDetected, }; // just trying to find a tag,not ndef or tech mTechLists = new String[][] { new String[] { Ndef. class .getName() }, new String[] { NdefFormatable. class .getName() } }; } /** * @param message * @param detectedTag * @return */ boolean writeNdefMessageToTag(NdefMessage message, Tag detectedTag) { LogUtil.i(MyConstant.TAG, TAG_ASSIST "into writeNdefMessageToTag" ); int size = message.toByteArray().length; try { Ndef ndef = Ndef.get(detectedTag); if (ndef != null ) { ndef.connect(); if (!ndef.isWritable()) { Toast.makeText( this , "Tag is read-only." , Toast.LENGTH_LONG).show(); return false ; } if (ndef.getMaxSize() < size) { Toast.makeText( this , "The data cannot written to tag, Tag capacity is " ndef.getMaxSize() " bytes, message is " size " bytes." , Toast.LENGTH_LONG) .show(); return false ; } ndef.writeNdefMessage(message); ndef.close(); String str = "Message is written tag, message=" message; Toast.makeText( this , str, Toast.LENGTH_LONG).show(); return true ; } else { NdefFormatable ndefFormat = NdefFormatable.get(detectedTag); if (ndefFormat != null ) { try { ndefFormat.connect(); ndefFormat.format(message); ndefFormat.close(); Toast.makeText( this , "The data is written to the tag " , Toast.LENGTH_SHORT) .show(); return true ; } catch (IOException e) { Toast.makeText( this , "Failed to format tag" , Toast.LENGTH_SHORT).show(); return false ; } } else { Toast.makeText( this , "NDEF is not supported" , Toast.LENGTH_SHORT).show(); return false ; } } } catch (Exception e) { Toast.makeText( this , "Write opreation is failed" , Toast.LENGTH_SHORT).show(); } return false ; } /** * @Title: supportedTechs * @Description: Check Support Techs * @param @param techs * @param @return * @return boolean * @throws */ public static boolean supportedTechs(String[] techs) { LogUtil.i(MyConstant.TAG, TAG_ASSIST "into supportedTechs" ); for (String s : techs) { LogUtil.i(MyConstant.TAG, TAG_ASSIST "all supportedTechs = " s); } boolean ultralight = false ; boolean nfcA = false ; boolean ndef = false ; for (String tech : techs) { if (tech.equals( "android.nfc.tech.MifareUltralight" )) { ultralight = true ; LogUtil.i(MyConstant.TAG, TAG_ASSIST "supportedTechs is:ultralight" ); } else if (tech.equals( "android.nfc.tech.NfcA" )) { nfcA = true ; LogUtil.i(MyConstant.TAG, TAG_ASSIST "supportedTechs is:NfcA" ); } else if (tech.equals( "android.nfc.tech.Ndef" ) || tech.equals( "android.nfc.tech.NdefFormatable" )) { ndef = true ; LogUtil.i(MyConstant.TAG, TAG_ASSIST "supportedTechs is:Ndef/NdefFormatable" ); } else if (tech.equals( "android.nfc.tech.MifareClassic" )) { LogUtil.i(MyConstant.TAG, TAG_ASSIST "supportedTechs is:MifareClassic" ); } } if (ultralight && nfcA && ndef) { return true ; } else { return false ; } } /** * enable TagWrite */ private void enableForegroundDispatch() { if (mNfcAdapter != null ) { mNfcAdapter.enableForegroundDispatch( this , mPendingIntent, mFilters, mTechLists); } } /** * disable TagWrite */ private void disableForegroundDispatch() { if (mNfcAdapter != null ) { mNfcAdapter.disableForegroundDispatch( this ); } } /** * NFC Function Check By skyseraph 2013-2 */ private void checkNFCFunction() { // TODO Auto-generated method stub mNfcAdapter = NfcAdapter.getDefaultAdapter( this ); // check the NFC adapter first if (mNfcAdapter == null ) { // mTextView.setText("NFC apdater is not available"); Dialog dialog = null ; CustomDialog.Builder customBuilder = new CustomDialog.Builder(mContext); customBuilder .setTitle(getString(R.string.inquire)) .setMessage(getString(R.string.nfc_notice2)) .setIcon(R.drawable.dialog_icon2) .setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }) .setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }); dialog = customBuilder.create(); dialog.setCancelable( false ); // back dialog.setCanceledOnTouchOutside( false ); SetDialogWidth(dialog).show(); return ; } else { if (!mNfcAdapter.isEnabled()) { Dialog dialog = null ; CustomDialog.Builder customBuilder = new CustomDialog.Builder(mContext); customBuilder .setTitle(getString(R.string.inquire)) .setMessage(getString(R.string.nfc_notice3)) .setIcon(R.drawable.dialog_icon2) .setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }) .setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Intent setnfc = new Intent( Settings.ACTION_WIRELESS_SETTINGS); // Intent setnfc = new // Intent(Settings.ACTION_NFC_SETTINGS); startActivity(setnfc); } }); dialog = customBuilder.create(); dialog.setCancelable( false ); // back dialog.setCanceledOnTouchOutside( false ); SetDialogWidth(dialog).show(); return ; } } } /** * @param dialog * @return */ private Dialog SetDialogWidth(Dialog dialog) { DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); int screenWidth = dm.widthPixels; int screenHeight = dm.heightPixels; WindowManager.LayoutParams params = dialog.getWindow().getAttributes(); if (screenWidth > screenHeight) { params.width = ( int )((( float )screenHeight) * 0.875 ); } else { params.width = ( int )((( float )screenWidth) * 0.875 ); } dialog.getWindow().setAttributes(params); return dialog; } /** *********************************************************************** @Title :WriteNdefTag.java * @Package :skyseraph.nfc_demo.tag.write * @ClassName : WriteTask * @Description : TODO * @author : skyseraph00@163.com * @date : 2013-9-13 上午11:38:58 * @version : V1.0 */ static class WriteTask extends AsyncTask<Void, Void, Void> { Activity host = null ; NdefMessage msg = null ; Tag tag = null ; String text = null ; WriteTask(Activity host, NdefMessage msg, Tag tag) { LogUtil.i(MyConstant.TAG, TAG_ASSIST "into WriteTask AsyncTask" ); this .host = host; this .msg = msg; this .tag = tag; } @Override protected Void doInBackground(Void... arg0) { int size = msg.toByteArray().length; try { Ndef ndef = Ndef.get(tag); if (ndef == null ) { NdefFormatable formatable = NdefFormatable.get(tag); if (formatable != null ) { try { formatable.connect(); try { formatable.format(msg); } catch (Exception e) { text = "Failed to format tag,Tag refused to format" ; } } catch (Exception e) { text = "Failed to connect tag,Tag refused to connect" ; } finally { formatable.close(); } } else { text = "NDEF is not supported in this Tag" ; } } else { ndef.connect(); try { if (!ndef.isWritable()) { text = "Tag is read-only" ; } else if (ndef.getMaxSize() < size) { text = "The data cannot written to tag,Message is too big for tag,Tag capacity is " ndef.getMaxSize() " bytes, message is " size " bytes." ; } else { ndef.writeNdefMessage(msg); text = "Message is written tag, message=" msg; } } catch (Exception e) { text = "Tag refused to connect" ; } finally { ndef.close(); } } } catch (Exception e) { text = "Write opreation is failed,General exception: " e.getMessage(); LogUtil.i(MyConstant.TAG, TAG_ASSIST "Exception when writing tag,Write opreation is failed" text); } return ( null ); } @Override protected void onPostExecute(Void unused) { if (text != null ) { Toast.makeText(host, text, Toast.LENGTH_SHORT).show(); } // host.finish(); // after writed, auto finish } } } |
好例子网口号:伸出你的我的手 — 分享!
网友评论
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
支持(0) 盖楼(回复)
支持(0) 盖楼(回复)