How to explicitly launch the stock launcher from my activity? - android

Platform: ASUS Nexus 7, running JellyBean
I've created a kiosk application by making it the default HOME / LAUNCHER intent. I need to be able to get out of it, to the stock android launcher, via a secret code for service and maintenance.
I've searched all over, and can't find a good, succinct answer. The best I've come up with is to create an intent chooser (Intent.createChooser(Intent i, String title)) and choose between my launcher and the stock launcher. This is okay, but really a workaround.
I've tried:
PackageManager pm = this.getPackageManager();
try {
Intent i = pm.getLaunchIntentForPackage("com.android.launcher");
if (i != null)
this.startActivity(i);
}
catch (ActivityNotFoundException e) { }
and I get null for the intent every time. Yet, the stock launcher shows a package of "com.android.launcher" on my tablet. Clearly I'm getting something totally wrong here.

Step #1: Document that they need to run your app manually once out of the launcher before setting it up as the home screen.
Step #2: On that first run, use resolveActivity() to find out what the default home screen is, and hold onto the relevant pieces of information from the ResovleInfo (e.g., the component name) in some persistent data store.
Step #3: Use that data to bring up the default home screen as needed from whatever back door you have in your kiosk app.

Related

How to determine a list of Android apps that are in the app drawer

I'm using the Package Manager class to get a list of all installed applications. I tried using the following flags to determine what was a "user app" vs a "system app":
ApplicationInfo.FLAG_SYSTEM
ApplicationInfo.FLAG_UPDATED_SYSTEM_APP
This worked, but not in the exact way I wanted. I want to be able to filter a list of all apps to determine: Is this app visible in the app drawer?
I don't want to interact with the low-level system apps, as that might cause some undesirable side effects. But I want to include things like "com.google.chrome", because it's an app in the app drawer, but is technically installed as a system app.
I debugged into the ApplicationInfo list returned from the Package Manager, and found that some apps have an Int Icon value of 0 or something else (1254865, etc). So I tried:
List<ApplicationInfo> allApps = Utilities.getAllApps(mContext);
List<ApplicationInfo> visibleApps = new ArrayList<>();
for (ApplicationInfo appInfo : allApps) {
if (appInfo.icon != 0) {
visibleApps.add(appInfo);
}
}
This helped me get closer, but on my stock emulator, there's 100 "allApps", and this logic helped me drill down to 54 apps. But there's only 25 apps in the drawer...
Update: Android may have moved away from this implementation with newer API versions.
Is this app visible in the app drawer?
If, by "app drawer", you are referring to a home screen launcher, the decision of what to show there is up to the developers of the home screen launcher.
You can find out what activities are being offered to show in the home screen launcher via PackageManager and queryIntentActivities(), looking for ACTION_MAIN/CATEGORY_LAUNCHER activities. From there, you could derive a list of apps that offer those activities (bearing in mind that any app might offer 0, 1, or several such activities).

Integrating Multi Projects into single app

I have three existing apps. Now i want to combine all the three into single app.
Say i have three button, when i click button 1 then app 1 should run. And when
button 2 is clicked app 2 should run. Is it possible in android studio? have
have tried searching but nothing helped.
From this SO start application knowing package name. Just use these two lines you can launch any installed application whose package name is known:
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.example.abc");
startActivity( LaunchIntent );
for the unknown package name
PackageManager pm;
pm = getPackageManager();
// get a list of installed apps.
packages = pm.getInstalledApplications(0);
I'm going to preface this by saying I do not have any experience with Android Studio. Hopefully it bears some resemblance with its terribly simplified counterpart App Inventor.
Anywho, I would create an independent main screen (activity?) that has 3 buttons on it and paste the three existing apps' code into other screens in the same app. Each button would open its corresponding screen/app through opening a new activity.
Got the solution. I just converted the three applications to library and imported them into the main app. Now i can call any activity from any of the three app any time as required. While using package manage all the three apps would have to be installed separately. Thank you coder and himty for sparing some time to answer my question. But still i have a problem. I am actually working on watch faces. Even though i can launch any activity, i still can't change the watch face. Tried Wallpaper but we can only open the face picker & cannot set the watch face.
ComponentName unique=new ComponentName(MainActivity.this,BlackOwlBlue.class);
Intent i=new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER)
.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,unique)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);

Start default Android wallpaper chooser

I'm trying to start default android wallpaper chooser. I'm using:
Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
startActivity(intent);
This code works but it opens app chooser. I want to open "Wallpapers" directly. My minSdkVersion is set to 16.
By "default" you seem to mean the wallpaper app that came with Android OS, rather than other wallpaper apps that the device may have. You can force Android to launch a particular activity by setting the component in the intent.
Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
intent.setComponent(...);
startActivity(intent);
However, this is a risky thing to do. If you run this code on a device that doesn't have the wallpaper app that you've specified, then you will get an ActivityNotFoundException.
Do you really need to launch one particular wallpaper app? A central feature of Android is that you say what you want to do, and it finds the app to do it. I don't know what your goal is, but another function that might be helpful is PackageManager.resolveActivity. You can use it to discover, in code, what app would be launched for a particular intent.
http://developer.android.com/reference/android/content/pm/PackageManager.html
Hope this helps.

Launching Android Market Main Page from an application

I'm trying to write a launcher-like application (I'm not planning to release it, it's just for me to use) but I don't seem to find any way to launch the Market.
All of the answers I've found actually perform a search on the Market (using a uri "market://") or even worse they run the Market on a specific app page, while I'm trying to show the main page of the Market, i.e. the page shown when you run it from the launcher.
I tried using just "market://" as a Uri, without query strings, but it doesn't work; I also tried to get exactly the same "signature" of the "start activity command" that appears in the LogCat when I run the Market from the Launcher (by manually editing component, flags and categories), but it still doesn't work.
Is there any way to get it to show the main page?
Thanks in anticipation.
Intent intent = new Intent();
intent.setClassName("com.android.vending", "com.android.vending.AssetBrowserActivity");
startActivity(intent);

LauncherActivity usage

Could you please explain me purpose and usage of LauncherActivity? Documentation says that it "Displays a list of all activities which can be performed for a given intent". I understood that it should automatically build list of all activities found in application and provide their launching. Am I right?
And how to use it? I have found no examples in the web.
Google Code shows the class code itself... It has a different constructor than is described in the Android Platform API.
public abstract class LauncherActivity extends ListActivity {
Intent mIntent;
PackageManager mPackageManager;
IconResizer mIconResizer;
Your phone can have more than one possible app which handles a given intent. One great example is opening a webpage. There's the stock WebKit based browser, you can install Firefox Mobile, Dolphin Browser, Opera Mini... When they all advertise that they can handle a given intent, how does the device know which one it should pass the intent to?
Android will use a LauncherActivity to bring up a selection list of packages where each one listed is one that knows how to do something with the given intent you provide it. When you pick one, you're picking which app you want, and the intent is routed to the matching app.
From that perspective, it's a class that's really part of the Android OS support code, part of figuring out where to distribute given intents to. It's hard to see a situation where you would need to involve yourself with it directly... you should be able to just call StartActivity(Intent), which throws the intent over the wall to the OS, and at that point the device itself should fire up LauncherActivity on its own (if it's even needed).
Completely unrelated (and horribly name-disambiguated) is your application's "Launcher Activity" (documentation) -- an activity that shows in AndroidManifest.xml with an intent filter with "android.intent.action.MAIN" and "android.intent.category.LAUNCHER" ... This is how your app advertises to the system that it wants to have an icon in the device's application list, and that a specific activity should be started when that icon's clicked. You absolutely need to do that.

Categories

Resources