从选项卡布局调用 Intent.ACTION_DIAL

发布于 2024-11-20 00:39:58 字数 3770 浏览 5 评论 0原文

我们如何从选项卡布局中调用 Intent.ACTION_DIAL?

我的代码是:

 Resources res = getResources(); // Resource object to get Drawables
        TabHost tabHost = getTabHost(); // The activity TabHost
        TabHost.TabSpec spec; // Resusable TabSpec for each tab
        Intent intent; // Reusable Intent for each tab


    // Create an Intent to launch an Activity for the tab (to be reused)
        intent = new Intent(Intent.ACTION_DIAL);
    
        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost
            .newTabSpec("contacts")
            .setIndicator("Contacts",
                res.getDrawable(R.drawable.tab_contacts))
            .setContent(intent);
            
        tabHost.addTab(spec);

但是应用程序显示异常

07-14 14:08:21.024: ERROR/AndroidRuntime(543): java.lang.SecurityException: Requesting code from com.android.contacts (with uid 10000) to be run in process org.sipdroid.sipua (with uid 10032)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.app.ActivityThread.getPackageInfo(ActivityThread.java:2330)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2558)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.widget.TabHost.setCurrentTab(TabHost.java:323)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:129)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:453)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.view.View.performClick(View.java:2408)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.view.View$PerformClick.run(View.java:8816)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.os.Handler.handleCallback(Handler.java:587)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.os.Handler.dispatchMessage(Handler.java:92)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.os.Looper.loop(Looper.java:123)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.app.ActivityThread.main(ActivityThread.java:4627)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at java.lang.reflect.Method.invokeNative(Native Method)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at java.lang.reflect.Method.invoke(Method.java:521)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at dalvik.system.NativeStart.main(Native Method)
07-14 14:08:21.063: WARN/ActivityManager(58):   Force finishing activity org.sipdroid.sipua/.ui.SIPTabWidget
07-14 14:08:21.683: WARN/ActivityManager(58): Activity pause timeout for HistoryRecord{43f7d678 org.sipdroid.sipua/.ui.SIPTabWidget}
07-14 14:08:27.443: DEBUG/dalvikvm(255): GC_EXPLICIT freed 93 objects / 4104 bytes in 135ms
07-14 14:08:32.106: WARN/ActivityManager(58): Activity destroy timeout for HistoryRecord{43f7d678 org.sipdroid.sipua/.ui.SIPTabWidget}

How can we call Intent.ACTION_DIAL from a tab layout?

My code is:

 Resources res = getResources(); // Resource object to get Drawables
        TabHost tabHost = getTabHost(); // The activity TabHost
        TabHost.TabSpec spec; // Resusable TabSpec for each tab
        Intent intent; // Reusable Intent for each tab


    // Create an Intent to launch an Activity for the tab (to be reused)
        intent = new Intent(Intent.ACTION_DIAL);
    
        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost
            .newTabSpec("contacts")
            .setIndicator("Contacts",
                res.getDrawable(R.drawable.tab_contacts))
            .setContent(intent);
            
        tabHost.addTab(spec);

But the app showing an exception

07-14 14:08:21.024: ERROR/AndroidRuntime(543): java.lang.SecurityException: Requesting code from com.android.contacts (with uid 10000) to be run in process org.sipdroid.sipua (with uid 10032)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.app.ActivityThread.getPackageInfo(ActivityThread.java:2330)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2558)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.widget.TabHost.setCurrentTab(TabHost.java:323)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:129)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:453)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.view.View.performClick(View.java:2408)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.view.View$PerformClick.run(View.java:8816)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.os.Handler.handleCallback(Handler.java:587)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.os.Handler.dispatchMessage(Handler.java:92)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.os.Looper.loop(Looper.java:123)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at android.app.ActivityThread.main(ActivityThread.java:4627)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at java.lang.reflect.Method.invokeNative(Native Method)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at java.lang.reflect.Method.invoke(Method.java:521)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-14 14:08:21.024: ERROR/AndroidRuntime(543):     at dalvik.system.NativeStart.main(Native Method)
07-14 14:08:21.063: WARN/ActivityManager(58):   Force finishing activity org.sipdroid.sipua/.ui.SIPTabWidget
07-14 14:08:21.683: WARN/ActivityManager(58): Activity pause timeout for HistoryRecord{43f7d678 org.sipdroid.sipua/.ui.SIPTabWidget}
07-14 14:08:27.443: DEBUG/dalvikvm(255): GC_EXPLICIT freed 93 objects / 4104 bytes in 135ms
07-14 14:08:32.106: WARN/ActivityManager(58): Activity destroy timeout for HistoryRecord{43f7d678 org.sipdroid.sipua/.ui.SIPTabWidget}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

与君绝 2024-11-27 00:39:58

看起来你和这个人有同样的问题:http:// /www.mail-archive.com/[email protected]/msg14856.html

您不能在自己的应用程序中使用来自其他应用程序的代码,除非它具有相同的 UserID。邮件列表提到用 SharedUserID 来欺骗它(http://developer.android.com/guide/topics/security/security.html#userid),但我怀疑这是否有效。

总而言之,我想说这是不可能的,除非您授予应用程序根访问权限。

It looks like you have the same problem like this guy: http://www.mail-archive.com/[email protected]/msg14856.html

You can not use code from other applications in your own, unless it has the same UserID. The mailinglists mentions tricking it with a SharedUserID (http://developer.android.com/guide/topics/security/security.html#userid), but I doubt this will work.

All in all I would state it is not possible, unless you give the application root access.

沦落红尘 2024-11-27 00:39:58

我得到了它。当我直接从 setOnTabChangedListener 调用 startActivity() 时,意图工作正常。

这是我的代码:

spec = tabHost.newTabSpec("dial")
    .setIndicator("Dialler", res.getDrawable(R.drawable.tab_dial))
    .setContent(intent);
    tabHost.addTab(spec);

在选项卡更改上我给出:

tabHost.setOnTabChangedListener(new OnTabChangeListener() {

        @Override
        public void onTabChanged(String tabId) {
        System.out.println(" Tab ID:  "+tabId);
        
        if(tabId.equals("dial")){
            intent =  new Intent(Intent.ACTION_DIAL);
            startActivity(intent);
            tabHost.setCurrentTab(0);
                    }   }
    });

I got it. The intent works fine when I called startActivity() directly from setOnTabChangedListener.

Here is my code:

spec = tabHost.newTabSpec("dial")
    .setIndicator("Dialler", res.getDrawable(R.drawable.tab_dial))
    .setContent(intent);
    tabHost.addTab(spec);

and on Tab change I give:

tabHost.setOnTabChangedListener(new OnTabChangeListener() {

        @Override
        public void onTabChanged(String tabId) {
        System.out.println(" Tab ID:  "+tabId);
        
        if(tabId.equals("dial")){
            intent =  new Intent(Intent.ACTION_DIAL);
            startActivity(intent);
            tabHost.setCurrentTab(0);
                    }   }
    });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文