2011-08-01 2 views
15

현재 Android에서 응용 프로그램을 개발하고 있습니다. 현재 응용 프로그램을 평가하기 위해 사용자에게 일부 기능을 제공하고 싶습니다. 사용자가 클릭하면 응용 프로그램을 평가할지 여부를 묻는 버튼이 표시됩니다. 예 (시장에서이 애플리케이션을 보여 주어야합니다.) 애플리케이션을 평가하려면 기기의 마켓 애플리케이션으로 이동하거나 브라우저를 열어이 애플리케이션을 표시하는 시장 &을로드합니다. 이전에 이런 종류의 기능을 사용했습니다. 도움을주세요.응용 프로그램을 사용하여 시장에서 평가하기

감사합니다.

답변

40

나는 항상이 같은 방법을 사용

private void launchMarket() { 
    Uri uri = Uri.parse("market://details?id=" + getPackageName()); 
    Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri); 
    try { 
     startActivity(goToMarket); 
    } catch (ActivityNotFoundException e) { 
     Toast.makeText(this, R.string.couldnt_launch_market, Toast.LENGTH_LONG).show(); 
    } 
} 
+1

@Cristian --- 빠른 답장을 보내 주셔서 감사합니다 .. getPackageName() 대신에 응용 프로그램 패키지를 제공해야합니까? 또한 장치를 감지해야 할 필요가 있다고 생각합니까? 일반적으로 장치에 있어야하지만 사용자가 제거한 경우 시장 앱을 확인하는 방법은 있습니까? –

+1

http://developer.android.com/reference/android/content/Context.html#getPackageName%28%29 아니요, 패키지 이름을 가져옵니다. 마켓 앱이 설치되지 않은 경우 예외가 발생하고 축배가 표시됩니다. – Rob

+0

감사합니다 Cristian ... –

2
public class AppRater { 
private final static String APP_TITLE = "App Name";// App Name 
private final static String APP_PNAME = "com.example.name";// Package Name 

private final static int DAYS_UNTIL_PROMPT = 3;//Min number of days 
private final static int LAUNCHES_UNTIL_PROMPT = 3;//Min number of launches 

public static void app_launched(Context mContext) { 
    SharedPreferences prefs = mContext.getSharedPreferences("apprater", 0); 
    if (prefs.getBoolean("dontshowagain", false)) { return ; } 

    SharedPreferences.Editor editor = prefs.edit(); 

    // Increment launch counter 
    long launch_count = prefs.getLong("launch_count", 0) + 1; 
    editor.putLong("launch_count", launch_count); 

    // Get date of first launch 
    Long date_firstLaunch = prefs.getLong("date_firstlaunch", 0); 
    if (date_firstLaunch == 0) { 
     date_firstLaunch = System.currentTimeMillis(); 
     editor.putLong("date_firstlaunch", date_firstLaunch); 
    } 

    // Wait at least n days before opening 
    if (launch_count >= LAUNCHES_UNTIL_PROMPT) { 
     if (System.currentTimeMillis() >= date_firstLaunch + 
       (DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000)) { 
      showRateDialog(mContext, editor); 
     } 
    } 

    editor.commit(); 
} 

public static void showRateDialog(final Context mContext, final SharedPreferences.Editor editor) { 
    final Dialog dialog = new Dialog(mContext); 
    dialog.setTitle("Rate " + APP_TITLE); 

    LinearLayout ll = new LinearLayout(mContext); 
    ll.setOrientation(LinearLayout.VERTICAL); 

    TextView tv = new TextView(mContext); 
    tv.setText("If you enjoy using " + APP_TITLE + ", please take a moment to rate it. Thanks for your support!"); 
    tv.setWidth(240); 
    tv.setPadding(4, 0, 4, 10); 
    ll.addView(tv); 

    Button b1 = new Button(mContext); 
    b1.setText("Rate " + APP_TITLE); 
    b1.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + APP_PNAME))); 
      dialog.dismiss(); 
     } 
    });   
    ll.addView(b1); 

    Button b2 = new Button(mContext); 
    b2.setText("Remind me later"); 
    b2.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      dialog.dismiss(); 
     } 
    }); 
    ll.addView(b2); 

    Button b3 = new Button(mContext); 
    b3.setText("No, thanks"); 
    b3.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      if (editor != null) { 
       editor.putBoolean("dontshowagain", true); 
       editor.commit(); 
      } 
      dialog.dismiss(); 
     } 
    }); 
    ll.addView(b3); 

    dialog.setContentView(ll);   
    dialog.show();   
}} 

지금과 같은 활동에 클래스를 통합 ->

AppRater.app_launched(this); 
+2

사용자가 이미 우리에게 등급을 매겼는지 여부를 어떻게 확인할 수 있습니까 ??? –

+0

우리의 앱을 방문하여 사용하는 경우 처리 방법 ... 평가가 없습니까? –

관련 문제