当我把贴近我的手机的NFC标签,我想我的应用程序启动 所以我说这到我的清单:Android的NFC重定向意图
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED" android:resource="@xml/nfc_tech_filter" />
这个伟大的工程。
如果用户没有登录我希望用户先登录 ,才可以从标签,所以我加入到我的 的onCreate这是我衡量活动进行传送的数据:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.sessionManager = new SessionManager(this);
this.sessionManager.login();
this.setContentView(R.layout.activity_measure);
this.nfcAdapter = NfcAdapter.getDefaultAdapter(this);
this.pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
this.filters = new IntentFilter[] { ndef, };
this.techLists = new String[][] { new String[] { android.nfc.tech.NfcV.class.getName() } };
this.textViewYear = (TextView) findViewById(R.id.measure_textview_year);
this.textViewMonthDay = (TextView) findViewById(R.id.measure_textview_month_day);
this.textViewTime = (TextView) findViewById(R.id.measure_textview_time);
this.textViewGlucose = (TextView) findViewById(R.id.measure_textview_glucose);
new StartReadTask().execute();
}
但用户登录后,他被重定向到我的主菜单,因为这个 实现的:
/**
*
* @param v
*/
@Override
public void onClick(View view) {
String username = this.textEditUsername.getText().toString();
String password = this.textEditPassword.getText().toString();
if(username.trim().length() > 0 && password.trim().length() > 0){
if(username.equals("test") && password.equals("test")){
this.sessionManager.createLoginSession("Test-Name", "Test-Email");
Intent intent = new Intent(this.getApplicationContext(), MainActivity.class);
this.startActivity(intent);
this.finish();
} else {
this.dialogAlertManager.showAlertDialog(LoginActivity.this, "Login failed..", "Username or Password is incorrect", false);
}
} else {
this.dialogAlertManager.showAlertDialog(LoginActivity.this, "Login failed..", "Please enter username and password", false);
}
}
这里所说的“MainActivity”是我的主菜单。但我想活动 重定向到我的测量活动,但我不知道我该怎么做。 “正常”登录后,没有nfc意图,我需要应用程序重定向到主菜单 但与nfc意图我希望它重定向到度量活动。
此外,当用户已经被记录在我想要的标签的数据将被立即传送 。现在,如果我想要传输数据,我必须保持标记靠近 电话才能开始测量活动,然后再放回去,然后再回到 传输数据。
我该怎么做这两件事?