I'm new to android. I've developed a library and integrated the same with two apps. And I have broadcast receiver for screen unlock in that library.and have stored unlock count in sharedpreferences. If the count is 2 then i ll show popup.and each application will be having its own private sharedpreferences. Whenever I receive unlock broadcast and the count is 2 then i'll show a pop up message.here, Since I have integrated the lib with two app,two popup msgs are coming up.I just want to show only one popup from any one of the app.I couldn't find a solution for this.How it can be achieved. any idea pls?
Thanks
Jeyanthi
You can list the installed applications on the current device using the Package Manager, like this :
PackageManager pm = getPackageManager();
pm.getInstalledPackages(0);
Then each PackageInfo contains the package name (com.yourname.package1, com.yourname.package2). You will also have the install and last update time (see the PackageInfo reference).
Then you could on each of those app detect if another one exist and then have some kind of priority. For example, only the last installed app display a popup, or use a priority of your own (application A before application B).
Related
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).
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);
I am looking for a way to automatically open an application on Android. Something like QTP on windows. I read about quite a few testing tools for Android that need the phone to be connected to the laptop via USB. Is it possible to code an android application that can open another specific application on the device automatically?
I understand that if it is my application or an open source one, I can get the UI element and perform click or type into it automatically using code but how can I access UI elements of other apps on the device.
Example: My app should be able to open my phone keypad and type in a number or open an app like Truecaller and type into the textview on main screen? Something like web automation but for Android device. Any help would be appreciated! Thank you!
You can use Intents:
//consider context as being the Context of your current app
PackageManager packageManager = context.getPackageManager();
Intent intent = packageManager.getLaunchIntentForPackage(PACKAGE_NAME);
context.startActivity(intent);
device.wait(Until.hasObject(By.pkg(PACKAGE_NAME)), 10000); //this is a UiAutomator method to wait for the application to be started (or 10 seconds).
You can also use solo UiAutomator methods: open the apps menu, click on the app icon. You can see an example here
How to check if intent or app has started ?
My use case is I am showing up notifications through my app and I want to clear them all via myBuilder.cancelAll() if default messaging app has started since my app shows sms notifications. So I am kind of looking for something like:
if (smsAppStarted) {
myBuilder.cancelAll();
}
Thanks
To check if an app has started:
Get the package name of the sms app you want to check.
Then refer to my answer here:
Android how to know an app has been started and range apps priority according the starting times
By using that code, the list taskInfo will contain the list of all apps currently running. Search that list using the package name of the sms app. If it is present in that list, it means that that app has started and currently running.
If I get you right, you need to determine, if another app is currently running. If so, then use this solution.
I want to implement an app which can detect what app launched, to do something with that!
for example I have a list of installed applications in my app and mark one favorite app. and when I start that marked app from default launcher or anyway, I could detect it and do something with that by a background service or broadcast receiver(For example launch a toast message).
How can I do this?
this isnt possible.. to be able to monitor all intents would make android extremely insecure
http://groups.google.com/group/andro...ddc9d36a24d77b
but there are ways to know when an application is launched. you just have to be creative.
this will give you a list of all the applications running.
Code:
ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> runningAppProcessInfo = am.getRunningAppProcesses();
however to know when an app is launched you would need a timed loop and then check between versions of the List to see if there is a new app. this would suck the juice and be inneficient
AppProtector seem to access the eventlog. maybe you could have a ContentObserver attached to the event log
http://developer.android.com/referen.../EventLog.html
http://developer.android.com/referen...tObserver.html
EDIT
Interesting.
I also found this which solve your problem.
When you open any app from launcher below code will return the info of opened app so now you need to compare a package name with your favourite app package name which you already stored in your app database.
Code:
String str = ((ActivityManager.RunningTaskInfo)this.am.getRunningTasks(1).get(0)).topActivity.getPackageName();