• 蓝牙模块连接后出现ANR,日志记录


    11-25 16:29:48.433 14507-14561/myapplication.com.myblue W/MALI: glDrawArrays:714: [MALI] glDrawArrays takes more than 5ms here. Total elapse time(us): 10221
    11-25 16:29:58.204 14507-14507/myapplication.com.myblue W/BluetoothAdapter: getBluetoothService() called with no BluetoothManagerCallback
                                                                                
                                                                                [ 11-25 16:29:58.206 17183:17202 I/         ]
                                                                                [JSR82][JBT] JBT jbt_session_connect_req
                                                                                
                                                                                [ 11-25 16:29:58.206 17183:17202 I/         ]
                                                                                [session] session_mutex_lock() +++, mutex: 0xeec301a8
                                                                                
                                                                                [ 11-25 16:29:58.206 17183:17202 I/         ]
                                                                                [session] session_mutex_lock() ---
    11-25 16:30:01.486 14507-14507/myapplication.com.myblue I/System.out: **android.bluetooth.BluetoothInputStream@3c5c4bb1
    11-25 16:30:40.726 14507-14528/myapplication.com.myblue I/ViewRootImpl: ANR Key Analyze: No Key event currently.
    11-25 16:30:40.726 14507-14528/myapplication.com.myblue I/ViewRootImpl: ANR Key Analyze: Previeous Event null,finish at 1970-01-01 08:00:00.000
    11-25 16:30:40.726 14507-14528/myapplication.com.myblue I/ViewRootImpl: ANR Motion Analyze: No motion event currently.
    11-25 16:30:40.727 14507-14528/myapplication.com.myblue I/ViewRootImpl: ANR Motion Analyze: Previeous Event MotionEvent { action=ACTION_UP, id[0]=0, x[0]=1030.0463, y[0]=161.91566, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=2030905, downTime=2030754, deviceId=3, source=0x1002 },finish at 2016-11-25 16:29:58.200
    11-25 16:30:40.884 14507-14580/myapplication.com.myblue W/Binder: Caught a RuntimeException from the binder stub implementation.
                                                                      java.lang.NullPointerException: Attempt to invoke interface method 'android.os.IBinder com.mediatek.anrappmanager.IFrameworks.serviceManagerGetService(java.lang.String)' on a null object reference
                                                                          at com.mediatek.anrappmanager.ANRManagerNative$1.b(SourceFile:77)
                                                                          at com.mediatek.anrappmanager.ANRManagerNative$1.c(SourceFile:75)
                                                                          at com.mediatek.anrappmanager.ANRManagerNative$a.get(SourceFile:97)
                                                                          at com.mediatek.anrappmanager.ANRManagerNative.getDefault(SourceFile:35)
                                                                          at com.mediatek.anrappmanager.ANRAppManager.dumpMessageHistory(SourceFile:59)
                                                                          at android.app.ActivityThread$ApplicationThread.dumpMessageHistory(ActivityThread.java:1315)
                                                                          at android.app.ApplicationThreadNative.onTransact(ApplicationThreadNative.java:687)
                                                                          at android.os.Binder.execTransact(Binder.java:454)
    11-25 16:30:40.884 14507-14580/myapplication.com.myblue W/System.err: java.lang.NullPointerException: Attempt to invoke interface method 'android.os.IBinder com.mediatek.anrappmanager.IFrameworks.serviceManagerGetService(java.lang.String)' on a null object reference
    11-25 16:30:40.884 14507-14580/myapplication.com.myblue W/System.err:     at com.mediatek.anrappmanager.ANRManagerNative$1.b(SourceFile:77)
    11-25 16:30:40.884 14507-14580/myapplication.com.myblue W/System.err:     at com.mediatek.anrappmanager.ANRManagerNative$1.c(SourceFile:75)
    11-25 16:30:40.884 14507-14580/myapplication.com.myblue W/System.err:     at com.mediatek.anrappmanager.ANRManagerNative$a.get(SourceFile:97)
    11-25 16:30:40.884 14507-14580/myapplication.com.myblue W/System.err:     at com.mediatek.anrappmanager.ANRManagerNative.getDefault(SourceFile:35)
    11-25 16:30:40.884 14507-14580/myapplication.com.myblue W/System.err:     at com.mediatek.anrappmanager.ANRAppManager.dumpMessageHistory(SourceFile:59)
    11-25 16:30:40.885 14507-14580/myapplication.com.myblue W/System.err:     at android.app.ActivityThread$ApplicationThread.dumpMessageHistory(ActivityThread.java:1315)
    11-25 16:30:40.885 14507-14580/myapplication.com.myblue W/System.err:     at android.app.ApplicationThreadNative.onTransact(ApplicationThreadNative.java:687)
    11-25 16:30:40.885 14507-14580/myapplication.com.myblue W/System.err:     at android.os.Binder.execTransact(Binder.java:454)
    11-25 16:30:43.719 17826-17826/myapplication.com.myblue I/ActivityThread: Switching default density from 480 to 380
    11-25 16:30:43.745 17826-17826/myapplication.com.myblue W/linker: /system/lib64/libfilterUtils.so: unused DT entry: type 0x6ffffffe arg 0x808
    11-25 16:30:43.745 17826-17826/myapplication.com.myblue W/linker: /system/lib64/libfilterUtils.so: unused DT entry: type 0x6fffffff arg 0x2
    11-25 16:30:44.159 17826-17859/myapplication.com.myblue E/GED: Failed to get GED Log Buf, err(0)
    11-25 16:30:44.159 17826-17859/myapplication.com.myblue I/OpenGLRenderer: Initialized EGL, version 1.4
    11-25 16:30:44.227 17826-17859/myapplication.com.myblue W/MALI: glDrawArrays:714: [MALI] glDrawArrays takes more than 5ms here. Total elapse time(us): 13735

     2.代码:

    package myapplication.com.myblue.activity;
    
    import android.bluetooth.BluetoothAdapter;
    import android.bluetooth.BluetoothDevice;
    import android.bluetooth.BluetoothSocket;
    import android.content.Intent;
    import android.os.Handler;
    import android.os.Message;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.ImageView;
    import android.widget.TextView;
    
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.text.SimpleDateFormat;
    import java.util.Timer;
    import java.util.TimerTask;
    import java.util.UUID;
    
    import myapplication.com.myblue.R;
    
    public class Zhuye_Activity extends AppCompatActivity {
    
        TextView textView1,textView_time,textView_lianjie;
        ImageView imageView1;
        EditText edittext;
        Button button_send;
        private BluetoothSocket btSocket = null;
        private OutputStream outStream = null;
        private InputStream inStream = null;
        private BluetoothAdapter BA;
        private  String address = "";
        private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_zhuye);
            Intent intent=getIntent();
            String mac=intent.getStringExtra("mac");
            String []a=mac.split("\*");
            address=a[1].trim();
    
            initView();
            textView1.setText(mac);
        }
        public void initView(){
            BA = BluetoothAdapter.getDefaultAdapter();
            BA.enable();
            button_send= (Button) findViewById(R.id.button_send);
            edittext= (EditText) findViewById(R.id.edittext);
            textView1= (TextView) findViewById(R.id.textview1);
            textView_time= (TextView) findViewById(R.id.textView_time);
            SimpleDateFormat    sDateFormat   = new SimpleDateFormat("yyyy-MM-dd    hh:mm:ss");
            String    date    =    sDateFormat.format(new  java.util.Date());
            textView_time.setText(date);
            imageView1= (ImageView) findViewById(R.id.imageView1);
            textView_lianjie= (TextView) findViewById(R.id.textView_lianjie);
            textView_lianjie.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    connect();
                }
            });
            imageView1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    finish();
                }
            });
            button_send.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String s=edittext.getText().toString().trim();
                    byte[] a=s.getBytes();
                    try {
                        outStream.write(a);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
    
                }
            });
    
            /**
             * 创建定时器,1000ms更新一次时间
             * **/
         //   Timer timer = new Timer();
           // timer.schedule(timerTask, 0, 10000);
        }
    
        /**
        * 连接蓝牙设备
        *
        * ***/
    
        public void connect(){
    
            BluetoothDevice device = BA.getRemoteDevice(address);
            try {
                btSocket = device.createRfcommSocketToServiceRecord(MY_UUID);
            } catch (IOException e) {
                System.out.println("**109"+e.toString());
    
            }
           // BA.cancelDiscovery();
    
                    try {
                        btSocket.connect();
                        outStream = btSocket.getOutputStream();
                       outStream.write(0x61);
                      outStream.write(0x41);
                        inStream = btSocket.getInputStream();
                        System.out.println("**"+inStream.toString());
                       System.out.println("**"+inStream.read());
                       int x = inStream.read();
                       outStream.write(x + 1);
                    } catch (IOException e) {
                        System.out.println("**124"+e.toString());
                    }
    
    
    
            try {
                btSocket.close();
            } catch (Exception e2) {
    
                // Log .e(TAG,"ON RESUME: Unable to close socket during connection failure", e2);
            }
        }
    //    public void connect(){
    //        BA = BluetoothAdapter.getDefaultAdapter();
    //        BluetoothDevice device = BA.getRemoteDevice(address);
    //      // pairedDevices = BA.getBondedDevices();
    //        try {
    //
    //            btSocket = device.createRfcommSocketToServiceRecord(MY_UUID);
    //
    //        } catch (IOException e) {
    //
    //            Log.d("T109",e.toString());
    //        }
    //     //  BA.cancelDiscovery();
    //        try {
    //
    //       //     new Thread(new Runnable() {
    //            //    @Override
    //           //     public void run() {
    //                  //  try {
    //                        btSocket.connect();
    //                        outStream = btSocket.getOutputStream();
    //                        inStream = btSocket.getInputStream();
    //                  //  } catch (IOException e) {
    //                      //  e.printStackTrace();
    //                  //  }
    //            //    }
    //          //  }).start();
    //
    ////            outStream = btSocket.getOutputStream();
    ////            String s="guoxiwang";
    ////            byte by[]=s.getBytes();
    ////            outStream.write(12345566);
    ////            outStream.write(by);
    ////
    ////            outStream.write(0x61);
    ////            outStream.write(0x41);
    ////            inStream = btSocket.getInputStream();
    ////            System.out.println("**"+inStream.toString());
    ////            System.out.println("**"+inStream.read());
    ////            int x = inStream.read();
    ////            outStream.write(x + 1);
    //
    //        } catch (Exception e) {
    //        }
    //        try {
    //            btSocket.close();
    //        } catch (IOException e2) {
    //
    //            // Log .e(TAG,"ON RESUME: Unable to close socket during connection failure", e2);
    //        }
    //    }
        /***
         * handler+TimerTask 实现更新时间
         *
         * ***/
        Handler handler=new Handler(){
            public void handleMessage(android.os.Message msg) {
                switch (msg.what) {
                    case 200:
                        SimpleDateFormat sDateFormat   = new SimpleDateFormat("yyyy-MM-dd    hh:mm:ss");
                        String    date    =    sDateFormat.format(new  java.util.Date());
                        textView_time.setText(date);
                        break;
                }
    
            }
        };
        TimerTask timerTask = new TimerTask() {
    
            @Override
            public void run() {
                Message message = new Message();
                message.what = 200;
                // message.obj = view;
                handler.sendMessage(message);
            }
        };
    
    
    
    }
    今天多一点积累,明天少一分烦恼
  • 相关阅读:
    从零搭建一个IdentityServer——资源与访问控制
    职 工 养 老 保 险 转 移—陕西省外转入
    EurekaUser-Redis
    EurekaUser-返回类型和全局异常
    C# 入门实战系列文章
    Python入门实战系列文章
    Python基础之Scrapy简介
    Python办公自动化之文件合并
    Python基础之shutil及zipfile模块
    Python基础之os模块简介
  • 原文地址:https://www.cnblogs.com/galibujianbusana/p/6100620.html
Copyright © 2020-2023  润新知