java - Open the default app when an image is pressed from a LinearLayout -


i have linearlayout contains 3 images:

<linearlayout     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:paddingbottom="0dp"     android:paddingleft="0dp"     android:paddingright="0dp"     android:paddingtop="0dp"     tools:context=".mainactivity"     android:orientation="horizontal"     android:layout_gravity="center" >     <imageview         android:id="@+id/imgfb"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:src="@drawable/fb"         android:padding="5dp" />         <imageview         android:id="@+id/imgtw"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:src="@drawable/tw"         android:padding="5dp" />     <imageview         android:id="@+id/imglin"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:src="@drawable/lin"         android:padding="5dp" /> </linearlayout> 

i call them inside activity (dialog being called prior):

imageview iv1 = (imageview) dialog.findviewbyid(r.id.imgfb); imageview iv2 = (imageview) dialog.findviewbyid(r.id.imgtw); imageview iv3 = (imageview) dialog.findviewbyid(r.id.imglin); 

how can use onclick() method open app if exist or open web browser url attached it?

//example public void onclick(view v) {     if (iv1 clicked()) {           check if fb installed, if take them fb page           if fb not installed, open browser , take them fb page      } } 

    boolean installed  = appinstalledornot("com.example.package");             if(installed){                 final intent intent = new intent(intent.action_main, null);                  final componentname cn = new componentname("com.example.package",                        "com.example.package.activityclass" );                 intent.setcomponent(cn);                 intent.addcategory(intent.category_launcher);                 intent.setflags(intent.flag_activity_new_task);                     mcontext.startactivity(intent); }else{      // not installed              string marketuri = "market://details?id=com.example.package";                  intent gotomarket = new intent(intent.action_view)                                     .setdata(uri.parse(marketuri));                    startactivity(gotomarket); }      }         public static boolean appinstalledornot(string package)         {             packagemanager pm = getpackagemanager();             boolean app_installed;             try             {                 pm.getpackageinfo(package, packagemanager.get_activities);                 app_installed = true;             }             catch (packagemanager.namenotfoundexception e)             {                 app_installed = false;             }             return app_installed ;         } 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -