Reputation: 1
I can't add startactivity(intent)
. I'm trying to go to another application using intent.
Can someone tell me how to add an intent to my overlay. I have a button to show that intent.
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();
}
}
Upvotes: 0
Views: 137
Reputation: 762
You can use this :
try {
Intent i = getPackageManager().getLaunchIntentForPackage("com.dropbox.android");
startActivity(i);
} catch (Exception e) {
Toast.makeText(getApplicationContext(),"Dropbox Application Not Installed",Toast.LENGTH_SHORT).show();
}
Here I have opened 'Dropbox Application' using the package name com.dropbox.android.
You can replace this Package name with yours.
Upvotes: 1