Thursday, October 22, 2015

Adb push-pull to your android device sdcard

First cd your path, where adb installed, copy and paste here any file to transfer..
then Shift+Right click and open command prompt.

now make sure that device is connected to pc via cable with adb driver installed on pc.

call this command now to check devices:

C:\androidsdk\platform-tools>adb devices
List of devices attached
HT359W917815    recovery

Now push any file to your device:

C:\androidsdk\platform-tools>adb push "ViperOne+9.0.0-fix_3.zip" /sdcard

it will take some time to transfer but you cant see the progress.
it will return following response after finishing transfer.

3622 KB/s (2010320545 bytes in 541.982s).

you just need device path of file to pull to your adb location

adb pull /sdcard/file.apk

Monday, October 12, 2015

SharedPreference Usage Example



Common for set values and get values

SharedPreferences sharedPreferences = getSharedPreferences("Pref_Tag", Context.MODE_PRIVATE);

Set values in Preference

SharedPreferences.Editor editor = sharedPreferences.edit();

editor.putString("String_Tag","NameToStore");
editor.putInt("Int_Tag", IntToStore);

//commit to save 
editor.commit();

Get values from Preference

String name = sharedPreferences.getString("String_Tag", "StringInCaseOfNoReturns");
int number = sharedPreferences.getString("Int_Tag", IntInCaseOfNoReturns);

Clear values from Preference

editor.clear();

Note:- You can not get preferences values, if values are stored on same activity, and you are on same page, and page is not destroyed yet, until you initialize SharedPreferences again before getting value.

Call AlertDialog in background thread, as well on Main thread.

Make sure to put this permission to manifest:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

public static void callDialog(Context context){
    AlertDialog.Builder alertDialogBiulder;
    alertDialogBiulder =
            new AlertDialog.Builder(context)
                    .setTitle("Title")
                    .setMessage("Would you like to do certain things?")
                    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                            //do certain things
                        }
                    })
                    .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    })
                    .setIcon(android.R.drawable.ic_dialog_alert);

    AlertDialog alertDialog = alertDialogBiulder.create();
    alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
    alertDialog.show();
}

Saturday, October 3, 2015

Set Custom font using extended TextView Class

Make sure to put otf, ttf to your assets folder

I choose to put assets --> fonts(folder) --> custom.otf or ttf

import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.TextView;

public class TextViewCustoma extends TextView {
    public TextViewMonaBella(Context context) {
        super(context);
        setTypeface(context);
    }

    public TextViewMonaBella(Context context, AttributeSet attrs) {
        super(context, attrs);
        setTypeface(context);
    }

    public TextViewMonaBella(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setTypeface(context);
    }

    public void setTypeface(Context context) {
        Typeface face = Typeface.createFromAsset(context.getAssets(), "fonts/" + "custom.otf");
        this.setTypeface(face);
    }
}

and set to XML

<com.example.TextViewCustom
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />