Java android check if Acrobat Reader is installed if no download - java

I want to check if Acrobat Reader is installed when is not installed I want to open an android market on Adobe Acrobat Reader
This is how I check intalled :
public static boolean canDisplayPdf(Context context)
{
PackageManager packageManager = context.getPackageManager();
Intent testIntent = new Intent(Intent.ACTION_VIEW);
testIntent.setType(MIME_TYPE_PDF);
if (packageManager.queryIntentActivities(testIntent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0) {
return true;
} else {
return false;
}
}
next I when this method return false I want open an andrid market (apk) :
final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object
try
{
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=Adoba Acrobat Reader" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe)
{
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id= Adoba Acrobat Reader" + appPackageName)));
}
But open an android market it doen't work

You can use this method to check for Adobe Acrobat Reader if its installed:
private boolean isPackageInstalled(String packagename, PackageManager packageManager) {
try {
packageManager.getPackageInfo(packagename, 0);
return true;
} catch (NameNotFoundException e) {
return false;
}
}
Usage:
boolean isAdobeInstalled = isPackageInstalled("com.adobe.reader", getPackageManager());
if (isAdobeInstalled) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=com.adobe.reader")));
}

change
Uri.parse("http://play.google.com/store/apps/details?id= Adoba Acrobat Reader" + appPackageName)));
to
Uri.parse("https://play.google.com/store/apps/details?id=com.adobe.reader)));

Related

How do I add a rating app button in my app in android studio before publishing my app?

I have created a navigation menu in my application where users can use and select the option of rating my app. The problem I am currently having is trying to figure out how to add a link to the rate my app button before I have actually published the app? How do developers add this option to their app before publishing it and what would be the best code to use for this problem?
This is the current code I have added in my MainActivity.java to send the user to rate my app. What changes should I make to this code?
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.nav_thumb:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=com.mydomain.tapp"));
startActivity(intent);
break;
}
drawerLayout.closeDrawer(GravityCompat.START);
return true;
}
try {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id=" + this.getPackageName())));
} catch (android.content.ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://play.google.com/store/apps/details?id=" + this.getPackageName())));
}
/*
* Start with rating the app
* Determine if the Play Store is installed on the device
*
* */
public void rateMyApp()
{
try
{
Intent rateIntent = rateIntentForUrl("market://details");
startActivity(rateIntent);
}
catch (ActivityNotFoundException e)
{
Intent rateIntent = rateIntentForUrl("https://play.google.com/store/apps/details");
startActivity(rateIntent);
}
}
private Intent rateIntentForUrl(String url)
{
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("%s?id=%s", url, getPackageName())));
int flags = Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
if (Build.VERSION.SDK_INT >= 21)
{
flags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
}
else
{
//noinspection deprecation
flags |= Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET;
}
intent.addFlags(flags);
return intent;
}
Add this code in the Activity or Class from where you would like to call.
Just call rateMyApp() with user click action

In Android how to check app is installed in your phone or not

How to check if app is installed or not on phone. If the app is installed, open the app, otherwise open the appstore link to download the app.
If the app is already there, I used the following code.
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("package name");
startActivity(LaunchIntent);
Checking if app is installed having package name:
public static final String PACKAGE_NAME = "com.__.__";
public static boolean isAppInstalled(Context context) {
PackageManager packageManager = context.getPackageManager();
Intent intent = new Intent(Intent.ACTION_VIEW);
if (intent.resolveActivity(packageManager) != null) {
try {
packageManager.getPackageInfo(PACKAGE_NAME, PackageManager.GET_ACTIVITIES);
return true;
} catch (PackageManager.NameNotFoundException ignore) {
}
}
return false;
}
Open Play Market having package name:
try {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}

APK not being deleted from download folder

I have set up a Broadcast that starts up when Application is installed with startActivityForResult(). The installation Intent is created here.
private static Intent getOpenDownloadedApkIntent(Context context, File file) {
String name = getPackageNameForAPK(file.getPath(), context);
if (name != null) {
INSTALL_APK_INFO.put(name, file);
}
// The type of intent to use to open the downloaded apk changed in Android N (7.0)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Uri path = FileProvider.getUriForFile(context,
context.getApplicationContext().getPackageName() + ".utils.DownloadedFileProvider",
file);
Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
intent.setData(path);
return intent;
} else {
Uri uri = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
intent.setDataAndType(uri, "application/vnd.android.package-archive");
return intent;
}
}
private static String getPackageNameForAPK(final String archiveFilePath, Context context) {
try {
PackageInfo info = context.getPackageManager().getPackageArchiveInfo(archiveFilePath, PackageManager.GET_META_DATA);
return info.packageName;
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
Now if it is Android 7 or higher, then the uninstall works, but if it is Android 6 or lower, then it just seems to delete the icon of the APK but not the APK itself.
Here is the code that should delete the APK:
private static BroadcastReceiver onInstallComplete = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
ApplicationInfo info = null;
try {
info = context.getPackageManager().getApplicationInfo(intent.getDataString().split(":")[1], PackageManager.GET_META_DATA);
} catch (PackageManager.NameNotFoundException ex) {
}
try {
if (info != null) {
File file = INSTALL_APK_INFO.get(info.packageName);
if (file != null) {
file.delete();
INSTALL_APK_INFO.remove(info.packageName);
}
}
} catch (NullPointerException ex) {
}
}
};
I am guessing that is has something to do with the path, but at the same time it seems to delete the icon of the APK. By icon I mean that if i remove the file.delete() then the APK is with icon in downloads folder but if I run the file.delete() then the APK is without the icon.
What am I doing wrong?
Do u mean to say that app is getting installed but without launcher icon?

Open another app activity, if app is not installed go to play store [duplicate]

This question already has answers here:
Open another application from your own (intent)
(20 answers)
Closed 5 years ago.
i want to open an another app activity from my app, if the app is not installed go to the play store to install the app.
my code is working fine but its only open the app from it's package name, it's not opening activity.
Code:
public void startApplication(String packageName)
{
try
{
Intent intent = new Intent("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
List<ResolveInfo> resolveInfoList = getPackageManager().queryIntentActivities(intent, 0);
for(ResolveInfo info : resolveInfoList)
if(info.activityInfo.packageName.equalsIgnoreCase(packageName))
{
launchComponent(info.activityInfo.packageName, info.activityInfo.name);
return;
}
// No match, so application is not installed
showInMarket(packageName);
}
catch (Exception e)
{
showInMarket(packageName);
}
}
private void launchComponent(String packageName, String name)
{
Intent intent = new Intent("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");
intent.setComponent(new ComponentName(packageName, name));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
private void showInMarket(String packageName)
{
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageName));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
Try
public void startApplication(String packageName) {
Intent launchIntent = getPackageManager().getLaunchIntentForPackage(packageName);
if (launchIntent != null) {
startActivity(launchIntent);
} else {
showInMarket(packageName);
}
}

How can I open play store market:// in webview [duplicate]

I have some links in my webview that are market:// links. When my users tap on them, it gives them a page cannot be found error.
How can I allow all links that begin with market:// to automatically open the Google play store when they are tapped? I tried:
final Intent intent = new Intent("android.intent.action.VIEW");
intent.setData(Uri.parse("market://details?id="));
startActivity(intent);
}
but that didn't seem to do anything. I am pretty new to this so any help would be appreciated. Also, FYI, I cannot change the market:// links to play.google.com myself. They are from my advertiser.
Is there anyway I can include it in this code:
public boolean shouldOverrideUrlLoading(WebView paramWebView, String paramString) {
if (DEBUG)
Log.e("shouldOverride", paramString);
if (Uri.parse(paramString).getHost()!=null && (!Uri.parse(paramString).getHost().equals("market.android.com")) && (!paramString.contains("facebook.com")) && (!Uri.parse(paramString).getHost().contains("twitter.com")) && (!Uri.parse(paramString).getHost().equals("play.google.com"))
&& (!Uri.parse(paramString).getHost().contains("bit.ly")) && (!Uri.parse(paramString).getHost().contains("plus.google.com")) && (!Uri.parse(paramString).getHost().contains("youtube.com"))){
if(isAppOrGamePage(paramString)){
final Intent intent = new Intent(MainActivity.this, PageActivity.class);
intent.putExtra("app_url", paramString);
startActivity(intent);
} else
return false;
} else {
final Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(paramString));
startActivity(intent);
}
return true;
}
}
You can decide what to do by looking the scheme of the url, if Google Play Store app is installed you can open the detail page in Play Store app, else you can show Google Play web page of the application
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getScheme().equals("market")) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
Activity host = (Activity) view.getContext();
host.startActivity(intent);
return true;
} catch (ActivityNotFoundException e) {
// Google Play app is not installed, you may want to open the app store link
Uri uri = Uri.parse(url);
view.loadUrl("http://play.google.com/store/apps/" + uri.getHost() + "?" + uri.getQuery());
return false;
}
}
return false;
}
});
you can use this code like this also if its help you:
// It will not work in android simulator as it does not have Google Play Store
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+APP_ID)));
if (url.startsWith("market://")||url.startsWith("vnd:youtube")||url.startsWith("tel:")||url.startsWith("mailto:"))
{
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
return true;
}

Categories

Resources