Programing

내 Android 애플리케이션에서 직접 Google Play 스토어를 여는 방법은 무엇입니까?

lottogame 2020. 2. 11. 22:17
반응형

내 Android 애플리케이션에서 직접 Google Play 스토어를 여는 방법은 무엇입니까?


다음 코드를 사용하여 Google Play 스토어를 열었습니다.

Intent i = new Intent(android.content.Intent.ACTION_VIEW);
i.setData(Uri.parse("https://play.google.com/store/apps/details?id=my packagename "));
startActivity(i);.

그러나 옵션 (브라우저 / 플레이 스토어)을 선택하는 완전한 작업보기가 표시됩니다. Play 스토어에서 애플리케이션을 직접 열어야합니다.


market://접두사를 사용하여이 작업을 수행 할 수 있습니다 .

final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object
try {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe) {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}

대상 기기에 Play 스토어가 설치되어 있지 않으면이 try/catch블록이 사용 되므로 여기서 블록을 사용합니다 Exception.

참고 : market://details?id=<appId>Google Play를 구체적으로 타겟팅하려면 Berťák 답변을 확인하려는 경우 모든 앱이 Uri 를 처리 할 수있는 것으로 등록 할 수 있습니다


여기에 많은 답변이 Uri.parse("market://details?id=" + appPackageName)) Google Play를 여는 데 사용 하는 것이 좋지만 실제로 는 충분하지 않습니다 .

일부 타사 응용 프로그램은 "market://"scheme 정의 된 자체 인 텐트 필터를 사용할 수 있으므로 Google Play 대신 제공된 Uri를 처리 할 수 ​​있습니다 (eg 이러한 상황은 egSnapPea 응용 프로그램에서 발생했습니다). 문제는 "Google Play 스토어를 여는 방법"입니다. 따라서 다른 응용 프로그램을 열고 싶지 않다고 가정합니다. 예를 들어 앱 등급은 GP Store 앱 등에서 만 관련이 있습니다.

Google Play와 Google Play 만 열려면이 방법을 사용합니다.

public static void openAppRating(Context context) {
    // you can also use BuildConfig.APPLICATION_ID
    String appId = context.getPackageName();
    Intent rateIntent = new Intent(Intent.ACTION_VIEW,
        Uri.parse("market://details?id=" + appId));
    boolean marketFound = false;

    // find all applications able to handle our rateIntent
    final List<ResolveInfo> otherApps = context.getPackageManager()
        .queryIntentActivities(rateIntent, 0);
    for (ResolveInfo otherApp: otherApps) {
        // look for Google Play application
        if (otherApp.activityInfo.applicationInfo.packageName
                .equals("com.android.vending")) {

            ActivityInfo otherAppActivity = otherApp.activityInfo;
            ComponentName componentName = new ComponentName(
                    otherAppActivity.applicationInfo.packageName,
                    otherAppActivity.name
                    );
            // make sure it does NOT open in the stack of your activity
            rateIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            // task reparenting if needed
            rateIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
            // if the Google Play was already open in a search result
            //  this make sure it still go to the app page you requested
            rateIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            // this make sure only the Google Play app is allowed to
            // intercept the intent
            rateIntent.setComponent(componentName);
            context.startActivity(rateIntent);
            marketFound = true;
            break;

        }
    }

    // if GP not present on device, open web browser
    if (!marketFound) {
        Intent webIntent = new Intent(Intent.ACTION_VIEW,
            Uri.parse("https://play.google.com/store/apps/details?id="+appId));
        context.startActivity(webIntent);
    }
}

요점은 Google Play 이외의 더 많은 응용 프로그램이 우리의 의도를 열 수 있으면 응용 프로그램 선택 대화 상자를 건너 뛰고 GP 응용 프로그램이 직접 시작된다는 것입니다.

업데이트 : 때로는 앱의 프로필을 열지 않고 GP 앱 만 여는 것처럼 보입니다. TrevorWiley가 자신의 의견에서 제안한 것처럼 Intent.FLAG_ACTIVITY_CLEAR_TOP문제를 해결할 수 있습니다. (아직 테스트하지 않았습니다 ...)

무엇을 이해하려면 이 답변참조하십시오 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED.


단계별로 튜토리얼로 Android 개발자 공식 링크로 이동하여 Play 스토어에서 애플리케이션 패키지에 대한 코드를 보거나 가져 오거나 Play 스토어 앱이 없으면 웹 브라우저에서 애플리케이션을 엽니 다.

안드로이드 개발자 공식 링크

http://developer.android.com/distribute/tools/promote/linking.html

응용 프로그램 페이지에 연결

웹 사이트에서 : http://play.google.com/store/apps/details?id=<package_name>

Android 앱에서 : market://details?id=<package_name>

제품 목록에 연결

웹 사이트에서 : http://play.google.com/store/search?q=pub:<publisher_name>

Android 앱에서 : market://search?q=pub:<publisher_name>

검색 결과에 연결

웹 사이트에서 : http://play.google.com/store/search?q=<search_query>&c=apps

Android 앱에서 : market://search?q=<seach_query>&c=apps


이 시도

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.example.android"));
startActivity(intent);

실제로 Google Play (또는 다른 앱)를 독립적으로 열려면 위의 모든 답변이 동일한 앱의 새로운보기에서 Google Play를 엽니 다.

Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.android.vending");

// package name and activity
ComponentName comp = new ComponentName("com.android.vending",
                                       "com.google.android.finsky.activities.LaunchUrlHandlerActivity"); 
launchIntent.setComponent(comp);

// sample to open facebook app
launchIntent.setData(Uri.parse("market://details?id=com.facebook.katana"));
startActivity(launchIntent);

중요한 부분은 실제로 Google Play 또는 다른 앱을 독립적으로 여는 것입니다.

내가 본 것의 대부분은 다른 답변의 접근 방식을 사용하며 이것이 누군가에게 도움이되기를 바라는 것은 아닙니다.

문안 인사.


Google Play 스토어 앱이 설치되어 있는지 확인할 수 있으며이 경우 "market : //" 프로토콜을 사용할 수 있습니다 .

final String my_package_name = "........."  // <- HERE YOUR PACKAGE NAME!!
String url = "";

try {
    //Check whether Google Play store is installed or not:
    this.getPackageManager().getPackageInfo("com.android.vending", 0);

    url = "market://details?id=" + my_package_name;
} catch ( final Exception e ) {
    url = "https://play.google.com/store/apps/details?id=" + my_package_name;
}


//Open the app page in Google Play store:
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivity(intent);

market : // 사용

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + my_packagename));

Eric의 대답은 정확하지만 Berťák의 코드도 작동합니다. 나는 이것이 더 우아하게 결합한다고 생각합니다.

try {
    Intent appStoreIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName));
    appStoreIntent.setPackage("com.android.vending");

    startActivity(appStoreIntent);
} catch (android.content.ActivityNotFoundException exception) {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}

를 사용 setPackage하면 기기에서 Play 스토어를 사용하도록합니다. Play 스토어가 설치되어 있지 않으면가 Exception발견됩니다.


넌 할 수있어:

final Uri marketUri = Uri.parse("market://details?id=" + packageName);
startActivity(new Intent(Intent.ACTION_VIEW, marketUri));

여기에서 참조 하십시오 :

이 질문에 대한 답변에서 설명한 방법을 시도해 볼 수도 있습니다 . Android 기기에 Google Play 스토어가 설치되어 있는지 여부를 확인할 수 없습니다


즉시 사용 가능한 솔루션 :

public class GoogleServicesUtils {

    public static void openAppInGooglePlay(Context context) {
        final String appPackageName = context.getPackageName();
        try {
            context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
        } catch (android.content.ActivityNotFoundException e) { // if there is no Google Play on device
            context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
        }
    }

}

에릭의 답변을 바탕으로합니다.


파티에서 늦게 공식 문서 가 여기 있습니다. 그리고 설명 된 코드는

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(
    "https://play.google.com/store/apps/details?id=com.example.android"));
intent.setPackage("com.android.vending");
startActivity(intent);

이 의도를 구성 할 때, 통과 "com.android.vending"Intent.setPackage()사용자가에서 앱의 세부 정보를 볼 수 있도록 구글 플레이 스토어 앱 대신 츄 . 코 틀린

val intent = Intent(Intent.ACTION_VIEW).apply {
    data = Uri.parse(
            "https://play.google.com/store/apps/details?id=com.example.android")
    setPackage("com.android.vending")
}
startActivity(intent)

Google Play Instant를 사용하여 인스턴트 앱을 게시 한 경우 다음과 같이 앱을 시작할 수 있습니다.

Intent intent = new Intent(Intent.ACTION_VIEW);
Uri.Builder uriBuilder = Uri.parse("https://play.google.com/store/apps/details")
    .buildUpon()
    .appendQueryParameter("id", "com.example.android")
    .appendQueryParameter("launch", "true");

// Optional parameters, such as referrer, are passed onto the launched
// instant app. You can retrieve these parameters using
// Activity.getIntent().getData().
uriBuilder.appendQueryParameter("referrer", "exampleCampaignId");

intent.setData(uriBuilder.build());
intent.setPackage("com.android.vending");
startActivity(intent);

코 틀린

val uriBuilder = Uri.parse("https://play.google.com/store/apps/details")
        .buildUpon()
        .appendQueryParameter("id", "com.example.android")
        .appendQueryParameter("launch", "true")

// Optional parameters, such as referrer, are passed onto the launched
// instant app. You can retrieve these parameters using Activity.intent.data.
uriBuilder.appendQueryParameter("referrer", "exampleCampaignId")

val intent = Intent(Intent.ACTION_VIEW).apply {
    data = uriBuilder.build()
    setPackage("com.android.vending")
}
startActivity(intent)

으로 공식 문서를 사용하는 https://대신에 market://,이 수확기 에릭의 코드 재사용와 M3-N50의 대답 (중복 배제) :

Intent intent = new Intent(Intent.ACTION_VIEW)
    .setData(Uri.parse("https://play.google.com/store/apps/details?id=" + getPackageName()));
try {
    startActivity(new Intent(intent)
                  .setPackage("com.android.vending"));
} catch (android.content.ActivityNotFoundException exception) {
    startActivity(intent);
}

GPlay 앱이 있으면 열려고 기본으로 돌아갑니다.


앱에서 Google Play 스토어를 열려면이 명령 directy :를 사용하면 market://details?gotohome=com.yourAppName앱의 Google Play 스토어 페이지가 열립니다.

특정 게시자의 모든 앱 표시

제목이나 설명에서 검색어를 사용하는 앱 검색

참조 : https://tricklio.com/market-details-gotohome-1/


public void launchPlayStore(Context context, String packageName) {
    Intent intent = null;
    try {
            intent = new Intent(Intent.ACTION_VIEW);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setData(Uri.parse("market://details?id=" + packageName));
            context.startActivity(intent);
        } catch (android.content.ActivityNotFoundException anfe) {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + packageName)));
        }
    }

이 목적을위한 나의 kotlin 인텐션

fun Context.canPerformIntent(intent: Intent): Boolean {
        val mgr = this.packageManager
        val list = mgr.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
        return list.size > 0
    }

그리고 당신의 활동에서

val uri = if (canPerformIntent(Intent(Intent.ACTION_VIEW, Uri.parse("market://")))) {
            Uri.parse("market://details?id=" + appPackageName)
        } else {
            Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)
        }
        startActivity(Intent(Intent.ACTION_VIEW, uri))

위의 답변 중 마지막 코드는 Google Play 스토어 앱을 사용하여 앱을 열려고 시도하고, 특히 Play 스토어를 실패하면 웹 버전을 사용하여 작업보기를 시작합니다. 크레딧은 @Eric, @Jonathan Caballero입니다.

public void goToPlayStore() {
        String playStoreMarketUrl = "market://details?id=";
        String playStoreWebUrl = "https://play.google.com/store/apps/details?id=";
        String packageName = getActivity().getPackageName();
        try {
            Intent intent =  getActivity()
                            .getPackageManager()
                            .getLaunchIntentForPackage("com.android.vending");
            if (intent != null) {
                ComponentName androidComponent = new ComponentName("com.android.vending",
                        "com.google.android.finsky.activities.LaunchUrlHandlerActivity");
                intent.setComponent(androidComponent);
                intent.setData(Uri.parse(playStoreMarketUrl + packageName));
            } else {
                intent = new Intent(Intent.ACTION_VIEW, Uri.parse(playStoreMarketUrl + packageName));
            }
            startActivity(intent);
        } catch (ActivityNotFoundException e) {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(playStoreWebUrl + packageName));
            startActivity(intent);
        }
    }

코 틀린 :

신장:

fun Activity.openAppInGooglePlay(){

val appId = BuildConfig.APPLICATION_ID
try {
    this.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$appId")))
} catch (anfe: ActivityNotFoundException) {
    this.startActivity(
        Intent(
            Intent.ACTION_VIEW,
            Uri.parse("https://play.google.com/store/apps/details?id=$appId")
        )
    )
}}

방법:

    fun openAppInGooglePlay(activity:Activity){

        val appId = BuildConfig.APPLICATION_ID
        try {
            activity.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$appId")))
        } catch (anfe: ActivityNotFoundException) {
            activity.startActivity(
                Intent(
                    Intent.ACTION_VIEW,
                    Uri.parse("https://play.google.com/store/apps/details?id=$appId")
                )
            )
        }
    }

BerťákStefano Munarini의 답변을 결합 하여이 앱 평가더 많은 앱 표시 시나리오를 모두 처리하는 하이브리드 솔루션을 만들었습니다 .

        /**
         * This method checks if GooglePlay is installed or not on the device and accordingly handle
         * Intents to view for rate App or Publisher's Profile
         *
         * @param showPublisherProfile pass true if you want to open Publisher Page else pass false to open APp page
         * @param publisherID          pass Dev ID if you have passed PublisherProfile true
         */
        public void openPlayStore(boolean showPublisherProfile, String publisherID) {

            //Error Handling
            if (publisherID == null || !publisherID.isEmpty()) {
                publisherID = "";
                //Log and continue
                Log.w("openPlayStore Method", "publisherID is invalid");
            }

            Intent openPlayStoreIntent;
            boolean isGooglePlayInstalled = false;

            if (showPublisherProfile) {
                //Open Publishers Profile on PlayStore
                openPlayStoreIntent = new Intent(Intent.ACTION_VIEW,
                        Uri.parse("market://search?q=pub:" + publisherID));
            } else {
                //Open this App on PlayStore
                openPlayStoreIntent = new Intent(Intent.ACTION_VIEW,
                        Uri.parse("market://details?id=" + getPackageName()));
            }

            // find all applications who can handle openPlayStoreIntent
            final List<ResolveInfo> otherApps = getPackageManager()
                    .queryIntentActivities(openPlayStoreIntent, 0);
            for (ResolveInfo otherApp : otherApps) {

                // look for Google Play application
                if (otherApp.activityInfo.applicationInfo.packageName.equals("com.android.vending")) {

                    ActivityInfo otherAppActivity = otherApp.activityInfo;
                    ComponentName componentName = new ComponentName(
                            otherAppActivity.applicationInfo.packageName,
                            otherAppActivity.name
                    );
                    // make sure it does NOT open in the stack of your activity
                    openPlayStoreIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    // task reparenting if needed
                    openPlayStoreIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                    // if the Google Play was already open in a search result
                    //  this make sure it still go to the app page you requested
                    openPlayStoreIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    // this make sure only the Google Play app is allowed to
                    // intercept the intent
                    openPlayStoreIntent.setComponent(componentName);
                    startActivity(openPlayStoreIntent);
                    isGooglePlayInstalled = true;
                    break;

                }
            }
            // if Google Play is not Installed on the device, open web browser
            if (!isGooglePlayInstalled) {

                Intent webIntent;
                if (showPublisherProfile) {
                    //Open Publishers Profile on web browser
                    webIntent = new Intent(Intent.ACTION_VIEW,
                            Uri.parse("http://play.google.com/store/search?q=pub:" + getPackageName()));
                } else {
                    //Open this App on web browser
                    webIntent = new Intent(Intent.ACTION_VIEW,
                            Uri.parse("https://play.google.com/store/apps/details?id=" + getPackageName()));
                }
                startActivity(webIntent);
            }
        }

용법

  • 게시자 프로필을 열려면
   @OnClick(R.id.ll_more_apps)
        public void showMoreApps() {
            openPlayStore(true, "Hitesh Sahu");
        }
  • PlayStore에서 앱 페이지를 열려면
@OnClick(R.id.ll_rate_this_app)
public void openAppInPlayStore() {
    openPlayStore(false, "");
}

이 링크는 Android에 있으면 market : //에 있고 PC에 있으면 브라우저에 자동으로 앱을 엽니 다.

https://play.app.goo.gl/?link=https://play.google.com/store/apps/details?id=com.app.id&ddl=1&pcampaignid=web_ddl_1

코 틀린

fun openAppInPlayStore(appPackageName: String) {
    try {
        startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$appPackageName")))
    } catch (exception: android.content.ActivityNotFoundException) {
        startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=$appPackageName")))
    }
}

여러분, 실제로 더 많은 것을 얻을 수 있다는 것을 잊지 마십시오. 예를 들어 UTM 추적을 의미합니다. https://developers.google.com/analytics/devguides/collection/android/v4/campaigns

public static final String MODULE_ICON_PACK_FREE = "com.example.iconpack_free";
public static final String APP_STORE_URI =
        "market://details?id=%s&referrer=utm_source=%s&utm_medium=app&utm_campaign=plugin";
public static final String APP_STORE_GENERIC_URI =
        "https://play.google.com/store/apps/details?id=%s&referrer=utm_source=%s&utm_medium=app&utm_campaign=plugin";

try {
    startActivity(new Intent(
        Intent.ACTION_VIEW,
        Uri.parse(String.format(Locale.US,
            APP_STORE_URI,
            MODULE_ICON_PACK_FREE,
            getPackageName()))).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
} catch (android.content.ActivityNotFoundException anfe) {
    startActivity(new Intent(
        Intent.ACTION_VIEW,
        Uri.parse(String.format(Locale.US,
            APP_STORE_GENERIC_URI,
            MODULE_ICON_PACK_FREE,
            getPackageName()))).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
}

폴백 및 현재 구문이있는 코 틀린 버전

 fun openAppInPlayStore() {
    val uri = Uri.parse("market://details?id=" + context.packageName)
    val goToMarketIntent = Intent(Intent.ACTION_VIEW, uri)

    var flags = Intent.FLAG_ACTIVITY_NO_HISTORY or Intent.FLAG_ACTIVITY_MULTIPLE_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
    flags = if (Build.VERSION.SDK_INT >= 21) {
        flags or Intent.FLAG_ACTIVITY_NEW_DOCUMENT
    } else {
        flags or Intent.FLAG_ACTIVITY_CLEAR_TASK
    }

    goToMarketIntent.addFlags(flags)

    try {
        startActivity(context, goToMarketIntent, null)
    } catch (e: ActivityNotFoundException) {
        val intent = Intent(Intent.ACTION_VIEW,
                Uri.parse("http://play.google.com/store/apps/details?id=" + context.packageName))

        startActivity(context, intent, null)
    }
}

참고 URL : https://stackoverflow.com/questions/11753000/how-to-open-the-google-play-store-directly-from-my-android-application



반응형