I want to create small application which when I start this small application in main activity I want to check if other application for example "barcode" is installed on my phone.
If yes I want to start application "barcode"
If no I want to install this application from google play.
How I can do that?
Check with following code if the application is installed
PackageManager pm = getPackageManager();
boolean app_installed = false;
try
{
pm.getPackageInfo("com.package.Barcode", PackageManager.GET_ACTIVITIES);
app_installed = true;
}
catch (PackageManager.NameNotFoundException e)
{
app_installed = false;
}
return app_installed ;
And following code redirects the user to the play store for downloading the application
String appName = "com.package.Barcode";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+appName));
startActivity(intent);
How to open an existing app you can find here:
Open another application from your own (intent)
And how to check if app exists you can find here:
How can I learn whether a particular package exists on my Android device?
Related
I've developed an ionic 3 app. I am unable to open whatsapp from my app with a specific contact in ionic 3. i don't want to send or share any thing but only wants to open whatsapp in android & iOS from my app with a specific contact. Is there any way to open whatsapp?
Till now i have implemented as below which is not working
window.open(`whatsapp:${+911234567890}`, '_system');
Any help much appreciate.
See it:
http://phonegap-plugins.com/plugins/ranjitpandit/whatsapp-phonegap-plugin
cordova.plugins.Whatsapp.send("yourNumber", sucessoCallback, errorCallback);
I am Using this:
String phone = "+8801510101010";
PackageManager packageManager = MainActivity.this.getPackageManager();
Intent i = new Intent(Intent.ACTION_VIEW);
try {
String url = "https://api.whatsapp.com/send?phone="+ phone;
i.setPackage("com.whatsapp");
i.setData(Uri.parse(url));
if (i.resolveActivity(packageManager) != null) {
MainActivity.this.startActivity(i);
}
} catch (Exception e){
e.printStackTrace();
}
I'm working on a social page that allows the user to select a link that will open whatsapp and send a message to the users chosen contact.
I am currently doing this as shown below.
<a class="modal__link modal__link--whatsapp js-product-share__link--wa"
href="whatsapp://send?text=<?php echo $whatsappBody . " " . $currentUrl;?>" data-action="share/whatsapp/share">
This methods supports both IOS and Android. However my problem is that if whatsapp is not installed on ether devices I simply get a generic error message.
Ideally I would like to be able to redirect the user to the appropriate store to download whatsapp.
Could any one give some insight into what the current method for fallbacking back is?
boolean installed = appInstalledOrNot("com.whatsapp");
if(installed){
// do your task
}else{
try {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + "com.whatsapp"));
i.addFlag(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
} catch (android.content.ActivityNotFoundException anfe) {
...
}
}
private boolean appInstalledOrNot(String uri) {
PackageManager pm = getPackageManager();
boolean app_installed;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
app_installed = true;
}
catch (PackageManager.NameNotFoundException e) {
app_installed = false;
}
return app_installed;
}
Try this and let me know if it works
I try to remove application from another application in android but When I run below code I got a this error "The application was not found in the list of installed applications" how can I solve this problem furthermore try to remove application has a many package which can I use?
Uri packageURI = Uri.parse("package:com.example.anke");
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
startActivity(uninstallIntent);
try below code and see your application's package name in your device and use this package name which you want to remove application.
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = getApplicationContext().getPackageManager().queryIntentActivities( mainIntent, 0);
You can check for whether particular application is installed or not like below
private boolean isApplicationInstalled(String packagename, Context context) {
PackageManager packageManager = context.getPackageManager();
try {
packageManager.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES);
return true;
} catch (NameNotFoundException e) {
return false;
}
}
If you get true go for uninstall, if false then application is not installed.
I have an Android Application which will detect whether an application is installed or not, after that it launches that application.
So the Android Code is
PackageManager pm = ctx.getPackageManager();
boolean app_installed = false;
try {
pm.getPackageInfo("com.mypackage.myactivity", PackageManager.GET_ACTIVITIES);
app_installed = true;
} catch (PackageManager.NameNotFoundException e) {
app_installed = false;
}
if(app_installed) {
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.mypackage.myactivity");
startActivity(LaunchIntent);
}
This works fine for Android. But when I convert my apk to bar file and then install it on a BB10 device then it doesn't recognises whether the application is installed or not.
Do i need to change the package name?
Please advice on this.
I am launching the default Youtube App installed on device to play a video. First, I want to check if the app exists on the device using PackageManager.
If the app does not exists, I want to redirect the user to the Google Play to download the app.
Below is the code snippet:
String appName = "com.google.android.youtube";
Boolean existFlg = false;
Context context = getApplicationContext();
PackageManager packageManager = context.getPackageManager();
// get all installed app's info
List<PackageInfo> pinfo = packageManager.getInstalledPackages(PackageManager.GET_ACTIVITIES);
for (int i = 0; i < pinfo.size(); i++) {
String name = pinfo.get(i).packageName;
if (name.equalsIgnoreCase(appName)) {
existFlg = true;
break;
}
}
if (existFlg) {
// start Youtube Native App
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:"+video_id));
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
}
// not installed
else {
// goto the market to download Youtube App
Uri uri = Uri.parse("market://details?id=com.google.android.youtube");
Intent market = new Intent(Intent.ACTION_VIEW, uri);
market.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
context.startActivity(market);
} catch (android.content.ActivityNotFoundException ex) {
// if market app not exist, goto the web of Google Play to download the Facebook App
String googleURL = "https://play.google.com/store/apps/details?id=com.google.android.youtube";
Uri googleplay_webpage = Uri.parse(googleURL);
Intent marketIntent = new Intent(Intent.ACTION_VIEW, googleplay_webpage);
marketIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(marketIntent);
}
}
This code works perfectly well on Android 4.0.4 and above. But when I am trying to run it on Android 2.3.4 it ALWAYS redirects the user to the Google Play irrespective of whether the App is installed or not.
Any idea as to how to make this compatible with Android 2.3.4 too ?
It is probably because PackageManager.GET_ACTIVITIES doesn't really make much sense here?
You probably want something like:
try {
PackageInfo pi = pm.getPackageInfo("com.google.android.youtube", 0);
// start Youtube
} catch (NameNotFoundException e) {
// go to Play Store
}
Also a better approach would be not to force the Youtube app on the user, but simply use the VIEW action and let them choose the app they want to use.