Create secondary app manager such as (facebook app manager) - android

Is there away to install secondary app when the user installs the APK?
The secondary app porpoise is to save local data that will be shared between multiple apps and detect + listen to app removal package.
I have seen that Facebook is doing something similar they have 2 apps called (Facebook App installer + Facebook App Manager)

you can do with the help of package name of the other app.
so once your first app is installed in phone , at some point yo can check for other app with the help of package name if it is installed or not by using below code
PackageManager pm = getPackageManager();
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
return true;
} catch (PackageManager.NameNotFoundException e) {
}
and if that is not the case you can take user to play store to get it installed.
Happy Coding :) !!

Related

Finding installed android applications that can install other applications

I want to find applications that the user has allowed to install other applications.
I know that if I look for "android.permission.INSTALL_PACKAGES" I would find mainly system packages that can install applications but I'd like to find applications (like the browser, or email) that the user allowed to install applications.
I'm trying the following code to loop through all applications which is obviously wrong as I can not find Chrome, who I allowed to install applications. Any suggestion how to achieve this?
final PackageManager pm = getPackageManager();
for (final PackageInfo pi : pm.getInstalledPackages(GET_PERMISSIONS)) {
try {
Context pcontext = createPackageContext(pi.packageName, 0);
if (ContextCompat.checkSelfPermission(pcontext, Manifest.permission.INSTALL_PACKAGES) == PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "Application able to install other apps: " + pi.packageName);
}
}catch (SecurityException|PackageManager.NameNotFoundException ex){
Log.d(TAG, "Exception " + ex);
}
}
If I'm understanding your question correctly, the answer is "that's not allowed."
Third-party apps can't actually install applications (see https://developer.android.com/reference/android/Manifest.permission#INSTALL_PACKAGES). Apps like Chrome call the system installer, they don't get install privileges themselves, so that's why you don't see them on the list.
And there's no way to check which other apps have launched an installer process. That would be a security/privacy issue, as it would mean any app could retrieve a list of other apps a user has installed on their device! Each process is assigned its own linux id and can't directly access data for any other app (i.e. it's sandboxed), using the exact same mechanism, in fact, that prevents one user from querying another user's data on a standard linux system.

How one does an app detect wheteher another app is installed and signed up by the user in their phone?

There are many android apps promoting other apps and gives rewards for installing the apps.So actually how , in android it is done - that in an app we can check the user's android pone if the targeted app is installed or not and even more than that they check whether an user is signed up for that app or not and then they give the rewards once they find out that the other app is installed and signed up by user..(I am obviously not talking about launching intent to open the app which easilyb detects wheteher the app is installed or open play store).
Thanks in advance for help..
Check if application is installed with packagename
Ask Question
Try this:
private boolean isPackageInstalled(String packagename, PackageManager packageManager) {
try {
packageManager.getPackageInfo(packagename, 0);
return true;
} catch (NameNotFoundException e) {
return false;
}
}
It attempts to fetch information about the package whose name you passed in. Failing that, if a NameNotFoundException was thrown, it means that no package with that name is installed, so we return false.
Note that we pass in a PackageManager instead of a Context, so that the method is slightly more flexibly usable and doesn't violate the law of Demeter. You can use the method without access to a Context instance, as long as you have a PackageManager instance.
public void someMethod() {
// ...
PackageManager pm = context.getPackageManager();
boolean isInstalled = isPackageInstalled("com.somepackage.name", pm);
// ...
}

Android: how to verify package is genuine

In one of my apps, I would like to detect if the user has got another app of mine installed.
This code works:
PackageManager pm = mAppContext.getPackageManager();
try {
pm.getPackageInfo("com.example.packagename", PackageManager.GET_ACTIVITIES);
// do something
} catch (PackageManager.NameNotFoundException e) {
// nothing to do
}
But I wonder how I can verify that the user has genuinely downloaded the app from Google Play. I guess it would be possible to install a non genuine package with the same package name, right?
PackageManager has a method getInstallerPackageName that for given package name gives you name of the installer. For pre-loaded(unless they are not installed from other 'market' like SamsungApps) and self-installed applications will return null. For applications originating from Google Play you should get com.android.vending. And I don't think that you are able to install two applications with the same package names declared in the manifest.

Is it possible to install an application via adb but still get Google Market updates?

My company is distributing both the hardware (samsung galaxy tab 10.1) and the software (my application) to our customers.
My intent is to "skip" the google account linking and use adb to install my production-signed application directly onto the tablet (identical as the apk I upload to google market). This will allow me to pre-configure the tablets for our customers, change the screen background to our logo, etc.
However, once the tablet has been delivered to the customer, I would want them to attach a google account to the tablet, and still be able to get updates from my application via the marketplace. In my testing, the application I manually installed never shows up in the list of applications in google market.
Is this possible?
Tim
UPDATE: I ended up writing a "Launcher" application which I will manually install on the device. It has one activity with the theme:
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen"
the activity has this code:
public class LauncherActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
startApplication("applicationnamehere");
finish(); // this kills the activity immediately.
}
public void startApplication(String application_name){
boolean successfulLaunch = false;
try{
Intent intent = new Intent("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
List<ResolveInfo> resolveinfo_list = getPackageManager().queryIntentActivities(intent, 0);
for(ResolveInfo info:resolveinfo_list){
if(info.activityInfo.packageName.equalsIgnoreCase(application_name)){
Intent launch_intent = new Intent("android.intent.action.MAIN");
launch_intent.addCategory("android.intent.category.LAUNCHER");
launch_intent.setComponent(new ComponentName(info.activityInfo.packageName, info.activityInfo.name));
launch_intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(launch_intent);
successfulLaunch = true;
break;
}
}
}
catch (ActivityNotFoundException e) {
launchMarket();
}
if (!successfulLaunch)
launchMarket();
}
private void launchMarket() {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=packagenamegoeshere"));
startActivity(intent);
}
}
You can stuff the constants into strings.xml.
It works well with the only issue being that it hangs around on the home screen even after my main application has been installed by the user. Since it (by default) tries to launch the LAUNCHER for my application, its not the end of the world.
It should be possible - look into what Titanium Backup does. It has a Market Doctor feature that can re-establish links to the Android Market after you restore the apks and data files using Titanium Backup.
You could also try loading a factory image onto some phone or tablet, skipping the account creation process, and seeing what the market database looks like for the included apps such as Youtube, Facebook, Gmail, Maps, etc.
In my testing, the application I manually installed never shows up in the list of applications in google market
This is because you didn't publish your app in Android market.
Is this possible?
As long as you use the same package name, maintain version increment properly in AndroidManifest.xml and signed with same keystore. where and how do get the latest apk doesn't matter, it will trigger the upgrade.
Checkout the Signing Strategies - Application upgrade from official dev guide.
I have found that I will get application updates after installing through adb if the following criteria are met:
1. same package name
2. version code specified in AndroidManifest.xml adb version < version code play store version
3. same key used to sign both apk's
It is possible. Proof: most of the phones is supplied with YouTube, Twitter, Facebook and other applications and these applications is possible to update via Market.

Write an application that can use plugins

I am trying to find a way to have plugins in an application.
My goal is to have a Core application, and offer plugins that can be downloadable on the market. (It can be anything, weather, radio player, etc...)
The plugins would not interact with each other, so the core application is more like a directory of multiple applications with kind of a SDK that the plugins use.
There is the Tic Tac Toe example in the Android doc, but the requires the main app to declare the external lib. My wish is that the core app detects the new installed plugins and shows them.
I found this other question but there is no answer.
Is there a way to do that?
Edit: There are also applications that can be unlocked by buying another app on the market. How do they work? I could not find anything interesting yet. You know what you find when you google "android unlock" :)
This is a little cleaner, so you don't have to use a try catch block.
Also, this avoids someone creating an app with the same name and manually installing it on their phone.
public boolean checkIfAllowed()
{
PackageManager pm = getPackageManager();
int match = pm.checkSignatures("your.first.package", "your.second.package");
if (match == PackageManager.SIGNATURE_MATCH)
{
Log.d("ALLOWED?", "signatures match");
return true;
}
else
{
Log.d("ALLOWED?", "signatures don't match");
return false;
}
}
You can use PackageManager to look for another application. If you know the package names of all of the 'plugins' then you can just check for each of them this way.
PackageManager pm = getPackageManager();
try {
ApplicationInfo appInfo = pm.getApplicationInfo("com.package.name.your.looking.for", 0);
//if we get to here then the app was found, do whatever you need to do.
} catch (NameNotFoundException e) {
//app was not found
}
if you want to decouple the main app from the plugins (using PackageManager.getApplicationInfo(package, int) MainApp has to know which package to search for) you can adopt this scheme:
at run time MainApp send a broadcast intent that every plugin has to listen to (by contract).
In response, every plugin send a direct intent to a component of MainApp that register information about available plugins and how to talk to them.
In this way, you don't have to update MainApp each time a new plugin is created.

Categories

Resources