Monthly Archives: October 2017

Copy database from assets to databases folder on Android

ContextWrapper cw =new ContextWrapper(getApplicationContext());
DB_PATH =cw.getFilesDir().getAbsolutePath()+ "/databases/";
private void copyDataBase()
    {
        Log.i("Database",
                "New database is being copied to device!");
        byte[] buffer = new byte[1024];
        OutputStream myOutput = null;
        int length;
        // Open your local db as the input stream
        InputStream myInput = null;
        try
        {
            myInput =myContext.getAssets().open(DB_NAME);
            // transfer bytes from the inputfile to the
            // outputfile
            myOutput =new FileOutputStream(DB_PATH+ DB_NAME);
            while((length = myInput.read(buffer)) > 0)
            {
                myOutput.write(buffer, 0, length);
            }
            myOutput.close();
            myOutput.flush();
            myInput.close();
            Log.i("Database",
                    "New database has been copied to device!");


        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
    }

References
https://stackoverflow.com/questions/18805874/copy-database-from-assets-to-databases-folder

Install Realm Object Server on Ubuntu 16.04

# Setup Realm's PackageCloud repository
curl -s https://packagecloud.io/install/repositories/realm/realm/script.deb.sh | sudo bash

# Update the repositories
sudo apt-get update

# Install the Realm Object Server
sudo apt-get install realm-object-server-developer

# Enable and start the service
sudo systemctl enable realm-object-server
sudo systemctl start realm-object-server

Realm Dashboard
http://localhost:9080/

Check firewall rules for external access to the Realm Dashboard

sudo ufw allow 9080/tcp
sudo ufw reload

References
https://realm.io/docs/get-started/installation/linux/

Data Browser for ObjectBox

// ObjectBox browser dependencies must be set before applying ObjectBox plugin so it does not add objectbox-android
// (would result in two conflicting versions, e.g. "Duplicate files copied in APK lib/armeabi-v7a/libobjectbox.so").
dependencies {
    debugCompile "io.objectbox:objectbox-android-objectbrowser:$objectboxVersion"
    releaseCompile "io.objectbox:objectbox-android:$objectboxVersion"
}
<uses-permission android:name="android.permission.INTERNET" />
if (BuildConfig.DEBUG) {
     new AndroidObjectBrowser(boxStore).start(this);
}
adb forward tcp:8090 tcp:8090

References
http://objectbox.io/objectbox-1-1-introduces-data-browser/

How to enable Annotation Processor in Android Studio 2.3

Close the project and find the option under File -> Other Settings -> Default Settings -> Build, Execution, Deployment -> Compiler -> Annotation Processors

Exit from Android Studio and edit the file /.idea/compiler.xml.
You should find:

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
    <component name="CompilerConfiguration">
        ...
        <annotationProcessing>
            <profile default="true" name="Default" enabled="false">
                <processorPath useClasspath="true" />
            </profile>
        </annotationProcessing>
    </component>
</project>

You should set enabled to true and the boring message disappears!

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
    <component name="CompilerConfiguration">
        ...
        <annotationProcessing>
            <!-- This is the line where to set enabled to true  -->
            <profile default="true" name="Default" enabled="true">
                <processorPath useClasspath="true" />
            </profile>
        </annotationProcessing>
    </component>
</project>

References
https://stackoverflow.com/questions/42692525/how-to-enable-annotation-processor-in-android-studio-2-3

Install LAMP server with Apache, PHP 7, and MySQL on Ubuntu 16.04

apt-get -y install mysql-server mysql-client
mysql_secure_installation
apt-get -y install apache2
apt-get -y install php7.0 libapache2-mod-php7.0
systemctl restart apache2
apt-get -y install php7.0-mysql php7.0-curl php7.0-gd php7.0-intl php-pear php-imagick php7.0-imap php7.0-mcrypt php-memcache  php7.0-pspell php7.0-recode php7.0-sqlite3 php7.0-tidy php7.0-xmlrpc php7.0-xsl php7.0-mbstring php-gettext
systemctl restart apache2

Enable the SSL website in apache

a2enmod ssl
a2ensite default-ssl
systemctl restart apache2

Get a free SSL Certificate from Let’s Encrypt

apt-get -y install python-letsencrypt-apache

Before we can start to create the SSL cert, set the domain name in the vhost configuration file. Open the default vhost file with an editor:

nano /etc/apache2/sites-available/000-default.conf

and add the line:

ServerName example.com
letsencrypt --apache -d example.com

Let’s encrypt Auto Renewal

crontab -e
0 1 * * * /usr/bin/letsencrypt renew &> /dev/null

References
https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-on-ubuntu-16-04-lamp/