对于一个工程项目,我基本上需要欺骗我的手机退出 NFC 搜索模式并进入手机持续输出能量的模式。显然我已经在设置中激活了 NFC,但我可以欺骗它离开搜索模式并让它持续输出能量的唯一方法是如果我把它放在一个空白标签的顶部。
我正在考虑实现这个 NFC 光束功能:(public boolean invokeBeam
活动活动)并将其植入BeamLargeFiles
Android Studio 中提供的示例代码中,如下所示。
我是应用程序开发的新手(尽管我有相当多的编码经验),所以我只是不确定它是否可行,或者我是否正在寻找正确的地方。任何想法,想法和帮助表示赞赏!
package com.example.android.beamlargefiles;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.text.Html;
import android.widget.TextView;
import android.view.Menu;
import com.example.android.common.activities.SampleActivityBase;
import com.example.android.common.logger.Log;
import com.example.android.common.logger.LogFragment;
import com.example.android.common.logger.LogWrapper;
import com.example.android.common.logger.MessageOnlyLogFilter;
/**
* A simple launcher activity containing a summary sample description
* and a few action bar buttons.
*/
public class MainActivity extends SampleActivityBase {
public static final String TAG = "MainActivity";
public static final String FRAGTAG = "BeamLargeFilesFragment";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView sampleOutput = (TextView) findViewById(R.id.sample_output);
sampleOutput.setText(Html.fromHtml(getString(R.string.intro_message)));
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
BeamLargeFilesFragment fragment = new BeamLargeFilesFragment();
transaction.add(fragment, FRAGTAG);
transaction.commit();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
/** Create a chain of targets that will receive log data */
@Override
public void initializeLogging() {
// Wraps Android's native log framework.
LogWrapper logWrapper = new LogWrapper();
// Using Log, front-end to the logging chain, emulates android.util.log method signatures.
Log.setLogNode(logWrapper);
// Filter strips out everything except the message text.
MessageOnlyLogFilter msgFilter = new MessageOnlyLogFilter();
logWrapper.setNext(msgFilter);
// On screen logging via a fragment with a TextView.
LogFragment logFragment = (LogFragment) getSupportFragmentManager()
.findFragmentById(R.id.log_fragment);
msgFilter.setNext(logFragment.getLogView());
logFragment.getLogView().setTextAppearance(this, R.style.Log);
logFragment.getLogView().setBackgroundColor(Color.WHITE);
Log.i(TAG, "Ready");
}
}
来自android studio提供的beamlargedata示例代码