Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start Activity Android with class name

I am using Following Code to start setting I want to launch the setting activity which is started by android ins

PackageList allowedAppsPackageName=CallHelper.Ds.getPackageList();
            PackageManager manager = CallDetectService.packageManager;
            Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
            mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

        final List<ResolveInfo> apps = manager.queryIntentActivities(mainIntent, 0);
        Collections.sort(apps, new ResolveInfo.DisplayNameComparator(manager));
        final int count = apps.size();
        ResolveInfo info=new ResolveInfo();;
        GridViewAppList.clear();

                 for (int i = 0; i < count; i++) 
                 {

                        info= apps.get(i);
                        if(info.activityInfo.applicationInfo.packageName.contains("setting"))
                            break;

                 }
                ApplicationInfo application = new ApplicationInfo();

                application.title = info.loadLabel(manager);
                application.setActivity(new ComponentName(
                        packageName,
                        info.activityInfo.name),
                        Intent.FLAG_ACTIVITY_NEW_TASK
                        | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                application.icon = info.activityInfo.loadIcon(manager);
                application.packagename=packageName;
                Log.i("PKG", application.packagename+" "+packageName+" "+info.activityInfo.name);
                GridViewAppList.add(application);
like image 585
Tushar Avatar asked Aug 10 '13 10:08

Tushar


People also ask

What does finish () do in Android?

On Clicking the back button from the New Activity, the finish() method is called and the activity destroys and returns to the home screen.

Can we create activity without UI in Android?

Explanation. Generally, every activity is having its UI(Layout). But if a developer wants to create an activity without UI, he can do it.

How can we call method in activity from non activity class?

use interface to communicate with activity from non activity class. create colorChange() in interface and get the instance of interface in non activity class and call that method.


1 Answers

You can use this snippet to open Settings Activity :

Intent intent=new Intent();
intent.setComponent(new ComponentName("com.android.settings", "com.android.settings.Settings"));
startActivity(intent);

If you do not know what Activity you have to open,you can find it's name and it's package name as I mentioned here.

like image 54
hasanghaforian Avatar answered Sep 23 '22 06:09

hasanghaforian