Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

How To Check New Version Of Application Android Code

private int _nVersionCode = 0;	
private boolean _bNewVersion = false;

// onCreate
     	 _nVersionCode   = this.getPackageManager()
     	.getPackageInfo(this.getPackageName(), 0).versionCode;
     	Log.d(String.valueOf(_nVersionCode), "versionCode");

// onStart loadPreferences
 public void loadPreferences() {
			//SharedPreferences settings = getSharedPreferences(F.PREFERENCES_NAME, 0);
			SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
		int nOldVersionCode =	settings.getInt("_nVersionCode",  0);// old vesion
		if(_nVersionCode > nOldVersionCode)
			_bNewVersion = true;

// onDestroy savePreferences	
	public void savePreferences() {
			SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
			SharedPreferences.Editor editor = settings.edit();
			editor.putInt("_nVersionCode", _nVersionCode); // save current version code

397LW NO topic_id

Další témata ....(Topics)


How to set different locales in android | how-to-set-different-locales-in-android

- create new folder with values in resources folder in project with extension your language code
For example:
My language is Czech (cs)
I have to create the folder values-cs in res folder

// for locale English is default
<?xml version="1.0" encoding="utf-8"?>

    <string name="app_name">App English default</string>
    <string name="action_settings">Settings English default</string>
    <string name="hello_world">Hello world</string>


// for locale Czech (cs)
<?xml version="1.0" encoding="utf-8"?>

    <string name="app_name">Aplikace česky cs</string>
    <string name="action_settings">Nastavení česky</string>
    <string name="hello_world">Ahoj světe!</string>


// for locale English US (r is region)

<?xml version="1.0" encoding="utf-8"?>

    <string name="app_name">App English Us locale</string>
    <string name="action_settings">Settings English Us locale</string>
    <string name="hello_world">Hello world from USA :)</string>


Into every values folder put strings.xml file
Translate every string from values folder into your locale.
If user selected your locale in device settings, application selects a string from the correct (proper) folder.

Download file from URL | download-file-from-url

Download image file from URL to ImageView Java Android source example code.

Context context = thisClass.this;
Drawable image = ImageOperations(context,
ImageView imgView;
imgView = (ImageView)findViewById(R.id.idImageView);

	private Drawable ImageOperations(Context ctx, String url, String saveFilename) {
		try {
			InputStream is = (InputStream) this.fetch(url);
			Drawable d = Drawable.createFromStream(is, "src");
			return d;
		} catch (MalformedURLException e) {
			return null;
		} catch (IOException e) {
			return null;

	public Object fetch(String address) throws MalformedURLException,IOException {
		URL url = new URL(address);
		Object content = url.getContent();
		return content;

android - OnClickListener must override a superclass method | android-onclicklistener-must-override-a-superclass-method

The method onClick(DialogInterface, int) of type new DialogInterface.OnClickListener(){} must override a superclass method.

Try this:
Right click on project
Select Properties
In open dialogue select Java compiler
Set Enable project specific settings
Set Compiler compliance level to 1.6




Android Studio Delete Hide Module | android-studio-delete-hide-module

To hide a module File->Project Structure Ctrl+Alt+Shift+S
In left panel click on Module which want to hide.
Click on minus symbol (-) on upper left corner of window.
Click Yes.

To delete module from disk click on module in project tree (to select) and press Delete on keyboard.

How to clear or hide an ImageView in Android | how-to-clear-or-hide-an-imageview-in-android

// solution 1
ImageView imageView = (ImageView)findViewById(R.id.myimage);
// or

// solution 2  hide ImageView

// solution 3 resize ImageView 0, 0
 hImageViewSemafor.setLayoutParams(new LinearLayout.LayoutParams(0,0));

Editace Jana Žákovská : 2013-07-18 09:43:24
Počet článků v kategorii: 397