GVKun编程网logo

MalformedByteSequenceException:2字节UTF-8序列的无效字节2(2字节的utf-8序列的字节2无效)

26

对于想了解MalformedByteSequenceException:2字节UTF-8序列的无效字节2的读者,本文将提供新的信息,我们将详细介绍2字节的utf-8序列的字节2无效,并且为您提供关于.

对于想了解MalformedByteSequenceException:2字节UTF-8序列的无效字节2的读者,本文将提供新的信息,我们将详细介绍2字节的utf-8序列的字节2无效,并且为您提供关于.impl.io.MalformedByteSequenceException: 2 字节的 UTF-8 序列、2字节的UTF-8序列的字节2无效 解决方案、Activiti:MalformedByteSequenceException: 3 字节的 UTF-8 序列的字节 3 无效。、android.content.IntentFilter.MalformedMimeTypeException的实例源码的有价值信息。

本文目录一览:

MalformedByteSequenceException:2字节UTF-8序列的无效字节2(2字节的utf-8序列的字节2无效)

MalformedByteSequenceException:2字节UTF-8序列的无效字节2(2字节的utf-8序列的字节2无效)

我有一个包含阿拉伯字符的xml文件。尝试解析文件时,出现异常,MalformedByteSequenceException:2字节UTF-8序列的无效字节2。我使用POI
DOM来解析文档。

日志是

2012-03-19 11:30:00,433 [ERROR] (com.infomindz.remitglobe.bll.remittance.BlackListBean) - Errorcom.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 2 of 2-byte UTF-8 sequence.    at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(Unknown Source)    at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(Unknown Source)    at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(Unknown Source)    at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipChar(Unknown Source)    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)    at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)    at com.infomindz.remitglobe.bll.remittance.BlackListBean.updateGeneralBlackListDetail(Unknown Source)    at com.infomindz.remitglobe.bll.remittance.schedulers.BlackListUpdateScheduler.executeInternal(Unknown Source)    at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:86)    at org.quartz.core.JobRunShell.run(JobRunShell.java:216)    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)

该异常仅在Windows Machine中出现,在Linux Machine中不出现。我该如何解决此问题。任何建议都应是可取的。

答案1

小编典典

我已解决问题,方法是使用UTF8格式创建XML文件。

OutputStreamWriter bufferedWriter = new OutputStreamWriter(filePath +                        System.getProperty("file.separator") + fileName), "UTF8");

使用上面的代码创建文件后,编码问题就解决了。感谢大家,在这里付出努力。

.impl.io.MalformedByteSequenceException: 2 字节的 UTF-8 序列

.impl.io.MalformedByteSequenceException: 2 字节的 UTF-8 序列

OSC 请你来轰趴啦!1028 苏州源创会,一起寻宝 AI 时代

Caused by: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 2 字节的 UTF-8 序列 

 

解决方案:

把出现问题 xml 文件中的 UTF-8 修改为 UTF8 即可且看如下:

image

 

2字节的UTF-8序列的字节2无效 解决方案

2字节的UTF-8序列的字节2无效 解决方案

2字节的UTF-8序列的字节2无效 解决方案

2字节的UTF-8序列的字节2无效

使用标签时,也出现这种情况。

这个问题是因为在xml文件中的中文注释的问题,有两种解决方案:

一、将xml文件的中文注释全部删除,解决

二、将xml文件顶部的encoding=UTF-8改为encoding=UTF8可以解决问题

个人博客为:
MoYu's Github Blog
MoYu's Gitee Blog

Activiti:MalformedByteSequenceException: 3 字节的 UTF-8 序列的字节 3 无效。

Activiti:MalformedByteSequenceException: 3 字节的 UTF-8 序列的字节 3 无效。

在win下开发,有时编译或运行项目会报3字节的UTF-8序列的字节3无效。
解决该问题的办法
1、将xml头文件改为GBK编码方式 ,我这里不OK

  1. <?xml version="1.0" encoding="GBK"?>  


2、使用Maven修改默认格式 ,我这里不OK

<build>
        <plugins>
            <!-- resource插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>

 

3、以上如果还不可行,那么在pom.xml里加入 ,我这里不OK

    1. <properties>  
    2.     <!-- 设置默认编码 -->  
    3.     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
    4. </properties> 

4、修改bpmn文件的编码格式为UTF-8,我这里OK

用记事本打开bpmn文件,另存为utf-8编码的文件,XML也是utf-8编码格式

pom.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>ActDemo</groupId>
    <artifactId>Activiti</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <!-- 设置默认编码 -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-engine</artifactId>
            <version>6.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.21</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.21</version>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.4.193</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>6.0.5</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <!-- resource插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

bpmn文件

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" xmlns:tns="http://www.activiti.org/test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" expressionLanguage="http://www.w3.org/1999/XPath" id="m1520825820812" name="" targetNamespace="http://www.activiti.org/test" typeLanguage="http://www.w3.org/2001/XMLSchema">
  <process id="process1" isClosed="false" isExecutable="true" processType="None">
    <startEvent id="_2" name="StartEvent"/>
    <endEvent id="_3" name="EndEvent"/>
    <userTask activiti:exclusive="true" id="_4" name="软件开发一"/>
    <userTask activiti:exclusive="true" id="_5" name="软件开发二"/>
    <sequenceFlow id="_6" sourceRef="_2" targetRef="_4"/>
    <sequenceFlow id="_7" sourceRef="_4" targetRef="_5"/>
    <sequenceFlow id="_8" sourceRef="_5" targetRef="_3"/>
  </process>
  <bpmndi:BPMNDiagram documentation="background=#FFFFFF;count=1;horizontalcount=1;orientation=0;width=842.4;height=1195.2;imageableWidth=832.4;imageableHeight=1185.2;imageableX=5.0;imageableY=5.0" id="Diagram-_1" name="New Diagram">
    <bpmndi:BPMNPlane bpmnElement="process1">
      <bpmndi:BPMNShape bpmnElement="_2" id="Shape-_2">
        <omgdc:Bounds height="32.0" width="32.0" x="60.0" y="160.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_3" id="Shape-_3">
        <omgdc:Bounds height="32.0" width="32.0" x="805.0" y="180.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_4" id="Shape-_4">
        <omgdc:Bounds height="55.0" width="85.0" x="275.0" y="190.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_5" id="Shape-_5">
        <omgdc:Bounds height="55.0" width="85.0" x="590.0" y="200.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="_6" id="BPMNEdge__6" sourceElement="_2" targetElement="_4">
        <omgdi:waypoint x="92.0" y="176.0"/>
        <omgdi:waypoint x="275.0" y="217.5"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_7" id="BPMNEdge__7" sourceElement="_4" targetElement="_5">
        <omgdi:waypoint x="360.0" y="217.5"/>
        <omgdi:waypoint x="590.0" y="227.5"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_8" id="BPMNEdge__8" sourceElement="_5" targetElement="_3">
        <omgdi:waypoint x="675.0" y="227.5"/>
        <omgdi:waypoint x="805.0" y="196.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

注意格式:为uft-8

 

android.content.IntentFilter.MalformedMimeTypeException的实例源码

android.content.IntentFilter.MalformedMimeTypeException的实例源码

项目:react-native-nfc-manager    文件:NfcManager.java   
@ReactMethod
  private void registerTagEvent(String alertMessage,Boolean invalidateAfterFirstRead,Callback callback) {
      Log.d(LOG_TAG,"registerTag");
isForegroundEnabled = true;

// capture all mime-based dispatch NDEF
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_disCOVERED);
try {
    ndef.addDataType("*/*");
} catch (MalformedMimeTypeException e) {
    throw new RuntimeException("fail",e);
   }
intentFilters.add(ndef);

// capture all rest NDEF,such as uri-based
      intentFilters.add(new IntentFilter(NfcAdapter.ACTION_TECH_disCOVERED));
techLists.add(new String[]{Ndef.class.getName()});

// for those without NDEF,get them as tags
      intentFilters.add(new IntentFilter(NfcAdapter.ACTION_TAG_disCOVERED));

if (isResumed) {
    enabledisableForegrounddispatch(true);
}
      callback.invoke();
    }
项目:Travel-Card-Reminder    文件:MainActivity.java   
public static void setupForegrounddispatch(final Activity activity,NfcAdapter adapter) {
    final Intent intent = new Intent(activity.getApplicationContext(),ReadCardActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(),intent,0);

    IntentFilter[] filters = new IntentFilter[1];
    String[][] techList = new String[][]{};

    filters[0] = new IntentFilter();
    filters[0].addAction(NfcAdapter.ACTION_NDEF_disCOVERED);
    filters[0].addCategory(Intent.CATEGORY_DEFAULT);
    try {
        filters[0].addDataType("*/*"); //Todo Use only needed MIME based dispatches.
    } catch (MalformedMimeTypeException e) {
        throw new RuntimeException("MIME type not supported.");
    }

    adapter.enableForegrounddispatch(activity,pendingIntent,filters,techList);
}
项目:android-testdpc    文件:AddCrossprofileIntentFilterFragment.java   
/**
 * Constructs an intent filter from user input. This intent-filter is used for cross-profile
 * intent.
 *
 * @return a user constructed intent filter.
 */
private IntentFilter getIntentFilter() {
    if (mActions.isEmpty() && mCategories.isEmpty() && mDataSchemes.isEmpty()
            && mDataTypes.isEmpty()) {
        return null;
    }
    IntentFilter intentFilter = new IntentFilter();
    for (String action : mActions) {
        intentFilter.addAction(action);
    }
    for (String category : mCategories) {
        intentFilter.addCategory(category);
    }
    for (String dataScheme : mDataSchemes) {
        intentFilter.addDataScheme(dataScheme);
    }
    for (String dataType : mDataTypes) {
        try {
            intentFilter.addDataType(dataType);
        } catch (MalformedMimeTypeException e) {
            Log.e(TAG,"Malformed mime type: " + e);
            return null;
        }
    }
    return intentFilter;
}
项目:NFCPoC    文件:MainActivity.java   
/**
 * @param activity The corresponding {@link Activity} requesting the foreground dispatch.
 * @param adapter  The {@link NfcAdapter} used for the foreground dispatch.
 */
public static void setupForegrounddispatch(final Activity activity,activity.getClass());
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(),0);

    IntentFilter[] filters = new IntentFilter[1];
    String[][] techList = new String[][]{};

    // Notice that this is the same filter as in our manifest.
    filters[0] = new IntentFilter();
    filters[0].addAction(NfcAdapter.ACTION_NDEF_disCOVERED);
    filters[0].addCategory(Intent.CATEGORY_DEFAULT);
    try {
        filters[0].addDataType(MIME_TEXT_PLAIN);
    } catch (MalformedMimeTypeException e) {
        throw new RuntimeException("Check your mime type.");
    }

    adapter.enableForegrounddispatch(activity,techList);
}
项目:KendaliPintuAndroid    文件:NFcopenDoorActivity.java   
public static void setupForegrounddispatch(final Activity activity,0);

    IntentFilter[] filters = new IntentFilter[1];
    String[][] techList = new String[][] {};
    filters[0] = new IntentFilter();
    filters[0].addAction(NfcAdapter.ACTION_NDEF_disCOVERED);
    filters[0].addCategory(Intent.CATEGORY_DEFAULT);
    try {
        filters[0].addDataType(MIME_TEXT_PLAIN);
    } catch (MalformedMimeTypeException e) {
        throw new RuntimeException("Check your mime type.");
    }
    adapter.enableForegrounddispatch(activity,techList);
}
项目:SkunkWrx    文件:NFCActivity.java   
/**
 * @param activity The corresponding {@link Activity} requesting the foreground dispatch.
 * @param adapter The {@link NfcAdapter} used for the foreground dispatch.
 */
public static void setupForegrounddispatch(final Activity activity,techList);
}
项目:Studentenportal    文件:NfcLogin.java   
public void onCreate(Bundle savedInstanceState) {
    // setup NFC
    // http://stackoverflow.com/questions/5685946/nfc-broadcastreceiver-problem
    // http://stackoverflow.com/questions/5685770/nfc-intent-get-info-from-the-tag
    // NOTE on devices without NFC,this method call returns NULL
    mNfcAdapter = NfcAdapter.getDefaultAdapter(mActivity);

    mNfcPendingIntent = PendingIntent.getActivity(mActivity,new Intent(mActivity,mActivity.getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),0);

    IntentFilter tech = new IntentFilter(NfcAdapter.ACTION_TECH_disCOVERED);
    try {
        tech.addDataType("*/*");
    } catch (MalformedMimeTypeException e) {
        throw new RuntimeException("fail",e);
    }
    mNfcFilters = new IntentFilter[] { tech };

    // mifare Classic are also NfcA,but in contrary to NfcA,mifareClassic support is optional
    // http://developer.android.com/reference/android/nfc/tech/mifareClassic.html
    mNfcTechLists = new String[][] { new String[] { NfcA.class.getName() } };
}
项目:nfc    文件:StickyNotesActivity.java   
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

    setContentView(R.layout.main);
    findViewById(R.id.write_tag).setonClickListener(mTagWriter);
    mNote = ((EditText) findViewById(R.id.note));
    mNote.addTextChangedListener(mTextWatcher);

    // Handle all of our received NFC intents in this activity.
    mNfcPendingIntent = PendingIntent.getActivity(this,new Intent(this,getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),0);

    // Intent filters for reading a note from a tag or exchanging over p2p.
    IntentFilter ndefDetected = new IntentFilter(NfcAdapter.ACTION_NDEF_disCOVERED);
    try {
        ndefDetected.addDataType("text/plain");
    } catch (MalformedMimeTypeException e) { }
    mNdefExchangeFilters = new IntentFilter[] { ndefDetected };

    // Intent filters for writing to a tag
    IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_disCOVERED);
    mWriteTagFilters = new IntentFilter[] { tagDetected };
}
项目:Android-nfc-p2p-Communication    文件:MainActivity.java   
private void _init()
{
    _nfcAdapter = NfcAdapter.getDefaultAdapter(this);

    if (_nfcAdapter == null)
    {
        Toast.makeText(this,"This device does not support NFC.",Toast.LENGTH_LONG).show();
        return;
    }

    if (_nfcAdapter.isEnabled())
    {
        _pendingIntent = PendingIntent.getActivity(this,0);

        IntentFilter ndefDetected = new IntentFilter(NfcAdapter.ACTION_NDEF_disCOVERED);
        try
        {
            ndefDetected.addDataType(_MIME_TYPE);
        } catch (MalformedMimeTypeException e)
        {
            Log.e(this.toString(),e.getMessage());
        }

        _intentFilters = new IntentFilter[] { ndefDetected };
    }
}
项目:Android-nfc-p2p-Communication    文件:ReadingWritingActivity.java   
private void _init()
{
    _nfcAdapter = NfcAdapter.getDefaultAdapter(this);

    if (_nfcAdapter == null)
    {
        Toast.makeText(this,e.getMessage());
        }

        _readIntentFilters = new IntentFilter[] { ndefDetected };
    }
}
项目:AndroidNdefImplementation    文件:NfcNdefReader.java   
public void setupForegrounddispatch(Activity activity) {
    final Intent intent = new Intent(activity.getApplicationContext(),activity.getClass());
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    final PendingIntent pendingIntent = PendingIntent.getActivity(
            activity.getApplicationContext(),0);

    IntentFilter[] filters = new IntentFilter[1];
    String[][] techList = new String[][] {};

    // Notice that this is the same filter as in our manifest.
    filters[0] = new IntentFilter();
    filters[0].addAction(NfcAdapter.ACTION_NDEF_disCOVERED);
    filters[0].addCategory(Intent.CATEGORY_DEFAULT);
    try {
        filters[0].addDataType(MIME_TEXT_PLAIN);
    } catch (MalformedMimeTypeException e) {
        throw new RuntimeException("Check your mime type.");
    }
    nfcAdapter.enableForegrounddispatch(activity,techList);
}
项目:NFC-Reader-and-Chat    文件:Beam.java   
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.beamer);

    mInfoText = (TextView) findViewById(R.id.mInfo);
    writeText = (EditText) findViewById(R.id.textWrite);

    // Check for available NFC Adapter
    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (mNfcAdapter == null) {
        mInfoText = (TextView) findViewById(R.id.mInfo);
        mInfoText.setText("NFC is not available on this device.");
    }

    mNfcPendingIntent = PendingIntent.getActivity(this,0);
    // Intent filters for exchanging over p2p.
    IntentFilter ndefDetected = new IntentFilter(NfcAdapter.ACTION_NDEF_disCOVERED);
    try {
        ndefDetected.addDataType("*/*");
    } catch (MalformedMimeTypeException e) {
        Toast.makeText(getApplicationContext(),"Error Exception",Toast.LENGTH_SHORT).show();
    }
    mNdefExchangeFilters = new IntentFilter[] { ndefDetected,};
}
项目:effective_android_sample    文件:ZannenNfcWriter.java   
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

    setContentView(R.layout.main);
    findViewById(R.id.write_tag).setonClickListener(mTagWriter);

    // Handle all of our received NFC intents in this activity.
    mNfcPendingIntent = PendingIntent.getActivity(this,0);

    // Intent filters for reading a note from a tag or exchanging over p2p.
    IntentFilter ndefDetected = new IntentFilter(NfcAdapter.ACTION_NDEF_disCOVERED);
    try {
        ndefDetected.addDataType("text/plain");
    } catch (MalformedMimeTypeException e) { }
    mNdefExchangeFilters = new IntentFilter[] { ndefDetected };

    // Intent filters for writing to a tag
    IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_disCOVERED);
    mWriteTagFilters = new IntentFilter[] { tagDetected };
}
项目:deprecated-event-bus    文件:EventsBus.java   
/**
 * @return Registration id to use in unregister(regId) method
 */
public static synchronized int register(String receiverId,EventsListener listener) {
    check();

    if (listener == null) throw new NullPointerException("Listener cannot be null");

    EventsReceiver receiver = new EventsReceiver();
    receiver.mReceiverId = receiverId;
    receiver.mListener = listener;

    try {
        sAppContext.registerReceiver(receiver,new IntentFilter(sIntentAction,BASE_MIME_TYPE + "/*"));
    } catch (MalformedMimeTypeException e) {
        e.printstacktrace();
    }

    sReceiversMap.put(++sRegistrationId,receiver);

    for (Intent sticky : sstickyEventsMap.values()) {
        receiver.onReceive(sAppContext,sticky);
    }

    return sRegistrationId;
}
项目:android-basic-test    文件:NfcTest.java   
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mNfcAdapter = NfcAdapter.getDefaultAdapter(getActivity());

    Intent intent = new Intent(getActivity(),getActivity().getClass());
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    mPendingIntent = PendingIntent.getActivity(getActivity(),0);

    mTechLists = new String[][] {new String[] {mifareClassic.class.getName()}};
    IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_TECH_disCOVERED);
    try {
        ndef.addDataType("*/*");
    } catch (MalformedMimeTypeException e) {
        throw new RuntimeException("fail",e);
    }
    mFilters = new IntentFilter[] {ndef};

    setButtonVisibility(true);
}
项目:mensacard-hack    文件:NfcPlugin.java   
private void removeMimeType(JSONArray data,CallbackContext callbackContext) throws JSONException {
    String mimeType = "";
    try {
        mimeType = data.getString(0);
        /*boolean removed =*/ removeIntentFilter(mimeType);
        callbackContext.success();
    } catch (MalformedMimeTypeException e) {
        callbackContext.error("Invalid MIME Type " + mimeType);
    }
}
项目:mensacard-hack    文件:NfcPlugin.java   
private void registerMimeType(JSONArray data,CallbackContext callbackContext) throws JSONException {
    String mimeType = "";
    try {
        mimeType = data.getString(0);
        intentFilters.add(createIntentFilter(mimeType));
        callbackContext.success();
    } catch (MalformedMimeTypeException e) {
        callbackContext.error("Invalid MIME Type " + mimeType);
    }
}
项目:mensacard-hack    文件:NfcPlugin.java   
private boolean removeIntentFilter(String mimeType) throws MalformedMimeTypeException {
  boolean removed = false;
  Iterator<IntentFilter> iter = intentFilters.iterator();
  while (iter.hasNext()) {
    IntentFilter intentFilter = iter.next();
    String mt = intentFilter.getDataType(0);
    if (mimeType.equals(mt)) {
      intentFilters.remove(intentFilter);
      removed = true;
    }
  }
  return removed;
}
项目:Androidthingsstudy    文件:Foregrounddispatch.java   
@Override
public void onCreate(Bundle savedState) {
    super.onCreate(savedState);

    setContentView(R.layout.foreground_dispatch);
    mText = (TextView) findViewById(R.id.text);
    mText.setText("Scan a tag");

    mAdapter = NfcAdapter.getDefaultAdapter(this);

    // Create a generic PendingIntent that will be deliver to this activity. The NFC stack
    // will fill in the intent with the details of the discovered tag before delivering to
    // this activity.
    mPendingIntent = PendingIntent.getActivity(this,0);

    // Setup an intent filter for all MIME based dispatches
    IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_disCOVERED);
    try {
        ndef.addDataType("*/*");
    } catch (MalformedMimeTypeException e) {
        throw new RuntimeException("fail",e);
    }
    mFilters = new IntentFilter[] {
            ndef,};

    // Setup a tech list for all NfcF tags
    mTechLists = new String[][] { new String[] { NfcF.class.getName() } };
}
项目:anroid-nfc-plugin    文件:ScanActivity.java   
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Create NFC Adapter
    mAdapter = NfcAdapter.getDefaultAdapter(this);

    // Pending intent
    mPendingIntent = PendingIntent.getActivity(this,ScanActivity.class).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),0);

    // Setup an intent filter for all MIME based dispatches (TEXT);
    IntentFilter ndefText = new IntentFilter(NfcAdapter.ACTION_NDEF_disCOVERED);
    try {
        ndefText.addDataType("*/*");
    } catch (MalformedMimeTypeException e) {
    }       

    // Setup an intent filter for all MIME based dispatches (URI);
    IntentFilter ndefURI = new IntentFilter(NfcAdapter.ACTION_NDEF_disCOVERED);
    ndefURI.addDataScheme("http");
    ndefURI.addDataScheme("https");

    mFilters = new IntentFilter[] { ndefText,ndefURI}; 

    // Setup a tech list for all NfcF tags
    mTechLists = new String[][] { new String[] { NfcF.class.getName() } };          
}
项目:android-nfc-wrapper    文件:NFCManager.java   
public IntentFilter[] getIntentFilter(String action,String category,String mimeType) {
    IntentFilter filter = new IntentFilter();
    if(action != null) filter.addAction(action);
    if(category != null) filter.addCategory(category);

    if(mimeType != null) {
        try {
            filter.addDataType(mimeType);
        } catch (MalformedMimeTypeException e) {
            throw new RuntimeException("Error handling MIME type.");
        }
    }

    return new IntentFilter[] { filter };
}
项目:FMTech    文件:lbt.java   
public final void a(Bundle paramBundle)
{
  super.a(paramBundle);
  this.ac = this.m.getString("square_id");
  if (paramBundle != null)
  {
    this.ag = ((Uri)paramBundle.getParcelable("uploading_image_uri"));
    this.ah = ((Uri)paramBundle.getParcelable("current_data"));
    this.Z = ((ipf)paramBundle.getParcelable("selected_user_photo"));
    this.b = ((RectF)paramBundle.getParcelable("CROP_COORDINATES"));
  }
  mbf localmbf = this.bn;
  if (lcm.a == null)
  {
    IntentFilter localIntentFilter = new IntentFilter();
    lcm.a = localIntentFilter;
    localIntentFilter.addAction("com.google.android.libraries.social.squares.edit.UPLOAD_PROGRESS");
  }
  try
  {
    lcm.a.addDataType("image/*");
    fy.a(localmbf.getApplicationContext()).a(new lcn(this),lcm.a);
    return;
  }
  catch (IntentFilter.MalformedMimeTypeException localMalformedMimeTypeException)
  {
    for (;;)
    {
      Log.e("UploadSquarePhotoTask","MIME type cannot be recognized.");
    }
  }
}
项目:ApkLauncher    文件:Foregrounddispatch.java   
@Override
public void onCreate(Bundle savedState) {
    super.onCreate(savedState);

    setContentView(R.layout.foreground_dispatch);
    mText = (TextView) findViewById(R.id.text);
    mText.setText("Scan a tag");

    mAdapter = NfcAdapter.getDefaultAdapter(this);

    // Create a generic PendingIntent that will be deliver to this activity. The NFC stack
    // will fill in the intent with the details of the discovered tag before delivering to
    // this activity.
    mPendingIntent = org.bbs.apklauncher.emb.PendingIntentHelper.getActivity(this,new org.bbs.apklauncher.emb.IntentHelper(this,};

    // Setup a tech list for all NfcF tags
    mTechLists = new String[][] { new String[] { NfcF.class.getName() } };
}
项目:ApiDemos    文件:Foregrounddispatch.java   
@Override
public void onCreate(Bundle savedState) {
    super.onCreate(savedState);

    setContentView(R.layout.foreground_dispatch);
    mText = (TextView) findViewById(R.id.text);
    mText.setText("Scan a tag");

    mAdapter = NfcAdapter.getDefaultAdapter(this);

    // Create a generic PendingIntent that will be deliver to this activity. The NFC stack
    // will fill in the intent with the details of the discovered tag before delivering to
    // this activity.
    mPendingIntent = PendingIntent.getActivity(this,};

    // Setup a tech list for all NfcF tags
    mTechLists = new String[][] { new String[] { NfcF.class.getName() } };
}
项目:easypgp    文件:NfcActivity.java   
/**
 * @param activity
 *          The corresponding {@link Activity} requesting the foreground
 *          dispatch.
 * @param adapter
 *          The {@link NfcAdapter} used for the foreground dispatch.
 */
public static void setupForegrounddispatch(final Activity activity,NfcAdapter adapter) {
  final Intent intent = new Intent(activity.getApplicationContext(),activity.getClass());
  intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

  final PendingIntent pendingIntent = PendingIntent.getActivity(
      activity.getApplicationContext(),0);

  IntentFilter[] filters = new IntentFilter[1];
  String[][] techList = new String[][] {};

  // Notice that this is the same filter as in our manifest.
  filters[0] = new IntentFilter();
  filters[0].addAction(NfcAdapter.ACTION_NDEF_disCOVERED);
  filters[0].addCategory(Intent.CATEGORY_DEFAULT);
  try {
    filters[0].addDataType(MIME_PUBLIC_KEY);
    filters[0].addDataType(MIME_TEXT_PLAIN);
  } catch (MalformedMimeTypeException e) {
    throw new RuntimeException("Check your mime type.");
  }

  adapter
      .enableForegrounddispatch(activity,techList);
}
项目:informant-droid    文件:SampleMediaRouteProvider.java   
private static void addDataTypeUnchecked(IntentFilter filter,String type) {
    try {
        filter.addDataType(type);
    } catch (MalformedMimeTypeException ex) {
        throw new RuntimeException(ex);
    }
}
项目:RejsekortReader    文件:DumpRaw.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dump_raw);
    // Show the Up button in the action bar.
    setupActionBar();

    mAdapter = NfcAdapter.getDefaultAdapter(this);
       mPendingIntent = PendingIntent.getActivity(
               this,0);

       // Setup an intent filter for all MIME based dispatches
       IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_disCOVERED);
    try {
        ndef.addDataType("*/*");
    } catch (MalformedMimeTypeException e) {
        throw new RuntimeException("fail",e);
    }
    IntentFilter td = new IntentFilter(NfcAdapter.ACTION_TAG_disCOVERED);
    mFilters = new IntentFilter[] { ndef,td };

    // Setup a tech list for all NfcF tags
    mTechLists = new String[][] { 
            new String[] { 
                    /*NfcV.class.getName(),NfcF.class.getName(),*/ 
                    NfcA.class.getName(),//NfcB.class.getName() 
                    } 
            };

    txtRaw = (TextView) findViewById(R.id.txtRaw);
}
项目:nfc    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    findViewById(R.id.write_tag).setonClickListener(mTagWriter);
    mNote = ((EditText) findViewById(R.id.note));
    mNote.addTextChangedListener(mTextWatcher);

    // Handle all of our received NFC intents in this activity.
    mNfcPendingIntent = PendingIntent.getActivity(this,0);

    // Intent filters for reading a note from a tag or exchanging over p2p.
    IntentFilter ndefDetected = new IntentFilter(NfcAdapter.ACTION_NDEF_disCOVERED);
    try {
        ndefDetected.addDataType("text/plain");
    } catch (MalformedMimeTypeException e) {
        Log.d(TAG,"Failed to addDataType");
    }
    mNdefExchangeFilters = new IntentFilter[]{ndefDetected};

    // Intent filters for writing to a tag
    IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_disCOVERED);
    mWriteTagFilters = new IntentFilter[]{tagDetected};
}
项目:V.FlyoutTest    文件:SampleMediaRouteProvider.java   
private static void addDataTypeUnchecked(IntentFilter filter,String type) {
    try {
        filter.addDataType(type);
    } catch (MalformedMimeTypeException ex) {
        throw new RuntimeException(ex);
    }
}
项目:sana.mobile    文件:BaseRunner.java   
public IntentFilter buildFilter(){
    Log.i(TAG,"buildFilter()");
    IntentFilter filter = new IntentFilter(dispatchResponseReceiver.broADCAST_RESPONSE);
    filter.addDataScheme(Encounters.CONTENT_URI.getScheme());
    try {

        filter.addDataType(Encounters.CONTENT_ITEM_TYPE);
    } catch (MalformedMimeTypeException e) {

    }
    return filter;
}
项目:sana.mobile    文件:EncounterTaskList.java   
public IntentFilter buildFilter(){
    IntentFilter filter = new IntentFilter(Response.RESPONSE);
    try{
        filter.addDataType(EncounterTasks.CONTENT_TYPE);
        filter.addDataType(EncounterTasks.CONTENT_ITEM_TYPE);
        filter.addDataType(Subjects.CONTENT_TYPE);
    } catch (MalformedMimeTypeException e) {
    }
    return filter;
}
项目:droidNFCdemo    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mPendingIntent = PendingIntent.getActivity(this,0);

    IntentFilter ndef1 = new IntentFilter(NfcAdapter.ACTION_TECH_disCOVERED);
    //IntentFilter ndef2 = new IntentFilter(NfcAdapter.ACTION_TAG_disCOVERED);
    mFilters = new IntentFilter[] {
            ndef1,//ndef2,};

       try {
           ndef1.addDataType("*/*");
           //ndef2.addDataType("*/*");
       } catch (MalformedMimeTypeException e) {
           throw new RuntimeException("fail",e);
       }
       mAdapter = NfcAdapter.getDefaultAdapter(this);

       if (getIntent() != null){
        resolveIntent(getIntent());
       }

}
项目:flingtap-done    文件:UpdateService.java   
protected IntentFilter getIntentFilter() throws MalformedMimeTypeException {
    IntentFilter filter = new IntentFilter(Intent.ACTION_VIEW);
    filter.addDataScheme("http");
    filter.addDataAuthority("beta.leankeen.com",null);
    filter.addDataAuthority("www.leankeen.com",null);
    filter.addDataAuthority("www.flingtap.com",null);
    filter.addDataAuthority("market.android.com",null);

    return filter;
}
项目:andevconnfc    文件:MainActivity.java   
private void resetForegrounddispatcher() {

        nfcAdapter.disableForegrounddispatch(this);

        if (!readRtdOnly) {
            nfcAdapter.enableForegrounddispatch(this,nfcPendingIntent,null,null);
            Log.i(DEBUG_MAIN_ACTIVITY,"Listening for any type of tag scan");
        } else {
            IntentFilter rtdFilter = new IntentFilter(
                    NfcAdapter.ACTION_NDEF_disCOVERED);
            try {
                rtdFilter.addDataType("text/plain");
            } catch (MalformedMimeTypeException e) {
                // Todo Auto-generated catch block
                e.printstacktrace();
            }

            IntentFilter[] filters = new IntentFilter[] { rtdFilter };
            nfcAdapter.enableForegrounddispatch(this,null);

            Log.i(DEBUG_MAIN_ACTIVITY,"Listening only for an RTD_TEXT NDEF record on a tag");

        }
    }
项目:GameLivreNFC    文件:KeynoteActivity.java   
private void prepareNFC() {
    IntentFilter ndefDetected = new IntentFilter(NfcAdapter.ACTION_NDEF_disCOVERED);

    try {
        ndefDetected.addDataType("application/vnd.serpro.nfcevents");
    } catch (MalformedMimeTypeException e) {
    }
    mNdefExchangeFilters = new IntentFilter[] { ndefDetected };

    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    mNfcPendingIntent = PendingIntent.getActivity(this,0);
}
项目:timelapse-sony    文件:NFCHandler.java   
public static IntentFilter[] getIntentFilterarray() {
    IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_disCOVERED);
    try {
        ndef.addDataType(SONY_MIME_TYPE);
    } catch (MalformedMimeTypeException e) {
        throw new RuntimeException("fail",e);
    }
    return new IntentFilter[]{ndef};
}
项目:geoPingProject    文件:GeoTrackOverlay.java   
public GeoTrackOverlay(final Context ctx,final MapView mapView,final ResourceProxy pResourceProxy,LoaderManager loaderManager,Person person,long timeInMs,GeotrackLastAddedListener geotrackLastAddedListener) {
super(pResourceProxy);
GEOTRACK_LIST_LOADER = R.id.config_id_geotrack_list_loader + (int) person.id + 1000;
// person.id;
Log.d(TAG,"#################################");
Log.d(TAG,"### Create " + person);
Log.d(TAG,"#################################");
this.context = ctx;
this.person = person;
this.loaderManager = loaderManager;
this.mapView = mapView;
this.mMapController = mapView.getController();

setDaterange(timeInMs);
// Service
this.sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
enableThreadExecutors();
if (Geocoder.isPresent()) {
    this.geocoder = new Geocoder(context,Locale.getDefault());
} else {
    this.geocoder = null;
    Log.w(TAG,"The Geocoder is not Present");
}
// Listener
this.geotrackLastAddedListener = geotrackLastAddedListener;
mStatusReceiver = new StatusReceiver();
try {
    mStatusReceiverIntentFilter = new IntentFilter(Intents.ACTION_NEW_GEOTRACK_INSERTED,GeoTrackerProvider.Constants.ITEM_MIME_TYPE);
} catch (MalformedMimeTypeException e) {
    Log.e(TAG,"Coud not create Intenfilter for mStatusReceiver : " + e.getMessage(),e);

}

// Init
initDirectionPaint(person.color);
onResume();

}
项目:Felix-on-android    文件:Foregrounddispatch.java   
@Override
public void onCreate(Bundle savedState) {
    super.onCreate(savedState);

    setContentView(R.layout.foreground_dispatch);
    mText = (TextView) findViewById(R.id.text);
    mText.setText("Scan a tag");

    mAdapter = NfcAdapter.getDefaultAdapter(this);

    // Create a generic PendingIntent that will be deliver to this activity. The NFC stack
    // will fill in the intent with the details of the discovered tag before delivering to
    // this activity.
    mPendingIntent = PendingIntent.getActivity(this,};

    // Setup a tech list for all NfcF tags
    mTechLists = new String[][] { new String[] { NfcF.class.getName() } };
}
项目:MEng    文件:Foregrounddispatch.java   
@Override
public void onCreate(Bundle savedState) {
    super.onCreate(savedState);

    setContentView(R.layout.foreground_dispatch);
    mText = (TextView) findViewById(R.id.text);
    mText.setText("Scan a tag");

    mAdapter = NfcAdapter.getDefaultAdapter(this);

    // Create a generic PendingIntent that will be deliver to this activity. The NFC stack
    // will fill in the intent with the details of the discovered tag before delivering to
    // this activity.
    mPendingIntent = PendingIntent.getActivity(this,};

    // Setup a tech list for all NfcF tags
    mTechLists = new String[][] { new String[] { NfcF.class.getName() } };
}

今天的关于MalformedByteSequenceException:2字节UTF-8序列的无效字节22字节的utf-8序列的字节2无效的分享已经结束,谢谢您的关注,如果想了解更多关于.impl.io.MalformedByteSequenceException: 2 字节的 UTF-8 序列、2字节的UTF-8序列的字节2无效 解决方案、Activiti:MalformedByteSequenceException: 3 字节的 UTF-8 序列的字节 3 无效。、android.content.IntentFilter.MalformedMimeTypeException的实例源码的相关知识,请在本站进行查询。

本文标签: