Skip to content

Commit

Permalink
提交事件广播接收器;
Browse files Browse the repository at this point in the history
获取手机栈顶应用
  • Loading branch information
马天宇 committed Mar 30, 2015
1 parent 7693d3a commit 9bc25d4
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 5 deletions.
4 changes: 0 additions & 4 deletions src/com/litesuits/common/receiver/PhoneReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ public void onReceive(Context context, Intent intent) {
}
}
}

if (state != null) {

}
}
}

Expand Down
85 changes: 85 additions & 0 deletions src/com/litesuits/common/receiver/TimeReceiver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.litesuits.common.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import com.litesuits.android.log.Log;

/**
* 时间广播
*
* @author MaTianyu
* @date 2015-03-09
*/
public class TimeReceiver extends BroadcastReceiver {

private static final String TAG = "TimeReceiver";

private TimeListener timeListener;

@Override
public void onReceive(Context context, Intent intent) {
if (Log.isPrint) {
Log.i(TAG, "action: " + intent.getAction());
Log.d(TAG, "intent : ");
Bundle bundle = intent.getExtras();
for (String key : bundle.keySet()) {
Log.d(TAG, key + " : " + bundle.get(key));
}
}
if (Intent.ACTION_TIME_TICK.equals(intent.getAction())) {
if (timeListener != null) {
timeListener.onTimeTick();
}
} else if (Intent.ACTION_TIME_CHANGED.equals(intent.getAction())) {
if (timeListener != null) {
timeListener.onTimeChanged();
}
} else if (Intent.ACTION_TIMEZONE_CHANGED.equals(intent.getAction())) {
if (timeListener != null) {
timeListener.onTimeZoneChanged();
}
}
}

public void registerReceiver(Context context, TimeListener timeListener) {
try {
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_TIME_CHANGED);
filter.addAction(Intent.ACTION_TIME_TICK);
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
filter.setPriority(Integer.MAX_VALUE);
context.registerReceiver(this, filter);
this.timeListener = timeListener;
} catch (Exception e) {
e.printStackTrace();
}
}

public void unRegisterReceiver(Context context) {
try {
context.unregisterReceiver(this);
} catch (Exception e) {
e.printStackTrace();
}
}

public static interface TimeListener {
/**
* 时区改变
*/
public void onTimeZoneChanged();

/**
* 设置时间
*/
public void onTimeChanged();

/**
* 每分钟调用
*/
public void onTimeTick();
}
}
22 changes: 21 additions & 1 deletion src/com/litesuits/common/utils/PackageUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.litesuits.common.utils;

import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
Expand All @@ -25,7 +26,7 @@ public class PackageUtil {
/**
* App installation location flags of android system
*/
public static final int APP_INSTALL_AUTO = 0;
public static final int APP_INSTALL_AUTO = 0;
public static final int APP_INSTALL_INTERNAL = 1;
public static final int APP_INSTALL_EXTERNAL = 2;

Expand Down Expand Up @@ -72,6 +73,25 @@ public static void goToInstalledAppDetails(Context context, String packageName)
context.startActivity(intent);
}


/**
* 获取指定程序信息
*/
public static ActivityManager.RunningTaskInfo getTopRunningTask(Context context) {
try {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
// 得到当前正在运行的任务栈
List<ActivityManager.RunningTaskInfo> runningTasks = am.getRunningTasks(1);
// 得到前台显示的任务栈
ActivityManager.RunningTaskInfo runningTaskInfo = runningTasks.get(0);
return runningTaskInfo;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}


public static int getAppVersionCode(Context context) {
if (context != null) {
PackageManager pm = context.getPackageManager();
Expand Down

0 comments on commit 9bc25d4

Please sign in to comment.