繁体   English   中英

为什么有些电话不需要意图过滤器?

[英]Why some phones don't need intent filter?

这类似于此问题,但不完全相同。 我不是问如何在运行时请求权限。

我正在android中进行nfc工作,因此我需要以下权限

<intent-filter>
            <action android:name="android.nfc.action.TAG_DISCOVERED" />
</intent-filter>

但是,在三星(SM-N900L)中,我只需要使用

String action = intent.getAction();
if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)
        || NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)
        || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
    resolveIntent(intent);
}

基本上,我的问题是,为什么在三星中我不需要意图过滤器,而在其他手机中我需要过滤器?

前景配置

@Override
protected void onResume() {
    super.onResume();
    if (hasNfcAdapter()) {
        if (!mAdapter.isEnabled()) {
            Toast.makeText(this, "NFC is disabled.", Toast.LENGTH_LONG).show();
        }
        mAdapter.enableForegroundDispatch(this, mPendingIntent, null, null);
    }
}

@Override
protected void onPause() {
    super.onPause();
    if (hasNfcAdapter())
        mAdapter.disableForegroundDispatch(this);
}

protected void initNfc() {
    mAdapter = NfcAdapter.getDefaultAdapter(this);
    if (mAdapter != null) {
        mPendingIntent = PendingIntent.getActivity(this, 0,
                new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
    }
}

protected boolean hasNfcAdapter() {
    return mAdapter != null;
}

这个问题应该问三星。

通常,供应商可以根据需要更改Android操作系统,并且在这种情况下,三星似乎已改变了行为。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM