取回结果从Android原生计算器 [英] Get Back Result from Android native Calculator

查看:108
本文介绍了取回结果从Android原生计算器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我调用Android原生计算器从我的应用程序,我怎么从它那里得到的结果数据..意味着我开始喜欢这个本地日历,我preSS回onActivityResult执行和返回的数据为空整理计算后,如何获得计算的数据..帮我

 意向书我=新意图();
i.setClassName(com.android.calculator2
            com.android.calculator2.Calculator);
startActivityForResult(ⅰ,1);

@覆盖
保护无效onActivityResult(INT申请code,INT结果code,意图数据){
super.onActivityResult(要求code,因此code,数据);
如果(要求code == 1){
    Log.i(计算器,结果数据为+数据);
 }
}
 

解决方案

经过一些测试,我开始认为你不能真正得到的东西从计算器回来。调用一些与 startActivityForResult 并不意味着它要返回的东西以外既然没有办法让出计算器超过pressing返回键等,我想这是其中的案例之一。

本机计算器似乎并没有被调用的setResult(RESULT_SUCESS,intent_with_data)这是为了能够检索这个结果所需的步骤。我能想到的,因为你想要做一些计算最简单的就是实现自己的计算器类并调用的那一个,而不是本地的。

计算器是很容易的,你必须在网上数不胜数的例子。只要确保你有一个确定按钮调用的setResult(RESULT_SUCESS,intent_with_data)你把群众演员的意图后,结果

警告

要知道,你是一个硬编码类名称,而不是调用一个意图通过指定的动作和URI。这可能会调用的Andr​​oid模拟器和标准版本的原始的计算器,但制造商改变那些各种各样的事情,因为没有人是应该叫他们像你打算与你的意图,你可能最终崩溃的应用程序。

I'm invoking android native calculator from my app, how do i get result data from it.. means i started native calender like this, after finishing calculation i press back onActivityResult is executed and data returned is null, how to get calculated data.. Help me

Intent i = new Intent();
i.setClassName("com.android.calculator2",
            "com.android.calculator2.Calculator");
startActivityForResult(i, 1); 

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data); 
if(requestCode == 1){
    Log.i("CALCULATOR", "Result Data is"+ data);
 }       
}

解决方案

After some testing, I'm starting to think that you can't really get something back from the calculator. Calling something with startActivityForResult doesn't mean it's going to return something other than null and since there's no way of getting out of the calculator other than pressing the back key, I think this is one of those cases.

The native calculator doesn't seem to be calling setResult(RESULT_SUCESS,intent_with_data) which is the step needed to be able to retrieve this result. Easiest thing I can think of, since you're wanting to do some calculation is to implement your own calculator class and call that one instead of the native one.

Calculators are easy to make and you have a zillion examples on the net. Just make sure you have an OK button that calls setResult(RESULT_SUCESS, intent_with_data) after you put extras to the intent with the result.

Warning

Be aware that you're hardcoding a class name instead of calling an intent by specifying an action and URI. This may call the original calculator on the emulator and standard versions of Android, but manufacturers change those kinds of things and since no one is supposed to be calling them like you intend to with your intent, you may end up crashing the app.

这篇关于取回结果从Android原生计算器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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