考虑一下这个场景:我制作了两个安卓应用程序,比如 A 和 B。B 扫描 NFC 标签,存储一个字符串“nfcservice”,然后我将该字符串存储在一个字节数组中,比如 TEMP_MSG 为十六进制。之后,我将该数组转换为字符串并将其发送到 App-A。在 App-A 中,我尝试匹配它,但每次都失败。问题是什么?你能提出一些建议吗?
应用程序-B 代码:
//nfcservice
byte[] TEMP_MSG = {(byte)0x6E, (byte)0x66, (byte)0x63, (byte)0x73, (byte)0x65,
(byte)0x72, (byte)0x76, (byte)0x69, (byte)0x63, (byte)0x65};
String nfcservicestring = new String(TEMP_MSG);
Intent intent = new Intent("com.android.apps.metromanager.MetroManagerActivity");
intent.putExtra("keyword", nfcservicestring);
startActivity(intent);
应用程序-A 代码:
public class MetroManagerActivity extends Activity
{
TextView myText;
String myString;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_metro_manager);
Bundle bundle = getIntent().getExtras();
if(bundle!=null) {
myString = bundle.getString("keyword");
Toast.makeText(getApplicationContext(), myString, Toast.LENGTH_LONG).show();
if(myString.equals("nfcservice")) {
LinearLayout lView = new LinearLayout(this);
myText = new TextView(this);
myText.setText("Welcome");
lView.addView(myText);
setContentView(lView);
} else {
LinearLayout lView = new LinearLayout(this);
myText = new TextView(this);
myText.setText("Bye Bye");
lView.addView(myText);
setContentView(lView);
}
}
}
}