无法在ArrayAdapter中将Intent添加到Google地图

时间:2013-03-13 05:11:23

标签: android android-intent android-arrayadapter

我有一个代码列表,其项目是对某事物的引用并具有地址。我需要这样做,当点击该列表中的任何项目时,应该启动对应于rowitem地址的Google Maps Navigation。顺便说一下,地址在行内是不可见的,地址是从中获取行信息的对象。我试过了代码: -

rowview.setOnClickListener(new View.OnClickListener() 
    {
        public void onClick(View v) 
        {
            //Intent intent = new Intent(context,);
            //Toast.makeText(context, "Yeah Boy", Toast.LENGTH_SHORT).show();
            LatLng tmp = objects.get(position).location;
            String uri = "http://maps.google.com/maps?saddr=" + location.getLatitude()+","+location.getLongitude()+"&daddr="+tmp.latitude+","+tmp.longitude;  
            Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
            intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
            context.startActivity(intent);
        }
    });
    return rowview;

但它似乎没有起作用。我有这个错误: -

android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

任何人都可以帮助我。提前谢谢。

3 个答案:

答案 0 :(得分:1)

  

构造函数Intent(int,Uri)未定义

使用setFlag方法设置标记。

Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
intent.setFlag(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);

答案 1 :(得分:1)

尝试为:

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
String uri = "Your URI String ";
intent.setData(Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", 
                 "com.google.android.maps.MapsActivity");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);

答案 2 :(得分:0)

我不知道变量“context”中的上下文。

如果您的代码包含在活动中,请尝试

而不是“上下文”

ActivityClass.this.startActivity(意向);