0

앱이 Android에 이미 설치되어있는 경우 알림을 제공하는 방법, 안드로이드 마켓에 대한 링크를 제공하는 방법이 아닌 경우 ???
이 나는 ​​조건이 실패 할 경우, 문제는 루프가 계속 경우 실행되는앱이 이미 Android에 설치되어있는 경우 알림을 제공하는 방법

public void onClick(View v) 
    { 
      final PackageManager pm = getPackageManager(); 
      //here i get set of installed apps 
     List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA); 

     for (ApplicationInfo packageInfo : packages) 
     { 
      //how do i check for installed package with clicked package 

      String data=packageInfo.packageName; 

      if(data.equals("com.bb")) 
      { 
      String TAG ="MyActivity"; 
      Log.d(TAG, "Installed package :" + packageInfo.packageName); 
      Log.d(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName)); 
      Toast.makeText(Listing.this, "You have Installed this Package:com.bb" , Toast.LENGTH_SHORT).show(); 

      } 

       //if the package is not installed, do this 

        else 
      { 


      String dictionary=items[position]; 
      Toast.makeText(Listing.this, dictionary , Toast.LENGTH_SHORT).show(); 


      if(dictionary.equalsIgnoreCase("Acronyms")) 
      { 
       String dictionary2="MAcronyms"; 
       Intent intent = new Intent(Intent.ACTION_VIEW); 
       intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=com." + dictionary2)); 
       startActivity(intent); 
      } 
        } 
       } 
      } 

을 종료 할 필요가 여기에 루프를 들어 여기에

을 시도

(eg..55 시간을 위해 다른 블록을 입력)

답변

0
 public void onClick(View v) 
     { 

    String str = "aaa"; 

    if(package1(str)==1) 
    { 
     Toast.makeText(Listing.this, "You have Installed this Package:aaa" , Toast.LENGTH_SHORT).show(); 
    } 
    else 
    { 
      String dictionary2="bba"; 
      Intent intent = new Intent(Intent.ACTION_VIEW); 
      intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=com." + dictionary2)); 
      startActivity(intent); 
    } 

    } 

    } 

public int package1(String str) 
{ 
     int i=0; 

     final PackageManager pm = getPackageManager(); 
     //get a list of installed apps. 
     List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA); 

     for (ApplicationInfo packageInfo : packages) 
     { 

      String data=packageInfo.packageName; 
      if(data.equals(str)) 
      { 
      i=1; 

      } 
       else 
        { 
        //i=0; 

        } 

       } 
       return i; 

       } 
1

시도 클린업> 다음 다음 구축하고, 그래, 내가 그랬어

public void onClick(View v) 
{ 
    final PackageManager pm = getPackageManager(); 
    //here i get set of installed apps 
    List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA); 

    for (ApplicationInfo packageInfo : packages) 
    { 
     //how do i check for installed package with clicked package 

     String data=packageInfo.packageName; 

     if(data.equals("com.bb")) 
     { 
      String TAG ="MyActivity"; 
      Log.d(TAG, "Installed package :" + packageInfo.packageName); 
      Log.d(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName)); 
      Toast.makeText(Listing.this, "You have Installed this Package:com.bb" , Toast.LENGTH_SHORT).show(); 
      break; 
     }else{//if the package is not installed, do this 


      String dictionary=items[position]; 
      Toast.makeText(Listing.this, dictionary , Toast.LENGTH_SHORT).show(); 


      if(dictionary.equalsIgnoreCase("Acronyms")) 
      { 
       String dictionary2="MAcronyms"; 
       Intent intent = new Intent(Intent.ACTION_VIEW); 
       intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=com." + dictionary2)); 
       startActivity(intent); 
      } 
     } 
    } 
} 
+0

코드 - 하지만, 그렇지 않으면 반복 55 시간 동안 뛰기 시작했습니다 –

+0

뭐라고 요? 확실합니까? 이제 깨끗하게 지어주세요. 그리고 업데이트 된 답변을 시도하십시오. 또는 단순히 붙여 넣기 복사하십시오. – Rajkiran

+0

패키지에는 55 팩 이름이 포함됩니다 ... for 루프가 55 번 실행되므로 loop do을 참조하십시오. –

관련 문제