twitter - Android : Can I use this intent from a 3rd party application? -


i'm using intent post message via twitter client. when there no twitter application on phone want redirect user market. exception activitynotfoundexception not working. everytime (when don't have twitter app) error "no applications can perform action"

intent intenttwitter = new intent(intent.action_send); intenttwitter.putextra(intent.extra_text,msg); intenttwitter.settype("application/twitter");  try{  startactivity(intent.createchooser(intenttwitter,"tweet")); }catch(activitynotfoundexception e){  // lead app market } 

i read activitynotfoundexception exception handler startactivity , child. maybe solution not in exception handling.

here solution posted.

i use packagemanager , queryintentactivities() indicate whether specified action can used intent. method queries package manager installed packages on phone can respond intent specified action. if no packages found , method returns false.

public static boolean isintentavailable(context context, string action) {         final packagemanager packagemanager = context.getpackagemanager();         final intent intent = new intent(action);         list<resolveinfo> list =                 packagemanager.queryintentactivities(intent,                         packagemanager.match_default_only);         return list.size() > 0;     } 

here complete code. connect twitter twitter client. i'm using

public void connecttwitter(){     string msg = getresources().getstring(r.string.partager_twitter).tostring();     intent intenttwitter = new intent(intent.action_send);     intenttwitter.putextra(intent.extra_text,msg);     intenttwitter.settype("application/twitter");     if (isintentavailable(this,"application/twitter")){         startactivity(intent.createchooser(intenttwitter,getresources().getstring(r.string.partager_sel_tweet)));     }     else{         /* handle exception if no suitable apps installed */           log.d("twitter", "catch exception");         new alertdialog.builder(partageractivity.this)          .settitle(getresources().getstring(r.string.partager_sel_tweet))          .setmessage(getresources().getstring(r.string.partager_app_download))        .setnegativebutton("non", null)          .setpositivebutton("oui", new dialoginterface.onclicklistener() {                        public void onclick(dialoginterface dialog, int whichbutton) {                           intentmarket("market://search?q=twitter");                        }                    })          .show();          }  } 

with intentmarket method.just enter url ="market://search?q=twitter" btw market not installed in emulator.

public void intentmarket (string url){     intent = new intent(intent.action_view);     uri u = uri.parse(url);     i.setdata(u);     try{         startactivity(i);     }     catch(activitynotfoundexception e){         toast.maketext(this, "pas d'applications twitter trouvé.", toast.length_short).show();       } } 

more packagemanager http://android-developers.blogspot.com/2009/01/can-i-use-this-intent.html

thumbs if find useful !


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -