Last active
April 5, 2018 08:04
-
-
Save ilwsm/b961c2b6cfc6666bcbbb2a617f6f8d9e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in adb shell I sent this commands for simulating dialog's appears: (Airplane dialog (https://i.stack.imgur.com/Qatww.jpg) is showing on LG G2 phone, on other phones, this dialog may not appear. ) | |
//"settings put global airplane_mode_on 1;am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true" | |
//"settings put global airplane_mode_on 0;am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false" | |
//or start another my dialog-style application, like: | |
// am start -n "org.kinocat.goodsearcher/org.kinocat.goodsearcher.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER | |
//but always topActivity = my main activity . | |
package org.kinocat.myapplication; | |
import android.app.Activity; | |
import android.app.ActivityManager; | |
import android.content.ComponentName; | |
import android.content.res.Resources; | |
import android.graphics.drawable.StateListDrawable; | |
import android.os.Bundle; | |
import android.support.v4.content.ContextCompat; | |
import android.support.v7.app.AlertDialog; | |
import android.support.v7.app.AppCompatActivity; | |
import android.view.View; | |
import android.widget.ArrayAdapter; | |
import android.widget.Spinner; | |
import java.util.List; | |
public class MainActivity extends AppCompatActivity { | |
private Spinner spinner; | |
private ActivityManager manager; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
} | |
@Override | |
protected void onResume() { | |
super.onResume(); | |
android.util.Log.d("", "onResume"); | |
} | |
@Override | |
protected void onPause() { | |
super.onPause(); | |
android.util.Log.d("", "omPause"); | |
} | |
@Override | |
public void onWindowFocusChanged(boolean hasFocus) { | |
super.onWindowFocusChanged(hasFocus); | |
manager = (ActivityManager)getSystemService(Activity.ACTIVITY_SERVICE); | |
new Thread(){ | |
@Override | |
public void run() { | |
for (int i = 0; i < 2; i++) { | |
try { | |
Thread.sleep(1000); | |
} catch (InterruptedException e) { | |
} | |
showTopActivity(); | |
} | |
} | |
}.start(); | |
} | |
private void showTopActivity() { | |
final List<ActivityManager.RunningTaskInfo> runningTasks = manager.getRunningTasks(1); | |
//this ugly code just for testing :) | |
int i = 0; | |
for (ActivityManager.RunningTaskInfo info : runningTasks) { | |
i++; | |
android.util.Log.d("FreakMurderer", i + ":" + info.topActivity); | |
//android.util.Log.d("FreakMurderer", i + ":" + info.baseActivity); | |
android.util.Log.d("FreakMurderer", "--"); | |
} | |
final ComponentName componentName = runningTasks.get(0).topActivity; | |
final String className = componentName.getClassName(); | |
//android.util.Log.d("FreakMurderer", "className:" + className); | |
if (className.equals("YOUR_EXPECTED_ACTIVITY_CLASS_NAME")) { | |
// do something | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment