没有官方方法可以确定对话是否被取消,但我们可以使用我们自己的自定义实现来检查应用程序是否已安装,然后继续登录过程,我正在使用以下代码执行此操作
@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();
}