Slatedroid info

Everything about android tablet pc [slatedroid]

Android SDK tutorial for beginners

Posted by wicked August - 18 - 2015 - Tuesday Comments Off

Android SDK Download

Android is the world’s most used mobile operating system, so it is essential that there is an easy way to develop apps for it.  This is where the Android SDK comes in. The SDK, which now comes as part of Android Studio and includes sample code and the emulator, makes it easier than ever to develop for Android. So, let’s get started.

What is the Android SDK?

SDK Manager

The Android SDK is a software development kit that includes all the necessary libraries and files for developers to make apps for Android. The kit also includes sample code with working applications, and the Android Virtual Device Manager, which lets you test your app on any version of Android (or Android Wear) that you want.

There are different components that can be downloaded, including platform-tools and build-tools.

  • Platform-tools are used to support new and existing features of Android, including the Android Debugging Bridge, bmgr and logcat. The Android Debugging Bridge (ADB) can be used to see what is causing errors and what processes are running as well as other things. bmgr is a tool used to manage the backup manager on an Android device with an API level of 8 or higher. It can be accessed by using the ADB.
  • Build-tools are made to work with the Platform-tools but can be updated independently if needed. These include JOBB, ProGuard and zipalign. JOBB allows you to build encrypted and unencrypted APK expansions in OBB format. ProGuard is able to shrink and secure your app by removing unused items, renaming classes and the like, this makes it harder for people to reverse-engineer your app and it makes the overall size smaller which is also a bonus. Zipalign optimizes .apk files to start in a certain alignment relative to the start of a file.
  • The SDK-tools are required and are used no matter what version of Android you develop for, these include: build-tools, debugging-tools and image-tools along with others.
  • The Android Debugging Bridge (ADB) and fastboot are also included in case you ever need to get your device out of a jam as well. Fastboot can be used to flash or wipe partitions to your device in case something happens, this is very easy to do. The ADB can be used to troubleshoot issues with your device and apps.

What makes the SDK special is that everything you could ever need or want is just a few clicks away, and with Google’s excellent developer page, anything is possible. Updating is a breeze too, if an update is available, the SDK will let you know when you launch the SDK Manager. This is a helpful way to make sure everything is up to date as well as check to see if there are any previews to download and mess around with.

How to use the samples provided

Google provides some very helpful samples, if used correctly. Samples can be found in the SDK folder under “samples” then under the Android version you want to take the sample from. Android Wear samples have an extra subfolder known as “wearable”. In these samples Google provides basic outlines for how the user interface should look for that version of Android and other new API changes.

When the watch face API came out, Google added a great example on how to use a classic ticking second hand watch face and a mechanical watch imitating sweeping second hand watch face. You can learn a lot by using the samples and the official documentation that Google provides. You can run the examples using the AVD Manager and modify the code however you like before using the same techniques in your own app.

The samples covers areas such as connectivity, including basic networking and Bluetooth; gestures, including gesture detection and multi-touch; and the user interface, including ActionBars, Notifications, transitions, swiping and Immersive mode.

What is the AVD Manager and how to use it

AVD Madness

The Android Virtual Device Manager is a very special entity when it comes to developing apps and the Android SDK. The AVD Manager lets you create virtual Android and Android Wear devices that you can run your apps on. These virtual devices are stripped down versions of Android that can be configured to any screen size, resolution and even type of processor including ARM, MIPS and x86.

In the last year, Google and Intel have made it a lot easier to run an AVD by using Intel’s Hardware Accelerated Execution Manager (HAXM) which enables the AVD to run in “Fast virt mode”. This makes for a very smooth virtual environment rivaling an actual Android device. The only downside is that there is no official way for two AVDs to communicate with each other. For example, you can’t have an Android phone connect with an Android Wear device if both are AVDs. However, you can connect your real device to an AVD wear device.

How the SDK and Android Studio tie together

Android Studio is in a league its own, and getting to know its ins and outs is a must, Gary Sims explains how to writing your first Android app using Android Studio. Android Studio makes accessing the SDK and AVD Manager a breeze. The icons to access both are located on the top middle toolbar. Having the Android SDK integrated into Android Studio is a huge plus when it comes to productivity. For example, the Android Debugging Bridge works beautifully with Android Studio and the AVD Manager. If you were to create a Android Wear app that requires the connection of a phone for data you could connect your phone and start an AVD of a wear device, connect the two and see exactly what is happening on each simultaneously. This is something that you will find hard to live without after you have used it a few times.

Android Developer Newsletter

Do you want to know more? Subscribe to our Android Developer Newsletter. Just type in your email address below to get all the top developer news, tips & links once a week in your inbox:

PS. No spam, ever. Your email address will only ever be used for Android Dev Weekly.

Wrap-up

The Android SDK is a very powerful tool for creating simple apps to complex games. The SDK, AVD Manager and Android Studio work wonderfully together. Using the samples and documentation provided by Google anything is possible. It has never been easier to develop for Android. So why not start? You can pick up the Android SDK here.

Google shows off Android M’s Auto Backup for Apps function in video

Posted by wicked July - 30 - 2015 - Thursday Comments Off

Google_Auto-Backup_for-Apps_Android-M

One of the great things about flashing a custom Rom on your Android device is being able to backup and restore your apps via the custom recovery or by using an app such as Titanium Backup, it’s especially helpful if you’ve had to factory reset your device or if you’ve swapped over to a new device. Now it seems like un-rooted users will also be able to automatically backup and restore their apps thanks to a feature called ‘Auto Backup for Apps’ that is present in the latest Android M Preview.

Google’s Matthew Jav Williams takes us on a video run through of the Auto Backup for Apps feature, telling us that the apps user data will be automatically backed up and stored in Google Drive with a 25mb limit. The app backups will not count as part of your Google Drive quota. If you’ve installed apps on your device either from a third-party app store or by side-loading, don’t worry, they will also be backed up because the Auto Backup for Apps function isn’t directly tied to the Google Play Store.

Backups will occur when:

  • It is night-time
  • The device is charging
  • The device is connected to WiFi

Developers can include this feature into their apps by re-building their apps with version 23 of the SDK, they can also choose to opt out of including the auto backup function as well as choosing not to back up sensitive data or device specific tokens. Matthew gives some coding examples in the video below which show how easy it is for developers to include the Auto Backup for Apps function.

 

Click here to view the embedded video.

Source: Google Developers Blog
Via: Phandroid

Come comment on this article: Google shows off Android M’s Auto Backup for Apps function in video

Best resources for Android Game Developers

Posted by wicked April - 30 - 2015 - Thursday Comments Off
Blek_development_screenshot_in_Unity

Android game development can be fun albeit stressful. There are so many resources for game developers. Some resources cater to PC or console games, while others try to cover all game devices.

Some resources are therefore more useful to mobile game developers than others, while some resources are more useful to Android game developers than other mobile device types. Most game resources are gravitating towards a cross platform model, so most of these resources will be useful to game developers for other platforms, or those looking to develop portable cross platform games.

Development

Before you begin development, you should have a basic understanding of the Android platform, and should know where to go for help if you get stuck. Here are a few useful sites:

Android Developer Blog
This is the official news and announcements for android developers, coming directly from the android team at Google. Every android application developer should, at the very least, visit regularly.

StackOverflow
Stackoverflow is a question and answer site for developers. Most issues you run into while developing has been encountered by someone else before, and asked, and answered on stackoverflow.

UX Magazine
The User Interface and User Experience of your game is a very important part of your game, which you ignore at your own peril. This website contains a ton of articles, tips, tricks and resources to guide your Interface design

Game Engines

dragon-screenshot700

It is pointless re-inventing the wheel and writing your game engine. There are many game engines out there that do all the grunt work for you including moving sprites, handling collisions, physics, etc. Take the time to learn and use one of them for your game:

Cocos2d
A widely used game engine, for mobile game development. As it’s name suggests, its used primarily for 2D games.

Corona
A free to use cross platform gaming SDK which can create apps for Android, iOS and Windows Phone. Based on the LUA language the SDK is easy to learn and includes a phone emulator which makes development easy on a Windows PC or a Mac.

LibGDX
A fantastic game engine, that also integrates with a physics engine. It is primarily a 2D game engine, although it can also be used for 3D game development.

Unity
Unity has become one of the most successful game engines for mobile games. Games developed with unity are portable across mobile devices, consoles, PC operating systems and the web. It has been used in a number of very popular games.

Unreal Engine
Another excellent game engine, developed and backed by Epic Software. Based on the engine used to develop the hugely popular and successful Unreal Tournament. Games developed with this engine are portable across mobile devices, consoles and PC operating systems.

Game Content (Graphics, Art and Music)

graphic-buffet-freebies

While the actual game play is very important, the game content is also very crucial to a game’s success. Here is a list of some of the places where you can get excellent game content for free, or purchase, as well as some places where you can get artists to work on your art:

Graphic Buffet
Contains a selection of 2D game graphics, assets, UI elements and more.

Lets Make Games
This is an excellent resource, containing links to assets for game developers. There are links to free and paid resources, including art, graphics, sound, music, models, animations and more. For both 2D and 3D games.

Super Game Asset
Has a selection of game art, including environment, characters, icons and more, mainly for RPG games

Unity Store
Artists and content creators can register and freely sell their creations through the Unity store. Game developers can then purchase the content and use within their games.

Unreal Engine Marketplace
Another excellent marketplace. If you use the Unreal Engine then this should be your first port of call for art.

Analytics

gameanalytics-progression-dashboard

Once you game has been released it is important to collection information about how it is being used. Where are the players getting stumped and giving up, and how do they react to purchase buttons and so on. To do this you need to use an analytics service. Find one that has an API and terms of use that you are comfortable with, and use it. While most are free, others come with fees.
Some of the most popular services used for game only analytics include:

Other widely used analytics tools, for Android apps in general include:

Monetization

Like the analytics space, there are quite a number of mobile advertising networks. There are different types of ads that can be served, including banners, interstitials, videos, walls, and even ones integrated with in-app purchases. Some networks, for example, deliver excellent interstitials, but do poorly on videos. It is possible to register on multiple ad networks, and serve ads based on which network has the higher rate for a given user location. Some of the major ad networks include

News And Publicity

Of course after writing your game you would want to publicize and share it with the world. These are a collection of websites and blogs that are dedicated to gaming news, trends and information. Most of them are cross platform, not Android only.

Wrap up and Android Developer Newsletter

These are some of the most best and most useful resources available for Android game developers. Now you can get coding, and create the next viral mobile game. Is there any other resource you think should be here? Leave a comment below and share with us.

Do you want to know more? Subscribe to our Android Developer Newsletter. Just type in your email address below to get all the top developer news, tips & links once a week in your inbox:


PS. No spam, ever. Your email address will only ever be used for Android Dev Weekly.

How to use SQLite to store data for your Android app

Posted by wicked April - 29 - 2015 - Wednesday Comments Off
sqlite-and-Android

Most Android apps will need to persist user data at sometime. There are different ways to store user data, but SQLite databases are a very convenient and speedy method of saving user (or app) data and information.

SQLite is an opensource SQL database that stores the database as a text file on a device. Basic familiarity with SQL sets up a developer nicely to use Android’s sqlite implementation. And for developers not familiar with SQL, do not be discouraged, SQL is pretty straightforward to learn, use and implement. SQLite is a relational database management system just like Oracle, MySQL and PostgreSQL. Due to its small footprint and public domain license, it is possibly the most widely deployed database engine in the world, it can be found in all types of software ranging from embedded systems, browsers, and operating systems.

Android has a built in SQLite implementation, and application specific database files are stored in a private disk space that’s inaccessible to other applications. This way, no application can access another application’s data.

Preparation

The complete source code for this tutorial is available on GitHub.

The sample application for this tutorial shows how to create a database, named “SQLiteExample.db”, that contains a single table named “person”. This table stores Person data, including his name, gender and age.

There are two Activities, MainActivity, which shows a list of stored Person names, and CreateOrEditActivity, which allows adding and editing Person details.

The most important class, in our sample, is the ExampleDBHelper class, which extends SQLiteOpenHelper. SQLiteOpenHelper is a helper class designed to manage database creation and version management. You override onCreate() and onUpgrade() methods, and whenever a new database is created or upgraded, the appropriate method gets invoked.

ExampleDBHelper is where all the SQLite operations are carried out, and both MainActivity and CreateOrEditActivity call methods from this class to view, create, update or delete data from the database.

Extending “SQLiteOpenHelper”

We create a class, called ExampleDBHelper, that extends SQLiteOpenHelper. We begin by defining the database, tables and columns as constants. This is always a good idea. If any of these names get changed, rather than hunting through the source for all occurrences, we simply change it once. Take special notice of the column called “_id” (PERSON_COLUMN_ID). This column has special significance which will be discussed below.

public static final String DATABASE_NAME = "SQLiteExample.db";
private static final int DATABASE_VERSION = 1;
public static final String PERSON_TABLE_NAME = "person";
public static final String PERSON_COLUMN_ID = "_id";
public static final String PERSON_COLUMN_NAME = "name";
public static final String PERSON_COLUMN_GENDER = "gender";
public static final String PERSON_COLUMN_AGE = "age";

In the constructor, we call SQLiteOpenHelper’s constructor, passing it the application context, the database name, an SQLiteDatabase.CursorFactory (we actually pass a null object here), and the database version. This constructor handles the creation or upgrade of the database. The database version should begin from 1, and increase linearly, whenever you modify the database schema.

public ExampleDBHelper(Context context) {
    super(context, DATABASE_NAME , null, DATABASE_VERSION);
}

The onCreate() is called whenever a new database is created. Here, you specify each table schema. In our example app, we have only one table.

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL("CREATE TABLE " + PERSON_TABLE_NAME + "(" +
        PERSON_COLUMN_ID + " INTEGER PRIMARY KEY, " +
        PERSON_COLUMN_NAME + " TEXT, " +
        PERSON_COLUMN_GENDER + " TEXT, " +
        PERSON_COLUMN_AGE + " INTEGER)"
    );
}

The overridden onUpgrade() method is called whenever the database needs to be upgraded (i.e. when the version has changed). Here, you should drop and/or add tables, or migrate data to new tables, or whatever else needs to be done to move from the previous database schema to the new schema. In our example, we simply drop the existing “person” table, and then call onCreate() to recreate it. I doubt you would want to do this with real user data.

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL("DROP TABLE IF EXISTS " + PERSON_TABLE_NAME);
    onCreate(db);
}

For the sample application, we want the ExampleDBHelper class to handle all data insertion, deletion, updates and views (basically all queries to the database must be through ExampleDBHelper). So we define appropriate methods for each of these scenarios.

To insert a new Person, we use the creatively named insertPerson() method. We use the SQLiteOpenHelper method getWritableDatabase() to get an SQLiteDatabase object reference to our already created database. The Person details are stored in a ContentValues object, with the appropriate column name as key, and corresponding data as value. We then call SQLiteDatabase’s insert method with the person table name, and the ContentValues object. NOTE that we left out the PERSON_COLUMN_ID column, which was specified as a primary key. It automatically increments.

public boolean insertPerson(String name, String gender, int age) {
    SQLiteDatabase db = getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    contentValues.put(PERSON_COLUMN_NAME, name);
    contentValues.put(PERSON_COLUMN_GENDER, gender);
    contentValues.put(PERSON_COLUMN_AGE, age);
    db.insert(PERSON_TABLE_NAME, null, contentValues);
    return true;
}

create_person
To update a person, we created an updatePerson() method. It is similar to the createPerson() method. The equivalent SQL statement to update a person row would be “UPDATE person SET name=’name’ and gender=’gender’ and age=’age’ WHERE ID=’id’“. The SQLiteDatabase update method is a convenient method for updating rows in a table. It is defined as: public int update (String table, ContentValues values, String whereClause, String[] whereArgs), where the whereClause represents the optional where clause, and whereArgs is a String[] of values that would replace the “?’s” included in the whereClause. Passing a null value as the whereClause will update all rows.

public boolean updatePerson(Integer id, String name, String gender, int age) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    contentValues.put(PERSON_COLUMN_NAME, name);
    contentValues.put(PERSON_COLUMN_GENDER, gender);
    contentValues.put(PERSON_COLUMN_AGE, age);
    db.update(PERSON_TABLE_NAME, contentValues, PERSON_COLUMN_ID + " = ? ", new String[] { Integer.toString(id) } );
    return true;
}

android_sqlite_edit_person
We implemented two methods to view person’s in the database. The first retrieves a single person, given his id, and the other retrieves all persons. Since we are not writing to the database, we retrieve a readable database with getReadableDatabase(), and perform a rawQuery(). RawQuery takes a SQL query string, with optional queryArgs and returns a Cursor object. A Cursor provides access to the result set returned. A Cursor can be transversed forward, backwards or randomly. Cursor also provides methods to retrieve particular columns, total columns, total rows and much much more.

public Cursor getPerson(int id) {
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor res = db.rawQuery( "SELECT * FROM " + PERSON_TABLE_NAME + " WHERE " +
        PERSON_COLUMN_ID + "=?", new String[] { Integer.toString(id) } );
    return res;
}
public Cursor getAllPersons() {
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor res = db.rawQuery( "SELECT * FROM " + PERSON_TABLE_NAME, null );
    return res;
}

Deleting data is also pretty straightforward. SQLiteDatabase has a delete() method that takes the table name to delete from, and optional whereClause and whereArgs. NOTE: Be very careful when writing this, as passing null in the whereClause would delete all rows.

public Integer deletePerson(Integer id) {
    SQLiteDatabase db = this.getWritableDatabase();
    return db.delete(PERSON_TABLE_NAME,
        PERSON_COLUMN_ID + " = ? ",
        new String[] { Integer.toString(id) });
}

android_sqlite_delete_person

Integrating the “Helper” with the rest of the app

At this point, we have completely prepared our database for use. To integrate this with both our activities, we initialize ExampleDBHelper in each Activity onCreate() method, and then call the appropriate method, depending on what action is required.

In MainActivity, we display a list of all persons using a ListView. Clicking on the “Add New” button starts CreateOrEditActivity in create mode, allowing us to create a new person. While clicking on any list item starts CreateOrEditActivity in edit mode, allowing us delete or edit and update the person info.

To display the list of persons, we request a Cursor containing all person records. We then use a SimpleCursorAdapter instance for displaying the list items. Do you remember the special column named “_id” mentioned above? SimpleCursorAdapter requires this column, or else it would not work. To use the SimpleCursorAdapter, we define a layout view for each list item called person_info.xml.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<TextView
    android:id="@+id/personID"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="@dimen/activity_vertical_margin"
    android:textSize="@dimen/text_size"/>

<TextView
    android:id="@+id/personName"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:padding="@dimen/activity_vertical_margin"
    android:textSize="@dimen/text_size"/>

</LinearLayout>

All the magic in MainActivity happens in the onCreate() method. We get a dbHelper object, request for all person’s, and populate the ListView with the received Cursor. Finally, we implement the onItemClickListener() so that when a person is clicked, we get the person ID and parse it as an extra to CreateOrEditActivity.
The complete MainActivity code follows:

public class MainActivity extends ActionBarActivity {
    public final static String KEY_EXTRA_CONTACT_ID = "KEY_EXTRA_CONTACT_ID";

    private ListView listView;
    ExampleDBHelper dbHelper;

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

        Button button = (Button) findViewById(R.id.addNew);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, CreateOrEditActivity.class);
                intent.putExtra(KEY_EXTRA_CONTACT_ID, 0);
                startActivity(intent);
            }
        });

        dbHelper = new ExampleDBHelper(this);

        final Cursor cursor = dbHelper.getAllPersons();
        String [] columns = new String[] {
                ExampleDBHelper.PERSON_COLUMN_ID,
                ExampleDBHelper.PERSON_COLUMN_NAME
        };
        int [] widgets = new int[] {
                R.id.personID,
                R.id.personName
        };

        SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this, R.layout.person_info,
                cursor, columns, widgets, 0);
        listView = (ListView)findViewById(R.id.listView1);
        listView.setAdapter(cursorAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView listView, View view,
                                    int position, long id) {
                Cursor itemCursor = (Cursor) MainActivity.this.listView.getItemAtPosition(position);
                int personID = itemCursor.getInt(itemCursor.getColumnIndex(ExampleDBHelper.PERSON_COLUMN_ID));
                Intent intent = new Intent(getApplicationContext(), CreateOrEditActivity.class);
                intent.putExtra(KEY_EXTRA_CONTACT_ID, personID);
                startActivity(intent);
            }
        });

    }

}

CreateOrEditActivity is a little bit more involved. The Activity allows creating, editing and deleting persons. It also changes its UI based on what action is to be performed. Because of it’s length, we shall only show and discuss the parts relevant to database interaction.

In onCreate(), if we receive a personID, we call dbHelper.getPerson() with that ID, and then populate the fields with the person details:

Cursor rs = dbHelper.getPerson(personID);
            rs.moveToFirst();
            String personName = rs.getString(rs.getColumnIndex(ExampleDBHelper.PERSON_COLUMN_NAME));
            String personGender = rs.getString(rs.getColumnIndex(ExampleDBHelper.PERSON_COLUMN_GENDER));
            int personAge = rs.getInt(rs.getColumnIndex(ExampleDBHelper.PERSON_COLUMN_AGE));
            if (!rs.isClosed()) {
                rs.close();
            }

If the delete button is clicked, we call dbHelper.delete() with the personID

case R.id.deleteButton:
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setMessage(R.string.deletePerson)
                        .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dbHelper.deletePerson(personID);
                                Toast.makeText(getApplicationContext(), "Deleted Successfully", Toast.LENGTH_SHORT).show();
                                Intent intent = new Intent(getApplicationContext(), MainActivity.class);
                                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                startActivity(intent);
                            }
                        })
                        .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                // User cancelled the dialog
                            }
                        });
                AlertDialog d = builder.create();
                d.setTitle("Delete Person?");
                d.show();
                return;

Finally, we implemented a persistPerson() method that checks if we require a person creation or update.

    public void persistPerson() {
        if(personID > 0) {
            if(dbHelper.updatePerson(personID, nameEditText.getText().toString(),
                    genderEditText.getText().toString(),
                    Integer.parseInt(ageEditText.getText().toString()))) {
                Toast.makeText(getApplicationContext(), "Person Update Successful", Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(getApplicationContext(), MainActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
            }
            else {
                Toast.makeText(getApplicationContext(), "Person Update Failed", Toast.LENGTH_SHORT).show();
            }
        }
        else {
            if(dbHelper.insertPerson(nameEditText.getText().toString(),
                    genderEditText.getText().toString(),
                    Integer.parseInt(ageEditText.getText().toString()))) {
                Toast.makeText(getApplicationContext(), "Person Inserted", Toast.LENGTH_SHORT).show();
            }
            else{
                Toast.makeText(getApplicationContext(), "Could not Insert person", Toast.LENGTH_SHORT).show();
            }
            Intent intent = new Intent(getApplicationContext(), MainActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
        }
    }

Conclusion

Extending SQliteOpenHelper helps you abstract the database creation, updates and maintenance, so you can focus on interacting with the database. We used different methods to interact with the database, including helper methods, and plain SQL commands.

While this sample app creates a simple one-table database, SQLite is a complete relational database system, and supports more advanced features including multiple tables, foreign keys, complex queries with joins and more. Using SQLite in your android app is a fast, secure, efficient and easy way to persist user and app data.

The complete source code for this tutorial is available on GitHub.

Android Developer Newsletter

Do you want to know more? Subscribe to our Android Developer Newsletter. Just type in your email address below to get all the top developer news, tips & links once a week in your inbox:


PS. No spam, ever. Your email address will only ever be used for Android Dev Weekly.

Android customization – how to make a screen recording, using ADB – root not required

Posted by wicked April - 9 - 2015 - Thursday Comments Off

Last week on our Android customization series, we dove into a deep and involved developer tool called ADB, or Android Debug Bridge. Our purpose last week was pretty simple, we were trying to hunt down apps that were eating up the battery on our Android devices, and we used logcat to do so.

This week, now that you’ve got ADB up and rolling, let’s keep using it. I have a short list of tasks I want to perform with ADB, but we will start off with the most fun of them all, capturing a screen recording on your Android device.

Before we get started

You do not require any special apps or to have root on your device to follow along today, or for any of our upcoming ADB tasks in the coming weeks. You will, however, need to have a connected computer with ADB setup and ready to roll.

Nexus 9 HP Chromebook USB ADB logcat

You will need to at least follow along our previous project to see how ADB is setup and enabled on your connected computer, and be ready to connect with an appropriate USB cable for your Android device.

Warning: The screen record functionality in ADB is for video only, it does not capture the audio of your device, please be prepared to capture audio separately, if required. The recording is limited to about 3 minutes in length, to help prevent copyright violations, I presume. Screen rotation is not supported, pick an orientation and stick with it for the recording.

Capture a screen recording with ADB

First things first, connect your Android device to your PC. Follow any steps required to enable ADB, fire up your command/Terminal window and get ready to rock.

ADB screenrecord sample

In your command or Terminal window, enter adb devices and hit enter.

As mentioned last week, you do not really need to do this, but it is always nice to see that your device is connected and reporting to your computer properly.

Now, enter adb shell and hit enter.

Shell enables a subset of new tools within ADB, and, in a manner of speaking, provides access to the command line controls of your actual device. If that does not make sense, don’t worry about it, we’ll have the chance to explain in more detail at a later date.

Enter screenrecord /sdcard/video.mp4 and hit enter.

You are now recording your Android device display.

To stop the recording, wait for three minutes to expire, or simply press Ctrl+C into the command/Terminal window.

ADB screenrecord Moto G on Chromebook

The video file is saved to your Android device, and will be located where you specified above, which would be on your /sdcard/ if you entered the exact text above. Feel free to specify a new storage location on your device, and a new file name as well, be careful not to run the command again right away, as it may overwrite your previous video.mp4 file.

What’s next

Our implementation above utilizes the bare bones defaults of the screen record tool. There are additional options available that may be of use to you.

First, the default will record the video at your device’s screen resolution, if supported. If you have issues, try specifying a specific screen resolution. The general format is to add –size WIDTHxHEIGHT to your command. For example, screenrecord –size 1280×720 /sdcard/recordings/my720pvideo.mp4. Consult your manufacturer for supported resolutions on your Android device’s AVC encoder.

You can also control the bit-rate and recording time (up to 3 minutes.) Head on over to the ADB help pages for more details – fair warning, our next few Android customization posts will cover our favorite tools on that ADB page, feel free to jump ahead if you wish. For now, the following image has the few supported screen record options for you.

ADB screenshots command options

Next week

Now that you have a screen recording or two saved to your Android device, you may want to get it off the device and onto your computer. We have talked about file transfers before on our Android customization series, but we’ve got ADB at our disposal now, so let’s use it. Next week, we will use ADB to transfer files to and from your computer and Android device.

What do you use a screen recording for? Work, entertainment, send to a friend to show them a problem you are having?

Android customization – improve battery life, use ADB logcat to find battery hogs

Posted by wicked April - 2 - 2015 - Thursday Comments Off

Nexus 9 HP Chromebook USB ADB logcat

Last week on our Android customization series, we took a few moments to look at the built-in Android tools in an attempt to hunt down rogue apps eating up your battery. We continue that pursuit for battery life perfection this week, taking a little bit more advanced look at identifying battery killing apps.

Warning: This week’s post is not intended for beginning Android users. While we encourage you all to expand your abilities, maybe even to give this project a go, we will be using Google’s ADB developer tools, which are not exactly made for your everyday Android experience.

Before we get started

Today we have a whole bunch of requirements, luckily, there is a great chance that you have everything you need kicking around. First, you will need a computer with a functioning Windows, Mac or Linux operating system. From there, that computer must have a functioning USB port. Doesn’t sound too bad so far, does it? Lastly, as far as hardware goes, you’ll need the USB cable that goes to your Android device.

Aside from the super obvious stuff above, you are going to need to have the Android SDK and appropriate drivers for your Android device installed on your computer. If you are unsure how this is done, rest assured, we’ve got you covered:

How to install the Android SDK
How to setup ADB

Use Logcat to watch your system

The idea is pretty simple here today folks, logcat is a tool that watches all of the system level actions on your device. While this list may be a little overwhelming at first, it is a low level developer’s tool after all, it shouldn’t take long for you to recognize your apps and how they are taking up the cycles on your device.

Once you have the Android SDK and ADP setup and running, you are likely already connected to your computer, but let’s start with those steps anyhow.

Nexus 9 HP Chromebook USB cable

Connect your Android device to your computer.

Turn on the necessary settings for your device, including USB Debugging, which is found in your Developer Options.

Fire up a command prompt on your computer.

Now, you will either have to CD (change directory) navigate to the location of your ADB.exe, or, find it in your platform-tools folder and open the folder in a terminal/command window.

Enter the command adb devices and hit enter. This step isn’t actually required, but it is a simple way to make sure your PC and your Android device are talking.

Enter the command adb logcat and hit enter.

Sit back and watch as your device pumps out its actions to your computer screen.

ADB Logcat CMD Windows

Now that you have your logcat, what’s eating your battery?

There is no easy solution here. Logcat is designed to catch actions as they happen, this means you will need to spend some time connected, allowing your device to do its thing. As you watch the log, you will soon begin to identify your apps, especially if they are misbehaving.

Our results

ADB Logcat Pogoplug WiFi off

If you recall, we’ve been hunting down poor battery life on our Nexus 9. Although we still have to figure out the real culprit, we learned something extremely valuable. We were able to determine that, as anticipated, two of our favorite customization apps, Pushbullet and Zooper Widget, are very well behaved apps. They do keep the device awake a bit here and there, as is expected with this level of use, but certainly are well behaved enough that uninstalling them is not required. At least this is true when you are connected to WiFi!

That’s right, the moment we turned off WiFi, as we have been doing frequently in an attempt to reduce power consumption, activity for both services ramp up. Again, the actions Pushbullet and Zooper Widget are taking are not strenuous on the battery themselves, but they are frequent, preventing your device from entering and remaining in a sleep state, thus, killing the battery faster than would be expected. Do we uninstall the apps or just keep WiFi turned on? Not sure yet, but we are pleased that we have something to work with.

What’s next

I hope that you were not expecting magic here today folks. There is no doubt that logcat is a bulletproof method to see what your device is doing in the background, but it is now up to you to determine if all of your apps’ actions are justified, or if you need to do a little uninstalling.

Every once in a while you can repair an app without full un-installation. Make sure you’ve got the app data backed up, if applicable, then head into the App section of Settings, try hitting the Clear Cache and/or Clear Data buttons. Clearing data will reset the app to an empty state, wiping all of your saved game data or requiring you to log back into the service.

Android clear app cache

While there is no guarantee that wiping an app’s data will fix it, you should find it is at least worth trying before giving up and uninstalling completely.

Final thought, do keep in mind that there are some apps that you just cannot fix. We’ve named and shamed some of these apps before. In the end, you may choose to live with the battery drain, if the app serves a purpose well enough for you. Worst of all, you may find that the Android operating system itself is sapping all your juice. If you are like me, you are just sitting back praying that Google pushes out a fix soon, or are considering some of those custom ROMs out there instead.

Next week

Android ADB shell

As we continued the process of hunting down apps that are eating up our battery, our Android customization post this week took to logcat to see what is going on. To get to logcat, we needed to use ADB, and you know what, ADB has some other cool features as well, let’s take a look at a few next week.

Did you manage to find any rogue apps in your logcat today? Will you uninstall them? Can you uninstall them?

Google getting serious with Cardboard

Posted by wicked December - 11 - 2014 - Thursday Comments Off

google_cardboard_500k_units

Whatever it started as, Google’s virtual reality viewer originally released as a “device” made out of a cardboard box has proven so successful that Google is investing even more in the platform. According to Google, they count more than half a million Cardboard viewers in use and with numbers like that, they have released a new round of updates for users, developers and makers of the device.

For users looking for a Cardboard compatible app, Google is making things a little easier with a dedicated collection page in the Google Play Store just for Cardboard apps. There are a variety out there including test drives, concerts, even games.

Developers who want to try their hand at a VR application now have access to a new set of Cardboard SDKs for Android and Unity. Google says the SDKs will speed the development process by taking over things like lens distortion correction, head tracking and side-by-side rendering. That will allow developers to focus on things like gameplay or graphics.

Google also announced the release of updated specifications for the open source Cardboard viewer. The primary addition to this update is specs for specific cutting tools that will help producers more easily do things like laser- or die-cut their viewers, even in large quantities. However, users who want a DIY solution can still use the specs for their own device.

Google indicated that next year they plan to add a calibration tool to the Cardboard SDK. This means things like the base and focal length for different viewers can be defined and apps will automatically adjust.

Anyone out there using Google Cardboard?

source: Google Developers

Come comment on this article: Google getting serious with Cardboard

Google makes Android SDKs available on DVD for offline use

Posted by wicked December - 3 - 2014 - Wednesday Comments Off

DEV_KIT_2_1

Now more than ever, Google is focusing on getting more of their products into the hands of users in developing markets. Take for example, Android One. The program is based on getting sub-$150 handsets to people in the world who wouldn’t normally have access to them, let alone be able to afford them. With the expansion of Android One around the world, there are going to be more developers wanting to make products using the Android SDK.

Sure, the SDK is available online, but what happens if you don’t have a trustworthy or fast enough internet connection? Google now has you covered, as they’re releasing the Android SDK and more on DVD.

If you’re interested in getting the kit for yourself, simply get in contact with your local Google Developer Group. They’ll ship you a kit that includes a total of 30GB worth of information, including YouTube videos, Cloud Platform documentation, and much more. Here’s the list of everything that’s included in kit:

Google making the Android SDK available for offline use is absolutely a step in the right direction, as more and more developers in regions with slower internet or low data caps will need access to it in the future. Now it should be pretty easy for people all around the world to get their hands on the SDK.

Google releases Android 5.0 Lollipop SDK and other tools

Posted by wicked October - 17 - 2014 - Friday Comments Off

android_lollipop_waving

As previously reported, Google has followed up their official release of Android 5.0 Lollipop earlier this week with the announcement that the full Android 5.0 SDK is now ready for developers to download. Along with the new SDK, the team is also making available updated developer images for the Nexus 5, Nexus 7 (2013), ADT-1, and the Android emulator. On their Android Developers Blog, Google indicates the first consumer devices to ship with Android 5.0 Lollipop will be the Nexus 6, Nexus 9 and Nexus Player starting on November 3rd with the Nexus 9. They indicate other Nexus devices, including the Nexus 4, 5, 7 (both the 2012 and 2013 versions), 10, and Google Play Edition devices, will receive an OTA update for Android 5.0 Lollipop “in the same timeframe.”

Android 5.0 Lollipop is packed full of new features and a long list of new APIs that developers can take advantage of, including the code necessary for their new Material Design, enhanced notifications, Project Volta and Battery Historian, Android Runtime (ART), OpenGL ES 3.1, and 64-bit support. With so many changes, Google is encouraging developers to grab appropriate preview images and start testing their apps now so they can be ready when consumer devices start getting Android 5.0 Lollipop.

If you don’t mind wiping your system, the developers have also made final preview images of Lollipop available for the Nexus 5 (“hammerhead”) and the Nexus 7 (2013) (“razor”) devices. If you decide to go down this path though, note that you will not receive the OTA update when released in November until you install a factory image on your device.

Google is also encouraging developers to go ahead and publish their updated apps with support for Android 5.0 Lollipop to Google Play. Depending on how fast developers move on this, we should probably expect to see a ton of updated apps hitting Google Play in the coming weeks.

source: Android Developers Blog

Come comment on this article: Google releases Android 5.0 Lollipop SDK and other tools

Nexus_5_Android_L_Developer_Preview_Home_Screen_01_TA

If you’re one of the many who jumped ship from their stable Android version to try out the Android L Developer Preview, you definitely noticed it’s not exactly the most polished thing in the world (not even close, actually).

No reason to be mad at Google, though — it’s just a developer preview, and we’re lucky to have something before launch.

As most Android enthusiasts tend to do, we looked ahead, and hoped for Google to upload an updated factory image of the L Developers Preview. But according to Googler Rich Hyndman, it ain’t happening.

Here’s what Hyndman had to say on the matter:

“There’ll be some extras coming, like the 64-bit emulator. But I don’t believe new device images are coming,” Hyndman said.

He also noted that, as we know, the release is primarily for developers to be able to test their apps and get them ready for the L launch.

“It is the first time we’ve had a preview release and it will mean less chance of issues with apps in the Play Store at launch and more apps ready to take advantage of the new features,” Hyndman said.

Expect the official version of L to start hitting Nexus devices this fall, alongside the launch of one (or more) new Nexus devices.

Check out Hyndman’s video about the developer preview below.

Click here to view the embedded video.

Source: BGR

 

 

 

 

Come comment on this article: Want an updated factory image of Android L Dev Preview? Not gonna happen, a Googler says

ePad 7 Android 4.0 ICS
$162 $100 FREE SHIPPING 

10" Android 4.2 1.2GHz Tablet PC

7