當我把貼近我的手機的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意圖我希望它重定向到度量活動。
此外,當用戶已經被記錄在我想要的標籤的數據將被立即傳送 。現在,如果我想要傳輸數據,我必須保持標記靠近 電話才能開始測量活動,然後再放回去,然後再回到 傳輸數據。
我該怎麼做這兩件事?