Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.9 kB
2
Indexable
Never
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.widget.Toast;

import java.util.List;

public class AppActivityFetcher {
    public static void getNonExportedActivities(Context context) {
        PackageManager packageManager = context.getPackageManager();

        try {
            // Lấy tất cả các ứng dụng đã cài đặt
            List<ResolveInfo> resolveInfos = packageManager.queryIntentActivities(
                    new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER),
                    PackageManager.GET_ACTIVITIES);

            for (ResolveInfo resolveInfo : resolveInfos) {
                ActivityInfo[] activities = packageManager.getPackageInfo(resolveInfo.activityInfo.packageName, PackageManager.GET_ACTIVITIES).activities;

                if (activities != null) {
                    for (ActivityInfo activity : activities) {
                        if (!activity.exported) { // Kiểm tra nếu exported = false
                            String activityName = activity.name;
                            String packageName = activity.packageName;
                            boolean enabled = activity.enabled;

                            System.out.println("Package: " + packageName);
                            System.out.println("Activity Name: " + activityName);
                            System.out.println("Exported: " + activity.exported);
                            System.out.println("Enabled: " + enabled);
                            System.out.println();
                        }
                    }
                }
            }
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }
}
Leave a Comment