context.getSystemService (Context.NSD_SERVICE)를 사용하는 데 문제가 있습니다. 그냥 충돌합니다. 코드는 다음과 같습니다 :context.getSystemService를 사용하여 NsdManager를 찾을 수 없습니다.
내 네트워크 서비스 검색 도우미 :
public NetworkServiceDiscoveryHelper(Context context)
{
mContext = context;
mNetworkDiscoveryManager = (NsdManager) context.getSystemService(Context.NSD_SERVICE);
}
내 활동 클래스 :
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mNsdHelper = new NetworkServiceDiscoveryHelper(this);
mNsdHelper.initializeNsd();
}
내가 http://developer.android.com/training/connect-devices-wirelessly/nsd.html에서 샘플 코드를 다음 봤는데가, 자신의 활동 생성자는 약간 다릅니다 :
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mStatusView = (TextView) findViewById(R.id.status);
mUpdateHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
String chatLine = msg.getData().getString("msg");
addChatLine(chatLine);
}
};
mConnection = new ChatConnection(mUpdateHandler);
mNsdHelper = new NsdHelper(this);
mNsdHelper.initializeNsd();
}
누군가 내게 설명 할 수있는 이유는 무엇입니까? 설치가 작동하지 않습니다. 추가 기능이 필요합니까? 나는 기본적으로 서비스를 생성하고 동일한 전화를 사용하여이 기능을 다시 테스트하도록 설정하려고했습니다. 네트워크 서비스 도우미와 지금까지의 활동 만 구현했습니다. 추가 기능을 설정해야합니까?
맨 아래 하나만 필요합니다. – Bushes