Thursday, 10 April 2014

Android- To get all version history and creation date and time for a particular APK.

4 comments
In this post you will have to find how to get the all version details and date of creation of particular APK file.

So from that you can access the details of one of your app with other app.Its very easy to do this just follow the following steps.


Step 1) Add your apk(that you want the details) in your sdcard or the folder you want.

Step 2) Add the following code in your activity.

ZipFile zf;

final PackageManager pm = getPackageManager();

      //Name of your apk file that you want details
String apkName = "yourappname.apk";    

     //Give it to the path of your apk file 
String fullPath = Environment.getExternalStorageDirectory() 
                                       + "/"  + apkName;

PackageInfo info = pm.getPackageArchiveInfo(fullPath, 0);

try {
zf = new ZipFile(fullPath);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

ZipEntry ze = zf.getEntry("classes.dex");
long time = ze.getTime();
String s = SimpleDateFormat.getInstance().format(
new java.util.Date(time));

Step 3)Just display your all details.
              
         Toast.makeText(this,"VersionCode : " + info.versionCode + ", 
                              VersionName : " + info.versionName + ", 
                              App Creation Date : " + s,

                        Toast.LENGTH_LONG).show();


Thanks..Android rocks..:)


Read full post »

Wednesday, 12 March 2014

Display list of files with particular extension like(.txt,.png,etc)

0 comments
In this post we look into how to get filtered list with particular extension from sdcard or anywhere.

Please follow the below steps to do this:-

1)Write a method like following which simply returns a filtered list so you will used these anywhere or display this in a list view.

public ArrayList<String> File_Select()
{
      File dir_home = new File(Environment.getExternalStorageDirectory(), "");
      ArrayList<String> filteredlist = new ArrayList<String>();
     
      if (dir_home .listFiles(new NameFilter()).length > 0) 
     {
 for (File file : (dir_home .listFiles(new NameFilter())) 
           {
                   filteredlist .add(file.getName().substring(0, (file.getName().length() - 4)));        
           }
    }
      
       return filteredlist ;
}


2)Finally,write a class that will perform this filtering

class NameFilter implements FilenameFilter 
{
public boolean accept(File dir, String name) 
        {
           return (name.endsWith(".txt") ||name.endsWith(".TXT"));
}
}

Done.Thanks..Android Rocks..:)
Read full post »

Monday, 10 February 2014

Open an pop-up window with animation.

0 comments
1)First you have to create a method that display an pop-up.

         public void display_popup() {
                LayoutInflater layoutInflater = (LayoutInflater) getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView= layoutInflater.inflate(R.layout.follow_leader, null);

PopupWindow popupWindow = new PopupWindow(popupView,                                                                                     LayoutParams.FILL_PARENT,
            LayoutParams.FILL_PARENT);
popupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 0);
         }

2)Next you have to write an animation XML for your pop-up inside res/anim folder.

fade_in.xml
                <set xmlns:android="http://schemas.android.com/apk/res/android"
                                android:fillAfter="true">
                   <alpha android:fromAlpha="0.0"
                               android:toAlpha="1.0"
                              android:duration="3000"/> //Time in milliseconds
                </set>
fade_out.xml
              <set xmlns:android="http://schemas.android.com/apk/res/android"
                    android:fillAfter="true" >
                   <alpha  android:duration="3000"
                               android:fromAlpha="1.0"
                              android:toAlpha="0.0" />
                </set>

3)After that you have to write an style for your pop-up inside values/style.xml file.

          <style name="PopupWindowAnimation">
                 <item name="android:windowEnterAnimation">@anim/fade_in</item>
                  <item name="android:windowExitAnimation">@anim/fade_out</item>
          </style>

4)Finally you set this style to pop-up by writing the below in your display_popup() method.

          popupWindow.setAnimationStyle(R.style.PopupWindowAnimation);

Done..android rocks..
Read full post »

Monday, 13 January 2014

Animation in Android

4 comments
In this post you find the animation for transition between two screens.

First you have to create anim folder inside /res folder.and write the following XML in that.

slide_in.xml
<?xml version="1.0" encoding="utf-8"?>
<translate 
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:duration="@android:integer/config_longAnimTime" 
      android:fromXDelta="100%p" 
      android:toXDelta="0%p">
</translate>

slide_out.xml
<?xml version="1.0" encoding="utf-8"?>
<translate
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:duration="@android:integer/config_longAnimTime" 
      android:fromXDelta="0" 
      android:toXDelta="-100%p">
</translate>

fade_in.xml
<set xmlns:android="http://schemas.android.com/apk/res/android" 
     android:fillAfter="true">
     <alpha android:fromAlpha="0.0" 
            android:toAlpha="1.0"
            android:duration="5000"/> 
</set>

fade_out.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true" >
   <alpha
        android:duration="5000"
        android:fromAlpha="1.0"
        android:toAlpha="0.0" />
</set>

slide_in_opp.xml
<?xml version="1.0" encoding="utf-8"?>
<translate 
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:duration="@android:integer/config_longAnimTime" 
      android:fromXDelta="-100%p" 
      android:toXDelta="0%p">
</translate>

slide_out_opp.xml
<?xml version="1.0" encoding="utf-8"?>
<translate
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:duration="@android:integer/config_longAnimTime" 
      android:fromXDelta="0" 
      android:toXDelta="100%p">
</translate>

Next,You just include this following in your java code to use this animations.

       overridePendingTransition(R.anim.slide_in, R.anim.slide_out);

Done..
Thanks.
Read full post »

Tuesday, 26 November 2013

Auto-complete Text view in android.

0 comments
In this post we look into the auto complete text view and how it will be used in your app.

Steps 1)Include the Auto-complete Text-view in your XML as following:-

<AutoCompleteTextView
                    android:id="@+id/txt_autoview"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:singleLine="true"
                    android:text=""
                    android:textColor="#000000"
   />

Steps 2)Implements an interface as following:-

public class Depots extends Activity implements TextWatcher {

AutoCompleteTextView  txt_market;
List<String> market;

}

Steps 3)Add the following in your onCreate():-

market = new ArrayList<String>();
txt_market = (AutoCompleteTextView) findViewById(R.id.txt_autoview);

//Before you setting an adapter to the textview you have to add an items to the arraylist.

txt_market.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, market));


Steps 4)Add the Unimplemented methods for your Text Watcher interface.


Thanks..
Read full post »

Thursday, 14 November 2013

How To Change Modes Of Phone(Normal,Silent,vibrate) Programmatically.

0 comments
Today we have seen how to change the modes of phone using audio manager in Android.

1)Declare the Audio manager class.

   AudioManager am;

   am= (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);

2)Next, we have to perform an action on particular button to change the mode.

   @Override
   public void onClick(View view) {

        switch (view.getId())
        {

   //For Normal Mode
            case R.id.btn_normal:

                         am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
            break;

   //For Silent Mode
            case R.id.btn_silent:

                        am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
            break;

   //For Vibrate Mode
            case R.id.btn_dnd:
          
                      am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
          break;
      }
 }

Thanks..
Read full post »

Thursday, 31 October 2013

Webview Demo in android

0 comments
Today,we look into a web-view to open a simple link without using browser.

1)Add the web-view in your XML with the following.

        <WebView
        android:id="@+id/webView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

2)Then write the following code in your activity to display the link in your web-view.

        WebView web;

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

web = (WebView) findViewById(R.id.webView1);

web.setWebViewClient(new myWebClient());
web.loadUrl("http://uniqueandroidtutorials.blogspot.in");
}

public class myWebClient extends WebViewClient {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
}

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub

view.loadUrl(url);
return true;

}
}

// To handle "Back" key press event for WebView to go back to previous screen.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && web.canGoBack()) {
web.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}

Done..Thanks..

To download the demo Click Here..
Read full post »
 

Copyright © Unique Android Tutorial.. Design by Free CSS Templates | Blogger Theme by BTDesigner | Powered by Blogger