今天上午完成了业务数据导入到手机,能显示汉字了。

Posted strongdady

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了今天上午完成了业务数据导入到手机,能显示汉字了。相关的知识,希望对你有一定的参考价值。

今天上午完成了业务数据导入到手机,能显示汉字了。

MainActivity.java 文件内容如下

package com.strongdady.qrscan;

import java.util.Arrays;
import java.util.List;




import java.io.File;

import java.io.InputStream;

import java.io.FileOutputStream;

import android.database.sqlite.SQLiteDatabase;
import android.database.Cursor;

import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;

import android.widget.Toast;
import android.content.Intent;



import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.widget.TextView;


import static android.os.Environment.getExternalStorageDirectory;


public class MainActivity extends AppCompatActivity {

private final int BUFFER_SIZE = 400000;
public static final String DB_NAME = "device.db"; // 保存的数据库文件名称
public static final String PACKAGE_NAME = "com.strongdady.qrscan";// 应用的包名
//public static final String DB_PATH = "/data"droid.os.Environment.getDataDirectory().getAbsolutePath()+"/"
public static final String DB_PATH =getExternalStorageDirectory()+"/data";

String device_no = "";
String owner="";
String register_date = "";
String device_name = "";
String sqlString="";
SQLiteDatabase db=null;
Cursor cursor;

private TextView mTextMessage;

private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {



public void copyDBFile()
{
mTextMessage.append(DB_PATH);
try {
File myDataPath = new File(DB_PATH+"/device_db");
if (!myDataPath.exists())
{
mTextMessage.append("inside copydbfile 20180521=|"+myDataPath.toString()+"|enddbfile");
myDataPath.mkdirs();// 假设没有这个文件夹,则创建
}
else
{
mTextMessage.append("inside copydbfile =|"+myDataPath.toString()+"|existed 2018_5-21!");
}
String dbfile=myDataPath+"/"+DB_NAME;
// if (!(new File(dbfile).exists())) {// 推断数据库文件是否存在,若不存在则运行导入,否则直接打开数据库

if (true) {// 推断数据库文件是否存在,若不存在则运行导入,否则直接打开数据库
InputStream is =getResources().openRawResource(R.raw.device); // 欲导入的数据库
FileOutputStream fos = new FileOutputStream(dbfile);
byte[] buffer = new byte[BUFFER_SIZE];
int count = 0;
while ((count = is.read(buffer)) > 0) {
fos.write(buffer, 0, count);
}
fos.close();
is.close();
}
db = SQLiteDatabase.openOrCreateDatabase(dbfile,null);

} catch (Exception e)
{
mTextMessage.append(e.toString());
}
}


@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {

switch (item.getItemId()) {
case R.id.navigation_home:
mTextMessage.setText(R.string.title_home);

IntentIntegrator integrator=new IntentIntegrator(MainActivity.this);

//List<String> oDesiredFormats = Arrays.asList("UPC_A,UPC_E,EAN_13,EAN_8,RSS_14,RSS_EXPANDED,CODE_39,CODE_93,CODE_128,ITF,CODABAR,QR_CODE,DATA_MATRIX,PDF_417".split(","));
List<String> oDesiredFormats = Arrays.asList("PDF_417,UPC_A,UPC_E,EAN_13,EAN_8,RSS_14,RSS_EXPANDED,CODE_39,CODE_93,CODE_128,ITF,CODABAR,QR_CODE,DATA_MATRIX".split(","));

integrator.setPrompt("scanning .....");
integrator.initiateScan(oDesiredFormats);

return true;


case R.id.navigation_dashboard:
mTextMessage.setText(R.string.title_dashboard);

copyDBFile();

mTextMessage.append(" after open database ");
if(db!=null)
mTextMessage.append(" db not null");
else
mTextMessage.append(" db is null!!");


try {
sqlString="SELECT * FROM device where device_no=‘1010-2012-000582‘";
cursor = db.rawQuery(sqlString, null);
}catch (Exception e)
{
mTextMessage.append("exceipion e"+e.toString());
}
owner="init001";


while (cursor.moveToNext()) {
mTextMessage.append("!!!!!!!!!!!!");
device_name = cursor.getString(cursor.getColumnIndex("device_name"));
owner = cursor.getString(cursor.getColumnIndex("owner"));
register_date=cursor.getString(cursor.getColumnIndex("register_date"));
mTextMessage.append("+here+");
}

mTextMessage.append("after cursor!!!"+"sqlstring:"+sqlString);
mTextMessage.append("owner:"+owner);
return true;

case R.id.navigation_notifications:
mTextMessage.setText(R.string.title_notifications);
return true;
}
return false;
}
};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mTextMessage = (TextView) findViewById(R.id.message);
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);

}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if (scanResult != null) {


mTextMessage.setText("设备编号 "+device_no);

Toast.makeText(this, device_no, Toast.LENGTH_LONG).show();
//String dbOpenString="/data/data/com.strongdady.qrscan/device.db";
//String dbOpenString=android.os.Environment.getDataDirectory().getAbsolutePath()+"device.db";

if (db==null)
mTextMessage.append("db is null");

else
mTextMessage.append("db is ok!");

cursor = db.rawQuery("SELECT * FROM device where device_no = ‘1010-2012-000582‘", null);


while (cursor.moveToNext()) {
device_name = cursor.getString(cursor.getColumnIndex("device_name"));
owner = cursor.getString(cursor.getColumnIndex("owner"));
register_date=cursor.getString(cursor.getColumnIndex("register_date"));
}

db.close();
mTextMessage.append("设备名称:"+device_name+owner+register_date);

}
else
{
//super.onActivityResult(requestCode, resultCode, data);
return;
}

}
}

以上是关于今天上午完成了业务数据导入到手机,能显示汉字了。的主要内容,如果未能解决你的问题,请参考以下文章

jira 如何导入数据!

编程题

急!今天上午手机刚卸载了有道笔记,又重新下载了,打开之后,今年的资料全部消失?怎么办呢?能否恢复?

百思不得姐(第二天)

为啥navicat导入excel表之后汉字变成了问号?

面向对象程序设计编程题完善1.0