2014-09-09 2 views
0

Android 사진 앱을 만들었으며 인 텐트를 사용하여 페이스 북, 트위터, 인스 타 그램에 이미지 공유 기능을 추가했지만 이미지 공유 앱 페이스 북, 트위터, 인스 타 그램 앱이 기기에 설치되지 않은 경우 충돌이 발생합니다.내 기기에 facebook 앱이 설치되어 있는지 확인하거나 프로그래밍 방식으로 내 기기에 설치되지 않은 경우

+0

힌트 : http://stackoverflow.com/questions/6711295/how-to-check-if-facebook-is-installed-android – geekInMe

답변

5

com.facebook.android 또는 com.facebook.katana와 패키지 이름을 대체 want.Just 무엇 question.It 당신을 줄 것이다 this 참조

코드 :

public class Example extends Activity { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     //Put the package name here... 
     boolean installed = appInstalledOrNot("com.Ch.Example.pack"); 
     if(installed) { 
      //This intent will help you to launch if the package is already installed 
      Intent LaunchIntent = getPackageManager() 
       .getLaunchIntentForPackage("com.facebook.katana");//if this name does not work provide the other one 
      startActivity(LaunchIntent); 

      System.out.println("App already installed on your phone");   
     } 
     else { 
      System.out.println("App is not installed on your phone"); 
     } 
    } 

    private boolean appInstalledOrNot(String uri) { 
     PackageManager pm = getPackageManager(); 
     boolean app_installed = false; 
     try { 
      pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES); 
      app_installed = true; 
     } 
     catch (PackageManager.NameNotFoundException e) { 
      app_installed = false; 
     } 
     return app_installed ; 
    } 
} 
+0

감사합니다. "com.facebook.katana"만 나를 위해 일했습니다 – tieorange

+0

appInstalledOrNot() 접근 방식에 권한이 필요합니까? – Bootstrapper

관련 문제