本文整理汇总了Java中android.content.pm.PackageManager.getInstallerPackageName方法的典型用法代码示例。如果您正苦于以下问题:Java PackageManager.getInstallerPackageName方法的具体用法?Java PackageManager.getInstallerPackageName怎么用?Java PackageManager.getInstallerPackageName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.pm.PackageManager
的用法示例。
在下文中一共展示了PackageManager.getInstallerPackageName方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: detect
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static int detect(Context c) {
if (Build.VERSION.SDK_INT < 5)
return APPSTORE;
PackageManager pm = c.getPackageManager();
String installer = pm.getInstallerPackageName(c.getPackageName());
if (installer != null && installer.equals("com.android.vending"))
return MARKET;
if (Build.MODEL.equalsIgnoreCase("Kindle Fire"))
return APPSTORE;
try {
if (pm.getPackageInfo("com.amazon.venezia", 0) != null)
return APPSTORE;
} catch (NameNotFoundException e) {
}
return MARKET;
}
示例2: setFromPackageInfo
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private void setFromPackageInfo(PackageManager pm, PackageInfo packageInfo) {
this.packageName = packageInfo.packageName;
final String installerPackageName = pm.getInstallerPackageName(packageName);
CharSequence installerPackageLabel = null;
if (!TextUtils.isEmpty(installerPackageName)) {
try {
ApplicationInfo installerAppInfo = pm.getApplicationInfo(installerPackageName,
PackageManager.GET_META_DATA);
installerPackageLabel = installerAppInfo.loadLabel(pm);
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, "Could not get app info: " + installerPackageName, e);
}
}
if (TextUtils.isEmpty(installerPackageLabel)) {
installerPackageLabel = installerPackageName;
}
ApplicationInfo appInfo = packageInfo.applicationInfo;
final CharSequence appDescription = appInfo.loadDescription(pm);
if (TextUtils.isEmpty(appDescription)) {
this.summary = "(installed by " + installerPackageLabel + ")";
} else if (appDescription.length() > 40) {
this.summary = (String) appDescription.subSequence(0, 40);
} else {
this.summary = (String) appDescription;
}
this.added = new Date(packageInfo.firstInstallTime);
this.lastUpdated = new Date(packageInfo.lastUpdateTime);
this.description = "<p>";
if (!TextUtils.isEmpty(appDescription)) {
this.description += appDescription + "\n";
}
this.description += "(installed by " + installerPackageLabel
+ ", first installed on " + this.added
+ ", last updated on " + this.lastUpdated + ")</p>";
this.name = (String) appInfo.loadLabel(pm);
this.icon = getIconName(packageName, packageInfo.versionCode);
this.installedVersionName = packageInfo.versionName;
this.installedVersionCode = packageInfo.versionCode;
this.compatible = true;
}
示例3: getInstallerPackageName
import android.content.pm.PackageManager; //导入方法依赖的package包/类
@Nullable
private static String getInstallerPackageName(Context context) {
PackageManager packageManager = context.getPackageManager();
if (packageManager != null) {
return packageManager.getInstallerPackageName(context.getPackageName());
}
return null;
}
示例4: getInstaller
import android.content.pm.PackageManager; //导入方法依赖的package包/类
static String getInstaller(Context context) {
PackageManager packageManager = context.getPackageManager();
String installer = packageManager.getInstallerPackageName(BuildConfig.APPLICATION_ID);
if (!TextUtils.isEmpty(installer)
&& packageManager.getLaunchIntentForPackage(installer) != null) {
return installer;
} else {
return null;
}
}
示例5: SetDonationKeyStatus
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public void SetDonationKeyStatus() {
if (BuildConfig.DEBUG) {
Status = true;
return;
//if debug mode, avoid the advertisements and use pro features
}
try {
PackageManager packageManager = getPackageManager();
packageManager.getPackageInfo("com.softminds.matrixcalculator.pro.key", 0);
//Key is Installed
//Checking the Authenticity of the Key
if (packageManager.checkSignatures(getPackageName(),
"com.softminds.matrixcalculator.pro.key")
== PackageManager.SIGNATURE_MATCH) {
Log.d(TAG, "The Signature of Key Matched with Application");
String manager = packageManager.getInstallerPackageName("com.softminds.matrixcalculator.pro.key");
if (manager != null) {
//Status = true;
Log.d(TAG, manager);
if (Objects.equals(manager, "com.android.vending")) {
Status = true;
} else {
Status = false;
Toast.makeText(this, R.string.clear_warn_invalid_install, Toast.LENGTH_LONG).show();
}
}
//the Key is Genuine and was Installed from Play
}
} catch (Exception e) {
Status = false;
}
}
示例6: hasMarketLink
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static boolean hasMarketLink(Context context, String packageName) {
try {
PackageManager pm = context.getPackageManager();
String installer = pm.getInstallerPackageName(packageName);
if (installer != null)
return installer.equals("com.android.vending") || installer.contains("google");
} catch (Exception ex) {
log(null, Log.WARN, ex.toString());
}
return false;
}
示例7: appLaunched
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* Should be called on every <code>Activity.onCreate()</code>. Checks if the
* trial period is over and if so brings up a notification dialog.
*
* @param ctx
* The application context.
*/
public static void appLaunched(Context ctx) {
try {
// Don't even bother if not installed from Google Play
PackageManager pm = ctx.getPackageManager();
String pn = ctx.getPackageName();
String inst = pm.getInstallerPackageName(pn);
if (inst == null || !(inst.startsWith("com.google")
|| inst.startsWith("com.android"))) {
return;
}
}
catch (Exception exp) {
Log.w("AppRater",exp);
// Just bailout. Don't even try recovery.
return;
}
SharedPreferences prefs = ctx.getSharedPreferences(PREFSFILE, 0);
if (prefs.getBoolean("dontshowagain", false)) {
return;
}
SharedPreferences.Editor editor = prefs.edit();
// Increment launch counter
long launch_count = prefs.getLong("launch_count", 0) + 1;
editor.putLong("launch_count", launch_count);
// Get date of first launch
Long date_firstLaunch = prefs.getLong("date_firstlaunch", 0);
if (date_firstLaunch == 0) {
date_firstLaunch = System.currentTimeMillis();
editor.putLong("date_firstlaunch", date_firstLaunch);
}
editor.commit();
// Wait at least n days before opening
if (launch_count >= LAUNCHES_UNTIL_PROMPT) {
if (System.currentTimeMillis() >= date_firstLaunch
+ (DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000)) {
showRateDialog(ctx);
}
}
}