1

私は現在このコードを使用しています:

ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);

if(taskInfo.get(0).topActivity.getPackageName().equalsIgnoreCase("com.android.settings")){
    ////Do Action       
}

現在のアクティビティが com.android.settings (Android 設定ページ) であるかどうかを確認できます。パッケージcom.android.setting内の特定のクラスファイルに置き換えようとしています。

 if(taskInfo.get(0).topActivity.getPackageName().equalsIgnoreCase("com.android.settings.LocationSettings") || taskInfo.get(0).topActivity.getPackageName().equalsIgnoreCase("com.android.settings/.LocationSettings")){
         ////Do Action

     }

私の問題は、このコードが「LocationSettings」を検出しないことです。

ここでは Android のソース コードと Cyanogen のソースを参照しています

4

1 に答える 1

0

The class you are checking for (com.android.settings.LocationSettings) is not a subclass of Activity so it would not show up in a list of activities.

In addition, getPackageName() only returns the package. So you would need to check the class-name against getClassName() separately.

于 2013-02-11T12:27:59.423 に答える