日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

esc pos java打印图片_android 调用蓝牙打印机(ESC/POS 热敏打印机)打印小票和图片...

發(fā)布時(shí)間:2023/11/27 生活经验 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 esc pos java打印图片_android 调用蓝牙打印机(ESC/POS 热敏打印机)打印小票和图片... 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

【實(shí)例簡介】其中對(duì)藍(lán)牙配對(duì)和連接打印功能進(jìn)行了封裝,可以快速實(shí)現(xiàn)藍(lán)牙打印功能

【實(shí)例截圖】

【核心代碼】

package com.xmwdkk.boothprint;

import android.Manifest;

import android.bluetooth.BluetoothAdapter;

import android.content.Intent;

import android.os.Build;

import android.os.Bundle;

import android.text.TextUtils;

import android.view.View;

import android.widget.TextView;

import com.xmwdkk.boothprint.base.AppInfo;

import com.xmwdkk.boothprint.bt.BluetoothActivity;

import com.xmwdkk.boothprint.print.PrintMsgEvent;

import com.xmwdkk.boothprint.print.PrintUtil;

import com.xmwdkk.boothprint.print.PrinterMsgType;

import com.xmwdkk.boothprint.util.ToastUtil;

import de.greenrobot.event.EventBus;

/***

* Created by liugruirong on 2017/8/3.

*/

public class MainActivity extends BluetoothActivity implements View.OnClickListener {

TextView tv_bluename;

TextView tv_blueadress;

boolean mBtEnable = true;

int PERMISSION_REQUEST_COARSE_LOCATION=2;

/**

* bluetooth adapter

*/

BluetoothAdapter mAdapter;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

tv_bluename =findViewById(R.id.tv_bluename);

tv_blueadress =findViewById(R.id.tv_blueadress);

findViewById(R.id.button4).setOnClickListener(this);

findViewById(R.id.button5).setOnClickListener(this);

findViewById(R.id.button6).setOnClickListener(this);

findViewById(R.id.button).setOnClickListener(this);

//6.0以上的手機(jī)要地理位置權(quán)限

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, PERMISSION_REQUEST_COARSE_LOCATION);

}

EventBus.getDefault().register(MainActivity.this);

}

@Override

protected void onStart() {

super.onStart();

BluetoothController.init(this);

}

@Override

public void btStatusChanged(Intent intent) {

super.btStatusChanged(intent);

BluetoothController.init(this);

}

@Override

public void onClick(View view) {

switch (view.getId()){

case R.id.button4:

startActivity(new Intent(MainActivity.this,SearchBluetoothActivity.class));

break;

case R.id.button5:

if (TextUtils.isEmpty(AppInfo.btAddress)){

ToastUtil.showToast(MainActivity.this,"請(qǐng)連接藍(lán)牙...");

startActivity(new Intent(MainActivity.this,SearchBluetoothActivity.class));

}else {

if ( mAdapter.getState()==BluetoothAdapter.STATE_OFF ){//藍(lán)牙被關(guān)閉時(shí)強(qiáng)制打開

mAdapter.enable();

ToastUtil.showToast(MainActivity.this,"藍(lán)牙被關(guān)閉請(qǐng)打開...");

}else {

ToastUtil.showToast(MainActivity.this,"打印測試...");

Intent intent = new Intent(getApplicationContext(), BtService.class);

intent.setAction(PrintUtil.ACTION_PRINT_TEST);

startService(intent);

}

}

break;

case R.id.button6:

if (TextUtils.isEmpty(AppInfo.btAddress)){

ToastUtil.showToast(MainActivity.this,"請(qǐng)連接藍(lán)牙...");

startActivity(new Intent(MainActivity.this,SearchBluetoothActivity.class));

}else {

ToastUtil.showToast(MainActivity.this,"打印測試...");

Intent intent2 = new Intent(getApplicationContext(), BtService.class);

intent2.setAction(PrintUtil.ACTION_PRINT_TEST_TWO);

startService(intent2);

}

case R.id.button:

if (TextUtils.isEmpty(AppInfo.btAddress)){

ToastUtil.showToast(MainActivity.this,"請(qǐng)連接藍(lán)牙...");

startActivity(new Intent(MainActivity.this,SearchBluetoothActivity.class));

}else {

ToastUtil.showToast(MainActivity.this,"打印圖片...");

Intent intent2 = new Intent(getApplicationContext(), BtService.class);

intent2.setAction(PrintUtil.ACTION_PRINT_BITMAP);

startService(intent2);

}

// startActivity(new Intent(MainActivity.this,TextActivity.class));

break;

}

}

/**

* handle printer message

*

* @param event print msg event

*/

public void onEventMainThread(PrintMsgEvent event) {

if (event.type == PrinterMsgType.MESSAGE_TOAST) {

ToastUtil.showToast(MainActivity.this,event.msg);

}

}

@Override

protected void onDestroy() {

super.onDestroy();

EventBus.getDefault().register(MainActivity.this);

}

}

總結(jié)

以上是生活随笔為你收集整理的esc pos java打印图片_android 调用蓝牙打印机(ESC/POS 热敏打印机)打印小票和图片...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。