如果用户有 Google 驱动器,如何检查为布尔数据?
How to check as boolean data if user has Google Drive?
我正在制作的应用程序必须能够从 Google Drive 下载文件。因此,该应用程序应检查用户是否拥有 Google 驱动器。一个名为 DriveDetector 的 class 负责检查这些事实。实际上,基本上所有 Android Phone 都有 Google 应用程序,包括 Google 驱动器。 Android 用户无法完全删除 Google 驱动器,但他们可以 Google 驱动器不可见。如何检查 GOOGLE 驱动器在用户 PHONE 上是否已激活?感谢阅读我的问题 post.
import android.content.Context;
public class DriveDetector {
private Context context;
public DriveDetector (Context context) {
this.context = context;
}
public boolean hasGoogleDrive() {
}
}
您可以通过以下方式检查应用程序是否已安装在 phone 中:
public static boolean isAppInstalled(Context context, String packageName) {
try {
context.getPackageManager().getApplicationInfo(packageName, 0);
return true;
}
catch (PackageManager.NameNotFoundException e) {
return false;
}
}
您可以像这样调用此方法来检查 google 驱动器:
boolean hasDrive = isAppInstalled(context, "com.google.android.apps.doc");
我正在制作的应用程序必须能够从 Google Drive 下载文件。因此,该应用程序应检查用户是否拥有 Google 驱动器。一个名为 DriveDetector 的 class 负责检查这些事实。实际上,基本上所有 Android Phone 都有 Google 应用程序,包括 Google 驱动器。 Android 用户无法完全删除 Google 驱动器,但他们可以 Google 驱动器不可见。如何检查 GOOGLE 驱动器在用户 PHONE 上是否已激活?感谢阅读我的问题 post.
import android.content.Context;
public class DriveDetector {
private Context context;
public DriveDetector (Context context) {
this.context = context;
}
public boolean hasGoogleDrive() {
}
}
您可以通过以下方式检查应用程序是否已安装在 phone 中:
public static boolean isAppInstalled(Context context, String packageName) {
try {
context.getPackageManager().getApplicationInfo(packageName, 0);
return true;
}
catch (PackageManager.NameNotFoundException e) {
return false;
}
}
您可以像这样调用此方法来检查 google 驱动器:
boolean hasDrive = isAppInstalled(context, "com.google.android.apps.doc");