This morning completed the business data import into the mobile phone, can display Chinese characters.

Source: Internet
Author: User

This morning completed the business data import into the mobile phone, can display Chinese characters.

Mainactivity.java file contents are as follows

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"; Saved database file name
public static final String package_name = "Com.strongdady.qrscan";//application's package name
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 ();//Assuming there is no this folder, create
}
Else
{
Mtextmessage.append ("Inside Copydbfile =|" +mydatapath.tostring () + "|existed 2018_5-21!");
}
String dbfile=mydatapath+ "/" +db_name;
if (! ( New file (DBFile). Exists ()) {//infer if the database file exists, run import if it does not exist, or open the database directly

if (true) {//infer that the database file exists, run the import if it does not exist, or open the database directly
InputStream is =getresources (). Openrawresource (R.raw.device); Databases that you want to import
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 number" +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:" +device_name+owner+register_date);

}
Else
{
Super.onactivityresult (Requestcode, ResultCode, data);
Return
}

}
}

This morning completed the business data import into the mobile phone, can display Chinese characters.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.