Small app がアクティブであることを検出するにはどうすればよいですか?
ミニアプリのパッケージ名は com.sony.nfx.app.plusone.calculator です。
getRunningTasks では、起動したアプリの一覧を取得できると思います。
ただし、ミニアプリは対象外です。
getRunningTasks で、起動したミニアプリのパッケージ名を取得できていません。
ミニアプリの検出をしたい。何か良い方法があれば教えてください。
**
プロセスのリストを取得するだけではありません。ユーザーが操作を開始したことを検出したい。
**
ありがとうございました。
sony タブレット S Android 4.0.3
アンドロイド Java コード
public void run_task_log(){
ArrayList<String> appList = new ArrayList<String>();
ActivityManager activityManager = (ActivityManager)getSystemService(ACTIVITY_SERVICE);
List<RunningAppProcessInfo> processList = activityManager.getRunningAppProcesses();
for(RunningAppProcessInfo process : processList) {
//Log.i(TAG,"pid:"+process.pid);
//Log.i(TAG,"processName:"+process.processName);
appList.add( (String) "" + process.pid + ":" +process.processName);
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, appList);
setListAdapter(adapter);
List<RunningTaskInfo> taskList = activityManager.getRunningTasks(10);
for(RunningTaskInfo task : taskList) {
Log.d("ActivityManager","task.topActivity.getPackageName():"+task.topActivity.getPackageName());
}
List<RunningServiceInfo> serviceList = activityManager.getRunningServices(30);
for(RunningServiceInfo serv : serviceList) {
Log.d("ActivityManager","PID:"+serv.pid+":serv.getPackageName():"+serv.service.getPackageName());
Log.d("ActivityManager","PID:"+serv.pid+":serv.clientPackage():"+serv.clientPackage);
}
PackageManager packageManager = getPackageManager();
ActivityManager activityManager1 = ((ActivityManager) getSystemService(ACTIVITY_SERVICE));
List<RunningTaskInfo> runningTask = activityManager1.getRunningTasks(100);
ArrayList<CharSequence> activityNameList = new ArrayList<CharSequence>();
if (runningTask != null) {
for (RunningTaskInfo task : runningTask) {
try {
Log.d("ActivityManager","packageManager.getApplicationLabel():"+packageManager.getApplicationLabel(packageManager.getApplicationInfo(task.topActivity.getPackageName(), 0)));
} catch (NameNotFoundException e) {
Log.e("ERROR", e.toString());
}
}
}
ActivityManager activityManager2 = (ActivityManager) getSystemService(Service.ACTIVITY_SERVICE);
String className = activityManager.getRunningTasks(3).get(0).topActivity.getClassName();
Log.d("ActivityManager","className:"+className);
}
Logcat ログ
12-11 16:53:36.360: D/T2MDMService(3775): ////// ID Service Timer Start ///
12-11 16:53:36.370: D/ActivityManager(3775): task.topActivity.getPackageName():com.sony.nfx.app.launcher2
12-11 16:53:36.370: D/ActivityManager(3775): task.topActivity.getPackageName():com.anetm.www.apprunlist
12-11 16:53:36.380: D/ActivityManager(3775): PID:434:serv.getPackageName():com.android.smspush
12-11 16:53:36.380: D/ActivityManager(3775): PID:434:serv.clientPackage():null
12-11 16:53:36.380: D/ActivityManager(3775): PID:2996:serv.getPackageName():com.sony.nfx.app.plusone.calculator
12-11 16:53:36.380: D/ActivityManager(3775): PID:2996:serv.clientPackage():null
12-11 16:53:36.380: D/ActivityManager(3775): PID:3174:serv.getPackageName():com.android.providers.media
12-11 16:53:36.380: D/ActivityManager(3775): PID:3174:serv.clientPackage():null
12-11 16:53:36.380: D/ActivityManager(3775): PID:3534:serv.getPackageName():com.sony.nfx.hwmonitorservice
12-11 16:53:36.390: D/ActivityManager(3775): PID:3534:serv.clientPackage():null
12-11 16:53:36.390: D/ActivityManager(3775): PID:313:serv.getPackageName():com.google.android.location
12-11 16:53:36.390: D/ActivityManager(3775): PID:313:serv.clientPackage():null
12-11 16:53:36.390: D/ActivityManager(3775): PID:0:serv.getPackageName():com.google.android.talk
12-11 16:53:36.390: D/ActivityManager(3775): PID:0:serv.clientPackage():null
12-11 16:53:36.390: D/ActivityManager(3775): PID:3522:serv.getPackageName():com.sony.nfx.app.wappushdbinit
12-11 16:53:36.390: D/ActivityManager(3775): PID:3522:serv.clientPackage():null
12-11 16:53:36.390: D/ActivityManager(3775): PID:249:serv.getPackageName():com.android.systemui
12-11 16:53:36.390: D/ActivityManager(3775): PID:249:serv.clientPackage():null
12-11 16:53:36.390: D/ActivityManager(3775): PID:3508:serv.getPackageName():com.sony.automagic.blservice
12-11 16:53:36.390: D/ActivityManager(3775): PID:3508:serv.clientPackage():null
12-11 16:53:36.390: D/ActivityManager(3775): PID:313:serv.getPackageName():com.google.android.location
12-11 16:53:36.390: D/ActivityManager(3775): PID:313:serv.clientPackage():null
12-11 16:53:36.390: D/ActivityManager(3775): PID:2984:serv.getPackageName():com.sony.smallapp.plusoneservice
12-11 16:53:36.390: D/ActivityManager(3775): PID:2984:serv.clientPackage():null
12-11 16:53:36.390: D/ActivityManager(3775): PID:328:serv.getPackageName():com.sony.nfx.inputmethod
12-11 16:53:36.400: D/ActivityManager(3775): PID:328:serv.clientPackage():android
12-11 16:53:36.400: D/ActivityManager(3775): PID:375:serv.getPackageName():com.android.stk
12-11 16:53:36.400: D/ActivityManager(3775): PID:375:serv.clientPackage():null
12-11 16:53:36.400: D/ActivityManager(3775): PID:167:serv.getPackageName():com.google.android.backup
12-11 16:53:36.400: D/ActivityManager(3775): PID:167:serv.clientPackage():null
12-11 16:53:36.400: D/ActivityManager(3775): PID:375:serv.getPackageName():com.android.phone
12-11 16:53:36.400: D/ActivityManager(3775): PID:375:serv.clientPackage():null
12-11 16:53:36.400: D/ActivityManager(3775): PID:375:serv.getPackageName():com.mbm.mbmservice
12-11 16:53:36.400: D/ActivityManager(3775): PID:375:serv.clientPackage():null
12-11 16:53:36.400: D/ActivityManager(3775): PID:249:serv.getPackageName():com.android.systemui
12-11 16:53:36.400: D/ActivityManager(3775): PID:249:serv.clientPackage():android
12-11 16:53:36.400: D/ActivityManager(3775): PID:3495:serv.getPackageName():com.sony.automagic.ui
12-11 16:53:36.400: D/ActivityManager(3775): PID:3495:serv.clientPackage():null
12-11 16:53:36.400: D/ActivityManager(3775): PID:313:serv.getPackageName():com.google.android.gsf
12-11 16:53:36.400: D/ActivityManager(3775): PID:313:serv.clientPackage():null
12-11 16:53:36.400: D/ActivityManager(3775): packageManager.getApplicationLabel():ホーム
12-11 16:53:36.400: D/ActivityManager(3775): packageManager.getApplicationLabel():AppRunList
12-11 16:53:36.410: D/ActivityManager(3775): className:com.android.launcher2.Launcher
12-11 16:53:36.410: D/T2MDMService(3775): ////// ID Service Timer End ///