How to launch Play Store in libgdx - android

Hi i am creating a simple game and i want yo know how to launch Play Store in ligbdx when someone would like to rate my game.
Please help!
Thanks

You have two options :
Either open directly by using complete URL (generic for all platform)
Gdx.net.openURI("https://play.google.com/store/apps/details?id=com.xyz.abc");
Use interfacing and implement platform specific APIs.
eg. like for Android
public void rate(){
Intent rateIntent = new Intent(Intent.ACTION_VIEW,Uri.parse("https://play.google.com/store/apps/details?id=com.xyz.abc"));
//or
//Intent rateIntent = new Intent(Intent.ACTION_VIEW,Uri.parse("https://play.google.com/store/apps/details?id="+getPackageName()));
startActivity(rateIntent);
}
It prompt a choose dialog, having browser and Playstore app (If PlayStore installed in device) option. choose PlayStore.
EDIT
try {
Intent viewIntent = new Intent(Intent.ACTION_VIEW,Uri.parse("market://details?id=" + getPackageName()));
startActivity(viewIntent);
}catch (android.content.ActivityNotFoundException anfe){
String url="https://play.google.com/store/apps/details?id="+getPackageName();
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
if (intent.resolveActivity(getPackageManager())!=null) {
startActivity(intent);
}
}

Related

How to open the Huawei AppGallery directly?

I know that is possible to open my app (based on package name) in Google Play Store, but how to do same in Huawei AppGallery?
Opening your app in the Huawei App Gallery is similar to opening Google Play Store:
Huawei App Gallery:
Scheme: market:// or appmarket://
Package: com.huawei.appmarket
vs. Google Play Store:
Scheme: market://
Package: com.android.vending
Here is a snippet for the Huawei App Gallery:
private void startHuaweiAppGallery() {
Uri detailsUri = Uri.parse("market://details?id=" + getPackageName());
Intent intent = new Intent(Intent.ACTION_VIEW, detailsUri);
List<ResolveInfo> otherApps =
getPackageManager().queryIntentActivities(intent, 0);
for (ResolveInfo app : otherApps) {
String packageName = app.activityInfo.applicationInfo.packageName;
if (!packageName.equals("com.huawei.appmarket")) {
continue;
}
intent.addFlags(
Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED |
Intent.FLAG_ACTIVITY_CLEAR_TOP
);
intent.setComponent(new ComponentName(packageName, app.activityInfo.name));
startActivity(intent);
return;
}
//Huawei App Gallery N/A. Open app link in browser.
//Huawei App ID can be found in the Huawei developer console
final string huaweiAppID = "100864605";
//ex. https://appgallery.cloud.huawei.com/marketshare/app/C100864605
Uri appUri = Uri.parse(
"https://appgallery.cloud.huawei.com/marketshare/app/C" + huaweiAppID
);
intent = new Intent(Intent.ACTION_VIEW, appUri);
startActivity(intent);
}
Here is the snippet for Google Play:
private void startGooglePlay() {
Uri detailsUri = Uri.parse("market://details?id=" + getPackageName());
Intent intent = new Intent(Intent.ACTION_VIEW, detailsUri);
List<ResolveInfo> otherApps =
getPackageManager().queryIntentActivities(intent, 0);
for (ResolveInfo app : otherApps) {
String packageName = app.activityInfo.applicationInfo.packageName;
if (!packageName.equals("com.android.vending")) {
continue;
}
intent.addFlags(
Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED |
Intent.FLAG_ACTIVITY_CLEAR_TOP
);
intent.setComponent(new ComponentName(packageName, app.activityInfo.name));
startActivity(intent);
return;
}
//Google Play N/A. Open app link in browser.
Uri appUri = Uri.parse(
"https://play.google.com/store/apps/details?id=" + getPackageName()
);
intent = new Intent(Intent.ACTION_VIEW, appUri);
startActivity(intent);
}
Here is the snippet to allow the user to pick Any Available Store on the device:
private void startAnyStore() {
Uri detailsUri = Uri.parse("market://details?id=" + getPackageName());
Intent intent = new Intent(Intent.ACTION_VIEW, detailsUri);
intent.addFlags(
Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED |
Intent.FLAG_ACTIVITY_CLEAR_TOP
);
startActivity(intent);
}
I agree with #Pierre
But I also think you can resolve activity with links
https://appgallery8.huawei.com/#/app/C<HUAWEI_APP_ID>
or
https://appgallery.cloud.huawei.com/uowap/index.html#/detailApp/C<HUAWEI_APP_ID>?appId=C<HUAWEI_APP_ID>
For example, https://appgallery.cloud.huawei.com/uowap/index.html#/detailApp/C101652909?appId=C101652909
If your application has already released on the Huawei Appgallery, then you can use this url to open the application directly.
URL with the appid of your applcation, for example the AppGallery's appid is 27162, then can open it with this URL
https://appgallery.huawei.com/#/app/C27162
You can replace the appid with your own appid .
URL with the package name of your application, for example the AppGallery's package name is com.huawei.appmarket, then can open it with this URL
https://appgallery.cloud.huawei.com/appDetail?pkgName=com.huawei.appmarket
You can replace the package name with your own package name.
Wish it can be helpful.
It seems Huawei App Gallery can now open the details page with the same URI that works for Google Play: market://details?id=<applicationId>
I just tried it out on AppGallery v11.1.2.304 with an applicationId that exists on both stores:
adb shell am start -a "android.intent.action.VIEW" -d "market://details?id=busu.blackscreenbatterysaver"
A simple way to open app in Huawei App Gallery store:
public void reviewApp(String packageName){
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("appmarket://details?id=" + packageName));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} catch (ActivityNotFoundException anfe) {
Toast.makeText(this, "Huawei AppGallery not found!", Toast.LENGTH_SHORT).show();
}
}
then call it from your activity:
reviewApp(this.getPackageName());
or:
reviewApp("com.myapp.android");
You can use the badge service provided by HUAWEI AppGallery to promote your app, including preparing materials for making a badge, configuring an app link, and obtaining referrer statistics. With the service, you can efficiently collect statistics on app downloads in AppGallery and provide the silent installation service for users to improve the promotion effect.
When a user taps your badge in a channel, the user is redirected to your app details page on AppGallery. The user can tap Install to automatically download and install your app.
Making a badge
Sign in to AppGallery Connect and click In-app distribution.
Click the Make badge tab.
Click Add and add an app either by searching by keyword or app ID. (You can only make a badge for a released app.)
Set Badge type, Display badge in, Channel name, and Referrer. The referrer is optional. If attribution statistics is required, you need to set the parameter.
Click Generate badge to obtain the badge and its link.
Check the screenshot below:
Launch Play Store/AppGallery via package name.
private boolean openInStore(String uri){
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(Intent.createChooser(intent,getString(R.string.open_with)));
return true;
} catch (ActivityNotFoundException anfe) {
return false;
}
}
private void startOpenInStore() {
String playStoreScheme = "market://details?id=", huaweiScheme = "appmarket://details?id=";
if (!openInStore(playStoreScheme+getPackageName())) {
if (!openInStore(huaweiScheme + getPackageName())) {
openInStore("https://play.google.com/store/apps/details?id=" + getPackageName());
}
}
}
As for how to link to an app detail page or an app list page on AppGallery:
• The link that you referred: here is to an app detail page. Huawei does support the app detail page using badge service on AppGallery. In other words, you can replace the Google link with Huawei badge link. You can get the detail information of badge service at here
• For app listing on AppGallery, Huawei has not opened the ability to all developers except some invited developers.
Hope this help and let me know if any questions.
Here is how to start App Gallery directly:
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri.Builder uriBuilder = Uri.parse("https://appgallery.cloud.huawei.com/ag").buildUpon();
intent.setData(uriBuilder.build());
intent.setPackage("com.huawei.appmarket");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
I think the shortest and easiest one would be running this simple link: https://appgallery.cloud.huawei.com/ag/n/app/<YOUR_APP_ID>.
No need to config anything and the rest will handled by Huawei automatically.
How to get YOUR_APP_ID?
Go to Huawei App Gallery
Search for your app (e.g. WeChat)
Copy the ID in the end of the link (e.g. https://appgallery.huawei.com/#/app/C5683)
In this case the APP_ID for WeChat would be C5683
So the Huawei app link for WeChat would be https://appgallery.cloud.huawei.com/ag/n/app/C5683
Ok bro. You can use the package name. com.huawei.appmarket and use Intent. There is a similar question here. Launch an application from another application on Android
Good luck for whatever you doing 😊

URL link Cardboard and youtube Android

I am trying to open a 360video from unity without using a “VideoTexture”, which means to use a URL and then, select the “cardboard experience”.
My question is if it is a way of launching directly the youtube application with the link of the youtube video (360) from Android, which will display the video in full screen using the gyroscope data.
Please write to michael.soler.beatty#gmail.com if needed
The video is
https://www.youtube.com/watch?v=EhueMB9EzoE
Thanks
This android code must be work:
public static void watchYoutubeVideo(String id){
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:" + id));
startActivity(intent);
} catch (ActivityNotFoundException ex) {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.youtube.com/watch?v=" + id));
startActivity(intent);
}
}
You can write an android unity plugin or use android jni inside Unity.

Send package name to any market

i know there are some topics with this title. but all of them only works with GooglePlay.
i want to let users choose their favorite market. send package name to market and get results.
i also tested this:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=com.android.example"));
startActivity(intent);
but this is not supported by some markets.
You need a separate intent for Amazon Appstore and Google Play:
This bit of code figures out which store it was installed from, then tries Google Play and Amazon Appstore. If the intents fail, it falls back to the right web page
String installer = getPackageManager().getInstallerPackageName(getPackageName());
if ("com.amazon.venezia".equals(installer)) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse("amzn://apps/android?p=com.monadpad...."));
startActivity(intent);
}
catch (Exception e) {
Intent browser = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.amazon.com..."));
startActivity(browser);
}
}
else if ("com.android.vending".equals(installer)) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse("market://details?id=com.monadpad..."));
startActivity(intent);
}
catch (Exception e) {
Intent browser = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://play.google.com/store/apps/details?id=com.monadpad...."));
startActivity(browser);
}
}

how to implement Rate Us in android

I have made an application now i want to implement Rate Us feature in it. so for that i have added this code in my app
i = new Intent(Intent.ACTION_VIEW , Uri.parse("market://details?id=com.bet.compny"));
startActivity(i);
break;
but when i click on the button for rate us getting force close. here is my log cat output.
android.content.ActivityNotFoundException: No Activity found to handle Intent {
act=android.intent.action.VIEW dat=market://details?id=com.bet.compny }
Any help would be appretiated.
Idk why you get the Error, but this should actually work. I also do it like this:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + APP_PNAME)));
But keep in mind that this would crash, if you are testing it on an Emulator/ a device without a play store. So I would suggest you to wrap it in a try and catch
This error occurs when running on a device without the Google PlayStore.
I guess you might be running this on a emulator device which doesn't have Playstore and hence the error.
Implement using try catch as follows:
try{
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+getPackageName())));
}
catch (ActivityNotFoundException e){
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id="+getPackageName())));
}
I am always using below code which is useful for us:
Intent rateIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + context.getPackageName()));
startActivity(rateIntent);
In think it will help full for you.
This is the best way to do it;
Appirater is an android library based off the original Appirater By
Arash Payan Appirater iPhone. The goal is to create a cleanly designed
App Rating prompt that you can drop into any android app that will
help remind your users to review your app on the android Market.
https://github.com/sbstrm/appirater-android
try {
Uri marketUri = Uri.parse("market://details?id=" + getPackageName());
Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri);
startActivity(marketIntent);
}catch(ActivityNotFoundException e) {
Uri marketUri = Uri.parse("https://play.google.com/store/apps/details?id=" + getPackageName());
Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri);
startActivity(marketIntent);
}
Best and Simple Code
private final String mStoreLink;
Without Activity need context/activity
this.mStoreLink = "market://details?id=" + activity.getPackageName();
Creat a method like this.
public void rateUsOnGooglePlay() {
final Uri marketUri = Uri.parse(mStoreLink);
try {
activity.startActivity(new Intent(Intent.ACTION_VIEW, marketUri));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(activity, "Couldn't find PlayStore on this device", Toast.LENGTH_SHORT).show();
}
}
This commonly happens on a device without the Google Play Store
i think u have test this code in emulator, and emulator have no plastore application, so this error came.
I have implement this and my code is like this.
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=applicationID of play sotre")));
please put try catch in bellow code.
and try this code in android device.
Uri marketUri = Uri.parse("market://details?id=" + packageName);
Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri);
startActivity(marketIntent);
in my case, I wanted the user to click on "MORE BY US" and he would be redirected
to my playstore homepage, but the app was crashing. The reason was simple. I added extra spaces and lines to the link something like below:
<string name = "more_app_link">
playstore.link...............
</string>
then I removed extra lines and spaces like this:
<string name = "more_app_link">playstore.link...............</string>
and it worked very well.

Open a facebook page from android app?

How can I start an intent to open a Facebook application on a phone and navigate to the prefered page in Facebook?
I tried:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.facebook.katana", "com.facebook.katana.ProfileTabHostActivity");
intent.putExtra("extra_user_id", "123456789l");
this.startActivity(intent);
Well, whatever I write to "1234567891", it is always navigating to my page. Always to me and not else.
How could I do this?
Here is the best and simple way to do it.
Just follow the code
public final void Facebook() {
final String urlFb = "fb://page/"+yourpageid;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(urlFb));
// If Facebook application is installed, use that else launch a browser
final PackageManager packageManager = getPackageManager();
List<ResolveInfo> list =
packageManager.queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
if (list.size() == 0) {
final String urlBrowser = "https://www.facebook.com/pages/"+pageid;
intent.setData(Uri.parse(urlBrowser));
}
startActivity(intent);
}
I had the exactly same problem, sent the user id but for some reason, my profile always opened instead of the friend's profile.
The problem is that if you pass the String of the Long object that represents the Facebook UID, or even a long primitive type, the intent won't be able to read it later. You need to pass a real Long.
So the complete code is:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.facebook.katana", "com.facebook.katana.ProfileTabHostActivity");
Long uid = new Long("123456789");
intent.putExtra("extra_user_id", uid);
startActivity(intent);
Ok enjoy and hope this helps :-)
Maxim
try this code :
String facebookUrl = "https://www.facebook.com/<id_here>";
try {
int versionCode = getPackageManager().getPackageInfo("com.facebook.katana", 0).versionCode;
if (versionCode >= 3002850) {
Uri uri = Uri.parse("fb://facewebmodal/f?href=" + facebookUrl);
startActivity(new Intent(Intent.ACTION_VIEW, uri));
} else {
Uri uri = Uri.parse("fb://page/<id_here>");
startActivity(new Intent(Intent.ACTION_VIEW, uri));
}
} catch (PackageManager.NameNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(facebookUrl)));
}
This solution won't work any more. The new version of the facebook app doesn't support anymore those kind of intents. See here the bug report
The new solution is to use the iPhone scheme mechanism (Yes, facebook decided to support the iPhone mechanism in Android instead of the implicit intent mechanism of Android).
So in order to open the facebook app with a user profile all you need to do is:
String facebookScheme = "fb://profile/" + facebookId;
Intent facebookIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(facebookScheme));
startActivity(facebookIntent);
If you are looking for other actions you can use the following page for all available actions (/you have to test it though, since I didn't find an official publication of facebook about this)

Categories

Resources