Friday, September 25, 2015

Using keytools

During early development i have trouble finding keytools or how to access them. Most developer in my understanding are using linux so it's like they can just type the keytools to run.

I tried to configure windows command once for them to be able to read inside JDK folder but now forgot already after upgrading my OS to Win10. This is like shortcut stuff so here goes

Go to your JDK install folder. Mine is here and usually everyone is:
C:\Program Files\Java\jdk1.7.0_79

Shift+RightClick on 'bin' folder and select 'open command windows here'

Now you are inside jdk bin folder and keytools command can be used.

type your keytools command here, for example

keytool -exportcert -alias your-key-name -keystore /path/to/your/keystore/file -list -v

your-key-name is your app-key you create
path should be location of your key ie c:\myapp\hello_world\key.jks

Sunday, September 20, 2015

Delay using Handler

private Handler mHandler = new Handler();

private Runnable mUpdateTimeTask = new Runnable() {
        public void run() {
            // do what you need to do here after the delay
            
        }
    };
insert this anywhere you want to run
mHandler.postDelayed(mUpdateTimeTask, 2000);

SetTextColor


text.setTextColor(Color.parseColor("#FFFFFF"));

Saturday, September 19, 2015

start new activity

// Define intent to play again
final Intent playagainIntent = new Intent(this, PlayActivity.class);

ActivityOptions options = ActivityOptions.makeCustomAnimation(GameOverActivity.this, R.anim.slide_up, R.anim.slide_down);
startActivity(playagainIntent, options.toBundle());

Required XML attribute “adSize” was missing

<com.google.android.gms.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    ads:adUnitId="YOUR_AD_UNIT_ID"
    ads:adSize="BANNER"/>
basically, add this line in the ads xml
xmlns:ads="http://schemas.android.com/apk/res-auto"

Device Test ID for Admob

If you are running admob ads on an emulator then there is no ID. just use the AdManager method and set it to TEST_EMULATOR like the logcat says. If you run on an actual device with usb debugging and watch the logcat, the ID will appear in there. You can filter the logs by using "device" or "adRequest" (Case Sensitive) as the filter. After filtering using the above mentioned terms "adRequest", you'll find a line -
12-19 17:48:25.615: I/Ads(2132): To get test ads on this device, call adRequest.addTestDevice("D9XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");

Thread/ Sleep for few seconds

anywhere in oncreate
Thread background = new Thread() {
            public void run() {

                try {
                    // Thread will sleep for 3 seconds

                    sleep(6 * 1000);

                    // After 3 seconds redirect to another intent
                    Intent mainmenu = new Intent(getBaseContext(), MainActivity.class);
                    // Use fade in fade out transition animation in startActivity
                    ActivityOptions options = ActivityOptions.makeCustomAnimation(intro.this, R.anim.fade_in, R.anim.fade_out);
                    startActivity(mainmenu,options.toBundle());

                    //Remove activity
                    finish();

                } catch (Exception e) {

                }
            }
        };

        // start thread
        background.start();