简体   繁体   English

打开触点出现问题 - Android

[英]Problem with opening contacts - Android

I've put a feature in my app that opens the contacts list.我在我的应用程序中添加了一个打开联系人列表的功能。 The problem is that some users reported that the app crashed when they tried to use it.问题是一些用户报告说,当他们尝试使用该应用程序时,该应用程序崩溃了。 The feature seems to works fine for most people(me included, with Nexus S).该功能似乎适用于大多数人(包括我在内,使用 Nexus S)。

Here's the code I've used to open the contacts -这是我用来打开联系人的代码 -

    call_friend.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent i = new Intent();
            i.setComponent(new ComponentName("com.android.contacts", "com.android.contacts.DialtactsContactsEntryActivity"));
            i.setAction("android.intent.action.MAIN");
            i.addCategory("android.intent.category.LAUNCHER");
            i.addCategory("android.intent.category.DEFAULT");
            startActivity(i);
        }
    }); 

Here's the log of the crash -这是崩溃的日志 -

            android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.contacts/com.android.contacts.DialtactsContactsEntryActivity}; have you declared this activity in your AndroidManifest.xml?
            at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
            at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
            at android.app.Activity.startActivityForResult(Activity.java:2817)
            at android.app.Activity.startActivity(Activity.java:2923)
            at can.you.drive.dont_drive$1.onClick(dont_drive.java:75)
            at android.view.View.performClick(View.java:2465)
            at android.view.View$PerformClick.run(View.java:8907)
            at android.os.Handler.handleCallback(Handler.java:587)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:123)
            at android.app.ActivityThread.main(ActivityThread.java:4627)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:521)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
            at dalvik.system.NativeStart.main(Native Method)

I don't know what's causing it.我不知道是什么原因造成的。 Thanks!谢谢!

Use an implicit Intent to launch the Contacts activity - ie tell the OS you want to view a list of contacts, and it will figure out the right activity to use (or prompt the user if more than one Contacts app is installed).使用隐式 Intent 启动联系人活动 - 即告诉操作系统您要查看联系人列表,它会找出要使用的正确活动(或在安装多个联系人应用程序时提示用户)。 The following Intent will do the trick:以下 Intent 可以解决问题:

Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setData(Uri.parse("content://contacts/people/"));
startActivity(i);

Try to avoid explicit Intents whenever possible... too many different devices out there to be absolutely sure that a particular package/activity will always exist.尽可能避免使用显式 Intent... 太多不同的设备无法绝对确定某个特定的包/活动将始终存在。

I think this is because the Android change the number for this App.我认为这是因为 Android 更改了此 App 的编号。 I had a similar problem if I used如果我使用,我会遇到类似的问题

intent.setClassName("com.android.contacts","com.android.contacts.DialtactsActivity");

it could run at Android 4.1 but not at 4.4.它可以在 Android 4.1 上运行,但不能在 4.4 上运行。 In 4.4 I had to change it like this在 4.4 中我不得不像这样改变它

intent.setClassName("com.google.android.dialer","com.android.dialer.DialtactsActivity");

Since you indicated above that the Galaxy S is experiencing the problem, you should take a look at what would appear to be the Android Manifest for the Contacts app on the Galaxy S here .由于您在上面指出 Galaxy S 遇到问题,您应该在此处查看Galaxy S 上联系人应用程序的 Android 清单。 Looking at this, there's no DialtactsContactsEntry Activity, which would explain what you're seeing.看看这个,没有 DialtactsContactsEntry Activity,它可以解释你所看到的。 Based on the manifest as well as this message on another forum, what you would need to use in this case is "com.sec.android.app.contacts.PhoneBookTopMenuActivity".根据清单以及另一个论坛上的此消息,在这种情况下您需要使用的是“com.sec.android.app.contacts.PhoneBookTopMenuActivity”。 This just covers the case of the Galaxy S - other devices that have their own Contacts replacement will likely have something completely different and there's no guarantee that the next rev of the Galaxy line won't choose to change this.这仅涵盖 Galaxy S 的情况 - 其他拥有自己替换联系人的设备可能会有完全不同的东西,并且不能保证 Galaxy 系列的下一版本不会选择更改这一点。

Of course (and I'm sure this is not news to you), the whole exercise underscores the inherent problems with using undocumented APIs/application features... the better approach is to use something like what ErikR described in his answer.当然(我相信这对你来说不是新闻),整个练习强调了使用未记录的 API/应用程序功能的固有问题......更好的方法是使用类似 ErikR 在他的回答中描述的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Android中阅读联系人的问题 - problem with reading contacts in android 以编程方式将vcf保存到Android中的联系人,而无需打开“联系人”应用 - Programmatically save a vcf to contacts in Android without opening Contacts app 我们如何在不打开“联系人”应用程序本身的情况下将新联系人插入Android联系人? - How do we insert new contacts into Android Contacts without opening the Contacts app itself? Android:在 webview 中打开相机的问题 - Android: Problem with the camera opening in webview 权限拒绝:打开提供者com.android.providers.contacts.ContactsProvider2 - Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 android联系人数据中TIMES_CONTACTED值的问题 - Problem with TIMES_CONTACTED value in android contacts data 打开 android 工作室模拟器时面临的问题 - Facing problem in opening android studio emulator 我的开发者应用程序在 Android 9 上打开数据库时出现问题 - My developer app problem with opening database on Android 9 Android:使用 InputStream 打开位于 SD 中的文件时出现问题 - Android: Problem with opening a file located in the SD with InputStream android中的联系人 - contacts in android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM