لقد فتحت متجر 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). أحتاج إلى فتح التطبيق في متجر 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)));
}
نحن نستخدم كتلة try/catch
هنا لأن Exception
سيتم طرحها إذا لم يتم تثبيت Play Store على الجهاز المستهدف.
NOTE: يمكن لأي تطبيق تسجيل قدرته على التعامل مع market://details?id=<appId>
Uri ، إذا كنت ترغب في استهداف Google Play على وجه التحديد ، فتحقق من إجابة Berťák
تشير العديد من الإجابات هنا إلى استخدام Uri.parse("market://details?id=" + appPackageName))
لفتح Google Play ، لكنني أعتقد أنها غير كافية في الواقع:
يمكن لبعض تطبيقات الجهات الخارجية استخدام مرشحات النوايا الخاصة بها مع تحديد مخطط "market://"
، وبالتالي يمكنهم معالجة Uri الموفر بدلاً من Google Play (لقد واجهت هذا الموقف مع تطبيق e.g.SnapPea). السؤال هو "كيفية فتح متجر 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 مباشرة.
UPDATE: في بعض الأحيان يبدو أنه يفتح تطبيق GP فقط ، دون فتح ملف تعريف التطبيق. كما اقترح TrevorWiley في تعليقه ، يمكن لـ Intent.FLAG_ACTIVITY_CLEAR_TOP
حل المشكلة. (لم أختبرها بنفسي بعد ...)
انظر هذه الإجابة لفهم ما يفعله Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
.
انتقل إلى الرابط الرسمي لمطوّر Android كمعرف تعليمي خطوة بخطوة ، وحصل على رمز حزمة التطبيقات الخاصة بك من متجر Play إذا كان موجودًا أو تطبيقات Play Store غير موجودة ، ثم افتح التطبيق من متصفح الويب.
رابط Android Developer الرسمي
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 Store app مثبتًا ، وإذا كان الأمر كذلك ، يمكنك استخدام "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);
استخدام السوق: //
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + my_packagename));
في حين أن إجابة إريك صحيحة ورمز 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 Store. إذا لم يكن هناك متجر Play مثبتًا ، فسيتم القبض على Exception
.
يمكنك ان تفعل:
final Uri marketUri = Uri.parse("market://details?id=" + packageName);
startActivity(new Intent(Intent.ACTION_VIEW, marketUri));
الحصول على مرجع هنا :
يمكنك أيضًا تجربة الطريقة الموضحة في الإجابة المقبولة لهذا السؤال: لا يمكن تحديد ما إذا كان متجر Google Play مثبتًا أم لا على جهاز Android
حل جاهز للاستخدام:
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()
حتى يرى المستخدمون تفاصيل تطبيقك فيتطبيق متجر Google Play} _ بدلاً من محدد . ل KOTLIN
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);
ل KOTLIN
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)
إذا كنت ترغب في فتح متجر Google Play من تطبيقك ، فاستخدم الأمر التالي: market://details?gotohome=com.yourAppName
، فسيفتح صفحات متجر Google Play على تطبيقك.
عرض جميع التطبيقات بواسطة ناشر محدد
ابحث عن التطبيقات التي تستخدم Query على العنوان أو الوصف
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)));
}
}
إليك الرمز النهائي من الإجابات أعلاه التي تحاول أولاً فتح التطبيق باستخدام تطبيق Google Play Store وتحديداً متجر 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);
}
}
بلدي وظيفة kotlin entension لهذا الغرض
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))
لقد قمت بدمج كل من Berťák و Stefano 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"); }
@OnClick(R.id.ll_rate_this_app) public void openAppInPlayStore() { openPlayStore(false, ""); }
سيفتح هذا الرابط التطبيق تلقائيًا في السوق: // إذا كنت تعمل بنظام Android ومتصفح إذا كنت تستخدم جهاز الكمبيوتر.
https://play.app.goo.gl/?link=https://play.google.com/store/apps/details?id=com.app.id&ddl=1&pcampaignid=web_ddl_1
وهناك نسخة kotlin مع احتياطي وبناء الجملة الحالي
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)
}
}
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));
}