问题开触点 - Android电子 [英] Problem with opening contacts - Android

查看:116
本文介绍了问题开触点 - Android电子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经把我的应用程序的一项功能,打开联系人列表。
问题是,一些用户报告说,当他们试图使用它的应用程序崩溃。
该功能似乎对大多数人正常工作(包括我在内,使用Nexus S)。

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).

这里的code我用开触点 -

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 - i.e. 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). The following Intent will do the trick:

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.

这篇关于问题开触点 - Android电子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆