我在我的 Android 应用程序中使用 LinkedIn SDK,这需要在设备中安装 LinkedIn 应用程序。当设备中未安装 LinkedIn 应用程序时,它会显示一个对话框,要求下载该应用程序。
到目前为止,我还没有找到一种方法来检测对话框是否已从应用程序中取消。深入研究,我发现该对话框由 com.linkedin.platform.internals
中名为 AppStore 的 LinkedIn SDK 类显示请指教。
最佳答案
没有官方方法可以查明对话是否被取消,但我们可以使用我们自己的自定义实现来检查应用程序是否已安装,然后继续登录过程,我正在使用以下代码进行登录
@Override
public void onResume() {
super.onResume();
//check if the linkdin is installed or not
if (linkedInInstalled()) {//if the linkedin is installed then proceed with login
login_linkedin();
} else {//else do not login ask user to download the app
showLinkdingInstallPopup();
}
}
private boolean linkedInInstalled() {
PackageManager pm = getPackageManager();
try {
pm.getPackageInfo("com.linkedin.android", PackageManager.GET_ACTIVITIES);
return true;
} catch (PackageManager.NameNotFoundException e) {
}
return false;
}
如果 LinkedIn 应用程序已安装,则继续正常登录过程,如果未安装,则向用户显示一条消息以安装链接
private void showLinkdingInstallPopup() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Linkedin is not installed on you device please install it to proceed with linkedin synch");
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
try {
Intent viewIntent =
new Intent("android.intent.action.VIEW",
Uri.parse("https://play.google.com/store/apps/details?id=com.linkedin.android&hl=en"));
startActivity(viewIntent);
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Unable to connect try after some time...",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//handle the dialog cancelled logic
dialogInterface.dismiss();
finish();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
关于android - 处理 Android 中 LinkedIn 应用程序下载对话框的取消,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35478928/