从Android的Intent中获取价值 [英] get the value from Intent of android

查看:488
本文介绍了从Android的Intent中获取价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先谢谢了. 当我打印Log.d("me",getIntent().toString());

Thanks in advance. When I print Log.d("me",getIntent().toString());

我得到:

Intent { act=android.intent.action.CALL_PRIVILEGED dat=tel:888 flg=0x13800000 cmp=com.ninetology.freecall.two/.CallFinalActivity }

我正在尝试获取与"dat"相关联的值,但是我遇到了NullPointer异常.

I am trying to fetch the value which is associated with "dat" but I am getting NullPointer exception.

//the code I am using is
getIntent().getStringExtra("dat"); // no use
//i tried 
getIntent().getExtras("dat").toString(); // NullPointer exception

我尝试使用"tel"作为上述代码中的键,但仍然没有用.

I tried with "tel" as key in above code still no use.

推荐答案

看来您做错了.

  1. getExtras()函数返回一个可以从中提取数据的包,而不是返回特定字符串的函数.

  1. The getExtras() function returns a bundle that you can extract data from and not a function that returns a specific String.

dat不是字符串值.这是Uri

dat is NOT a String value as you can see from the data that was printed. it's a Uri,

尝试按需解析它,我相信您将能够获取数据.

try parsing it as you should and I'm sure you'll be able to get the data.

public void onCreate(Bundle b) { //mistyped
    super.onCreate(b);
    Uri data = getIntent().getData();
    // OR USE THIS
    String data = getIntent().getDataString();
    // DO STUFF
}

这篇关于从Android的Intent中获取价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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