Showing posts with label android. Show all posts
Showing posts with label android. Show all posts

Sunday, May 26, 2013

Converting APK to BAR and deploying it to BB10 device

As you might know BB10 device support Android application. But to install Android application on BB10, first you need to convert .apk file to .bar file.

I already have install BB10 NDK (Native Development Kit ), so I did not struggled with installing certificate file and setup the signer. BB10 NDK installer and IDE did that for me.

You will also need android sdk installed on your pc, before you begin. You can find detailed instruction here at BlackBerry Development site.

Following are few steps that I often use to convert APK to BAR file.

1) export ANDOID_HOME varible

export ANDROID_HOME=~/android_sdk/sdk/

2) Verify if APK file does not you unsupported APIs.

 ./apk2barVerifier ./ANDROID_APPLICATION.apk 

3) If your APK does not use unsupported APIs then you can go ahead and covert APK to BAR to test on your device.

./apk2bar ./ANDROID_APPLICATION.apk -d DEBUG_TOKEN_FILE 

4) Install BAR file to development device.

Following will deploy all BAR files under test folder to device.I find this method easier.

./batchbar-deploy ~/Desktop/test 169.254.0.1 DEVICE_DEVELOPMENT_PASSWORD

Or you can deply individual BAR file using following command.

 ./blackberry-deploy -installapp -package ./BAR_FILE.bar -device 169.254.0.1 -password DEVICE_DEVELOPMENT_PASSWORD

Once testing is done, you can use blackberry-signer command to sign BAR file and publish it on App World. But I did not tried it my self. I just wanted to install one android app on my BB10 and my device is always on development mode so I just used BAR files with Debug token.

Saturday, January 7, 2012

Playing audio file and getting metadata in Android

As I indicated in my previous post that I am currently learing Android to port my audiobook reader app to android.

I managed to create initial book list screen, and now trying to learn how to play audio file and fetch metadata file.

Playing audio file with android is quite easy, Audio and Video are played using MediaPlayer class and quite easy to use.

Following is sample code to play media file in android.

private MediaPlayer mPlayer;

mPlayer = new MediaPlayer();
mPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
        String path = "/sdcard/music/sample music.mp3";
 mPlayer.setDataSource(path);
 mPlayer.prepare();
 mPlayer.start();    
} catch (Exception e) {
 e.printStackTrace();
}

In above code we are setting data source and then preparing mediaplayer then calling start to play media file. It can be paused by pause API and stopped by calling stop.

Now that I am able to play audio file, I tried to fetch its metadata file to show detais of Audio file to user. Fetching metadata was not as easy as playing file as its requied to use ContentResolver API and at first glance it looks quite strange to use it. After spending some time I managed to fetch metadata using following code.

To fetch metadata first we need to decide which attributes we are instrested in. Following are quite frequently used attributes.
       
String[] TRACK_COLUMNS = new String[] {          
 MediaStore.Audio.AudioColumns.ALBUM,
 MediaStore.Audio.AudioColumns.ARTIST,
 MediaStore.Audio.AudioColumns.DURATION,
 MediaStore.Audio.AudioColumns.TRACK,
 MediaStore.Audio.AudioColumns.YEAR, 
 MediaStore.MediaColumns.SIZE,
 MediaStore.MediaColumns.TITLE,
 MediaStore.MediaColumns.DATA,
 MediaStore.MediaColumns.DISPLAY_NAME
 };
Then we need to use ContentResolver to query audio content provider to fetch metadata. I am instrested in query metadata for perticular file. So I am using MediaStore.MediaColumns.DISPLAY_NAME (filename) as selection and then specifying instrested filename in values array.
ContentResolver resolver = getBaseContext().getContentResolver();
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
//Uri uri = Media.getContentUriForPath(path);

String selection = MediaStore.MediaColumns.DISPLAY_NAME + "=?";        
String[] values = new String[] { new File(path).getName() };
Finally calling query API using instrested attributes and specifying required condition, Using Cursor we can retrive required metadata.
Cursor cursor = resolver.query(uri, TRACK_COLUMNS, selection, values, null);
while(cursor.moveToNext()) {             
   for( int i = 0 ; i < cursor.getColumnCount(); ++i ) {
      Log.d("TEST", cursor.getString(i));
   }
}
So that's all, Hope it will be helpful.

Saturday, December 31, 2011

i-muz Tx72 7" inch android tablet

Recently I purchased iMuz Tx72 7" inch android tablet. I wanted a tablet on which I can read book and browse internet and this tablet full fill both that requirement quite well.

I went for this tablet as other similar config tablet like Kindle Fire or Nook are not easily available here or available but need to pay extra price. This was easily available for me, placed order online on gmakret and got it next day.

Currently it comes with android 2.3.3 and their site suggest that android 4 will be supported in around month time.

It has 512 mb ram, Cortext A8 1GHz cpu and 8 gb internal storage with up to 32 gb SD card support.  Its wifi only model and support TV out using HDMI , mini usb and front camera for video call. If you want a full specifiction its here.

Its multitouch device and display quality is good. Thought its supported resolution is 480x800 only. Its sound quality its good, sound is clear and loud enough and video from youtube and dailymotion played fine.

I tried HDMI out, but was not successful trying to see device screen on my TV, might be cable problem but i suspect its device problem.

Home key, back , search and other standard android key are not backlight supported , so using them at night is guess work.

Battery takes time to get fully charged but once charged enough, it keeps going for atlest two days for normal reading and browsing use and works around 4 hour if watching you tube video.

Now on software part, by default it comes with app called app installer which let you install android apk file, browser, Email client, ES file explorer , Gallary and music application.

It was kind of disappointment by not seeing android market place application, but I was expecting it as it kind of entry level device. I tried to install market place by apk but its says not supported and web version keep complaining that you dont have any device attched to your google account. So I cant install any application from official android market place.

But I was able to install amazon store and getjar store and was able to install app from those store.

I installed PDF reader and worked great. I tried to install skype app but it never worked and was not able to login, so can not try it. But Fring worked great and also supported video calling feature.  And other normal application like Angry bird, guitar hero, piano worked great. 

I also liked ES file explorer as it allows to browse device easily and also it allows network shared storage. Like I shared my computer's folder over network and I was able to connect that computer and download contect from that shared folder using ES file explorer.  It also allows to connect to Dropbox and FTP server easily. But I tried only network shared folder.

Overall, its good device for reading and browsing and serve well as development device. It has fairly supported standard feature of tablet at fair price.



Saturday, December 24, 2011

Creating custom list view and adaptor in Android

I recently got new toy for myself a imuz TX72 7" android tablet to satisfy my book reading hobby.

I will write a seperate post for tablet, but as I got this tablet, I thought to port my Audiobook reader app to Android so I can here my audiobook on this tablet as well.

As I started to port, First thing I need to learn is how to create view and specially list view. I required to create custom Listview so I can show thumnail and other audiobook details.

So to start, First you need to create is activity. I also wanted to put button on main activity so I did not derived my activity from ListActivity but derived it from Activity. For new people to android like me, Activity is something that we see on screen , a view.

My main activity goes like below.

    
public class AudiobookReaderActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       
       setContentView(R.layout.main);
       
       ListView list = (ListView) findViewById(R.id.BookList);
       list.setAdapter( new BookListAdaptor(this));  
    }  
}

Now we have list view, but how invidiual list item looks is decided by item's xml file, which provide layout and views details to be drawn as item.

Following is my list item, with one image and two text view.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=
       "http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
    
    <ImageView
        android:id="@+id/AlbumArt"        
      android:layout_width="55dip"
  android:layout_height="55dip"/>
    
 <LinearLayout xmlns:android=
              "http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:orientation="vertical" >    
 
  <TextView xmlns:android=
                "http://schemas.android.com/apk/res/android"
      android:id="@+id/BookName"     
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:textStyle="bold" 
      android:padding="3dp"
      android:textColor="#FFFF00" 
      android:textSize="16sp" >
  </TextView>
  
  <TextView xmlns:android=
                      "http://schemas.android.com/apk/res/android"
      android:id="@+id/TrackName"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:padding="3dp" >
  </TextView>
  
 </LinearLayout>
</LinearLayout>

Now look is set for list view, now we need to provide data to list, by creating adaptor class. Adaptor class act as model and provide data to list view.

Following is my custom list adaptor class to support Book data structure. Here getView method is importat as it uses our xml file to create liste item and decide our list view's look.

import java.util.ArrayList;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.content.Context;

public class BookListAdaptor extends BaseAdapter {
 
 public BookListAdaptor( Context context) {
  mContext = context;
  
  //load book list from file or database
  mBookList = new ArrayList();

  mBookList.add(new AudioBook("Harry Potter"));
  mBookList.add(new AudioBook("The Hobbit"));
 }

 @Override
 public int getCount() { 
  return mBookList.size();
 }

 @Override
 public Object getItem(int position) {
  return mBookList.get(position);
 }

 @Override
 public long getItemId(int position) {
  return position;
 }

 @Override
 public View getView(int position, View convertView, ViewGroup parent) {  
  
        if (convertView == null) {
   LayoutInflater layoutInflator = 
                             LayoutInflater.from(mContext);
   convertView = layoutInflator.
                             inflate(R.layout.list_item, null);
        }
     
        TextView bookName = (TextView) convertView.
                                      findViewById(R.id.BookName);
        TextView trackName = (TextView)convertView.
                                      findViewById(R.id.TrackName);
        ImageView imageView = (ImageView)convertView.
                                      findViewById(R.id.AlbumArt);
  
  
  AudioBook book = mBookList.get(position);
  bookName.setText(book.bookName());
  trackName.setText(book.bookName());
  imageView.setBackgroundResource(android.R.drawable.btn_plus);
  
  return convertView;
  
 }

    private Context mContext;
    private ArrayList mBookList;
}

Book class looks something like following.

package com.niku;

import java.util.ArrayList;


public class AudioBook {
 
    public AudioBook( String aBookName) {
 mBookName = aBookName;
    }
 
    public String bookName() 
    {
        return mBookName;
    }

    private String mBookName;
}  
That's all. Final list view will looks like followign snap. Thanks fo reading my blog.






Wednesday, February 24, 2010

Google Shooper application

Google announced android application called Google Shopper. This application lets you find product information quickly by using your phone's camera. It can recognize cover art of books, CDs, DVDs, and video games, along with most barcodes. You can also speak the name of the product you're looking for. It can tell price of item , places from where it can be purchased. It also saves your history so you'll always have product and price information even when you don't have a signal.

Here is demo video from google.



Monday, February 22, 2010

Adam Tablet from Notion Ink

I came to know about this new tablet developed by Notion Ink named as Adam, so think to share some information regarding this.

It is prices around $300 aprox 15000 INR and on the technical side, Adam has 6.3 x 9.8 inch display with 1024X600 SVGA, 32 GB flash drive, SD card support, Digital Compass, GPS and Wi-Fi. Connectivity includes USB, HDMI, 3.5mm headphone jack and a microphone input, and a 3 MP autofocus camera with video recording support.

It will run Andriod as Os and will support andriod's app store from which user will be able to download thounds of application.