java - onActivityResult not executed after contact picked
问题描述
after i choose a contact to display name and phone number via intent,onActivityResult is not executed.
I look for some answer here but nono have solved my problem.When i star to develop that function it worked but after some validations(if permission are granted) its stops working.
contact.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(GeneralUtility.validatePermission(context, Manifest.permission.READ_CONTACTS)){
initPickContacts();
}else{
GeneralUtility.navigateSettingByApp(context);
Toast.makeText(context, "Permiso no obtenido", Toast.LENGTH_SHORT).show();
}
}
});
public void initPickContacts(){
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
startActivityForResult(intent, PICK_CONTACT_REQUEST);
Intent i = new Intent(Intent.ACTION_PICK,
ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(i, PICK_CONTACT_REQUEST);
}
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (requestCode == PICK_CONTACT_REQUEST) {
if (resultCode == RESULT_OK) {
Uri contactUri = intent.getData();
renderContact(contactUri);
}
}
}
I need to obtain the uri of the contact.
解决方案
it works now. I changed the value of PICK_CONTACT_REQUEST to 1 and onActivityResult works.
推荐阅读
- asp.net-core - 如何在 .NET Core 解决方案中访问另一个项目的根文件夹?
- ios - 在约束中添加计算会降低系统性能吗?
- python - PIL(枕头)使用“libpng 警告:iCCP:已知不正确的 sRGB 配置文件”保存 png
- ios - 如何让您的 API 仅在显示容器视图时运行?
- java - 为什么 visualvm 中的“总时间”列与运行时持续时间不同?
- uninstallation - 如何卸载通过 distils 安装的 pycocotools
- php - 如何为 whmcs 订单添加操作挂钩
- python - 对于句子中的不同单词,我怎样才能得到像 A=B 这样的输出
- laravel-6 - BadMethodCallException 方法 Illuminate\Translation\Translator::getFromJson 不存在
- node.js - nodejs sequelize 包含关系排序