Skip to main content

Featured

Android studio “SDK tools directory is missing”

Following 2 possible solutions will resolve this problem :  Solution1 : To fix the problem, it was required that I list the path to my corporate PAC file by using  Configure -> "Appearance and Behavior" -> System Settings -> HTTP Proxy . I selected "Automatic proxy configuration url:" Delete your  ~/.Android*  folders (losing all of your settings :/). Run Android Studio. It will show you a welcome wizard where it tries to download the SDK again (and fails due to my rubbish internet). Click the X on the wizard window. That will enable you to get to the normal welcome dialog. Go to Settings->Project Defaults->Project Structure and change the Android SDK location to the correct one. Solution 2 : To fix the problem, it was required that I list the path to my corporate PAC file by using  Configure -> "Appearance and Behavior" -> System Settings -> HTTP Proxy . I selected "Automatic proxy configuration url:&quo

Best Working Code to set event Listener for Home button of Device,Android

I Found issue of ,the method onKeyDown() will not work (in Latest version of
Android 4.0 and after vertions) ,when user press home button of the Device in LegalPlex Project..

i resolved this issue by using a method of:

1)public void onUserLeaveHint() { // this only executes when Home is <span id="IL_AD7" class="IL_AD">selected</span>.
        // do stuff
        super.onUserLeaveHint();
        System.out.println("HOMEEEEEEEEE");
    }
Note : Place this method on below of onCreate() method,then u wil get..

2) above method will raised issues like,it called when user press back button and also in other cases..
to overcome use this :

@Override
    protected void onPause() {
        super.onPause();
        if(isApplicationSentToBackground(this)){
            SharedVariables.is_application_is_paused=true;
           
                       
            if(mp.isPlaying()){
                SharedVariables.is_mp_music_played=true;
                mp.pause();
            }
           
            if(mp1.isPlaying()){
                SharedVariables.is_mp1_music_played=true;
                mp1.pause();
            }
        }
    }
   
    public boolean isApplicationSentToBackground(final Context context) {
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<RunningTaskInfo> tasks = am.getRunningTasks(1);
        if (!tasks.isEmpty()) {
            ComponentName topActivity = tasks.get(0).topActivity;
            if (!topActivity.getPackageName().equals(context.getPackageName())) {
                return true;
            }
        }
        return false;
    }
   
   
    @Override
    protected void onRestart() {
       
            super.onRestart();
            if(SharedVariables.is_application_is_paused)
            {
                SharedVariables.is_application_is_paused=false;   
               
                if(SharedVariables.is_mp1_music_played){                   
                    mp1=MediaPlayer.create(getApplicationContext(), R.raw.sample1);//Background music that plays continuously..
                    mp1.start();
                    mp1.setLooping(true);
                   
                }else   if(SharedVariables.is_mp_music_played){
                    mp=MediaPlayer.create(getApplicationContext(), R.raw.mad_plans_short); //Music that plays when clicked the spin button.
                    mp.start();
                }
               
                SharedVariables.is_mp_music_played=false;
                SharedVariables.is_mp1_music_played=false;
            }
    }

->here case is stopped  music when user press home button ,and play music when application opened.
and give permission in Manifest file:
<uses-permission android:name="android.permission.GET_TASKS" />   

i implemented this in my SlotGame Project....

Comments

  1. is the application developed in phonegap? or a native android app? what does the span id represent?

    How to do this on a native android app

    ReplyDelete
    Replies
    1. Hi,

      This application was developed in Native Android App only.
      don't worry about that span id,its commented one and i didn't use that span id
      in above source code.

      Thanking you,
      @Pavan

      Delete
  2. Hi pavan,

    Thanks for sharing the valuable code. It was very helpful

    ReplyDelete

Post a Comment