2013-05-25 41 views
0

我不能添加startactivity(intent)。我正在嘗試使用意向去另一個應用程序。無法運行startactivity(意向)

有人可以告訴我如何添加一個intent到我的覆蓋。 我有一個按鈕來顯示意圖。使用包名com.dropbox.android

try { 
    Intent i = getPackageManager().getLaunchIntentForPackage("com.dropbox.android"); 
    startActivity(i); 
} catch (Exception e) { 
     Toast.makeText(getApplicationContext(),"Dropbox Application Not Installed",Toast.LENGTH_SHORT).show(); 
} 

在這裏,我已經打開 'Dropbox的應用程序':

public class AddItemizedOverlay extends ItemizedOverlay<OverlayItem> { 
    private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>(); 

    private Context context; 

    public AddItemizedOverlay(Drawable defaultMarker) { 
     super(boundCenterBottom(defaultMarker)); 
    } 

    public AddItemizedOverlay(Drawable defaultMarker, Context context) { 
     this(defaultMarker); 
     this.context = context; 
    } 

    @Override 
    protected OverlayItem createItem(int i) { 
     return mapOverlays.get(i); 
    } 

    @Override 
    public int size() { 
     return mapOverlays.size(); 
    } 

    @Override 
    protected boolean onTap(int index) { 
     final OverlayItem item = this.mapOverlays.get(index); 
     final Dialog dialog = new Dialog(this.context); 
     dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     dialog.setContentView(R.layout.dialog_layout); 
     TextView title = (TextView)dialog.findViewById(R.id.title); 
     TextView subtitle = (TextView)dialog.findViewById(R.id.subtitle); 
     Button get = (Button)dialog.findViewById(R.id.get); 
     title.setText(item.getTitle()); 
     String Snip = item.getSnippet(); 
     String Alamat = Snip.substring(0, Snip.indexOf('-')); 
     subtitle.setText(Alamat); 
     final String Geo = Snip.substring(Snip.indexOf('-') + 1); 

     get.setOnClickListener(new View.OnClickListener() { 

      public void onClick(View view){ 

       String url = Geo; 
       Intent i = new Intent(Intent.ACTION_VIEW); 
       i.setData(Uri.parse(url)); 
       startActivity(i); // this line is the error code 
      } 
     }); 


     dialog.show(); 
     return true; 
    } 

    public void addOverlay(OverlayItem overlay) { 
     mapOverlays.add(overlay); 
     this.populate(); 
    } 
} 
+6

使用上下文來啓動活動。 context.startActivity(ⅰ);嘗試這個。你也有任何錯誤或例外嗎? – Raghunandan

回答

1

您可以使用此。

你可以用你的名字替換這個包名。