How to know app's URL before publishing it? [duplicate] - java

This question already has answers here:
How to open the Google Play Store directly from my Android application?
(26 answers)
Closed 3 years ago.
I've recently started creating an app for Android.
I want to add "Rate us" button that sends to the app in Google play store.
How to get the URL, and what is the code to do that ?

You can get playstore URL using package name of APP,
Uri uri = Uri.parse("market://details?id=" + context.getPackageName());
or
Uri uri = Uri.parse("http://play.google.com/store/apps/details?id=" + context.getPackageName())
you can use this way:
Uri uri = Uri.parse("market://details?id=" + context.getPackageName());
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://play.google.com/store/apps/details?id=" + context.getPackageName())));
}
Hope it will help!!

First of all, you should upload your App to the Google Play Store. Then, you should go to the profile of your app in store and choose "Copy URL", your url-adress may looks like:
https://play.google.com/store/apps/details?id=<app_name>
To get the URL in App and use it, you should create method with next code-line:
Uri appUrl = Uri.parse("http://play.google.com/store/apps/details?id=" + context.getPackageName() + "")
Final result of code to do that here:
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://play.google.com/store/apps/details?id=" +getPackageName())));
Main topic: https://developer.android.com/distribute/marketing-tools/linking-to-google-play

Related

Android - Java - Intent to send facebook chat message (facebook disabled xmpp)

***Facebook deprecated xmpp api.
Is there a way to open an intent (or pass data to fb) to send chat message on android device?
Facebook & Messenger apps installed on the device.
Thanks :-)
You need to pass uri to the intent
Here 100005727832736 is the user id of the person who you want to
message to
Uri uri = Uri.parse("fb-messenger://user/100005727832736");
Here is my sample code
Uri uri = Uri.parse("fb-messenger://user/100005727832736");
Intent toMessenger= new Intent(Intent.ACTION_VIEW, uri);
try {
startActivity(toMessenger);
}
catch (android.content.ActivityNotFoundException ex)
{
Toast.makeText(context, "Please Install Facebook Messenger", Toast.LENGTH_LONG).show();
}
}
This is what worked for me and i haven not tested this for some time now.
To launch facebook app let urlString = "fb://page/your_fb_page_id"
To launch facebook messenger let urlString = "fb-messenger://user/your_fb_page_id"
FB page id is usually numeric. To get it, goto Find My FB ID input your profile url, something like www.facebook.com/edgedevstudio then click "Find Numberic ID".
Voila, you now have your fb numeric id. replace "your_fb_page_id" with the generated Numeric ID
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(urlString))
if (intent.resolveActivity(packageManager) != null) //check if app is available to handle the implicit intent
startActivity(intent)

How to send app invites from my application (via whatsapp,hike,message)

I am new for Android. I created a simple food app. I want to send invitation to my friends from my app via Whatsapp, message etc. while clicking the invite button. I don't have any idea about that. Can you anyone guide me (Show some examples means more helpful to me).
Thanks in advance!
Refer this link
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);
private void onShareClicked() {
String link = "https://play.google.com/store/apps/details?id=com.recharge2mePlay.recharge2me";
Uri uri = Uri.parse(link);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, link.toString());
intent.putExtra(Intent.EXTRA_TITLE, "Recharge2me");
startActivity(Intent.createChooser(intent, "Share Link"));
}
And simply call this function in onClickListner.
btn_tellAFreind.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
onShareClicked();
}
});
try this tutorial from google using Firebase, maybe this can help you:
https://codelabs.developers.google.com/codelabs/firebase-android/#10
You can generate short link by using the following codes:
DynamicLink dynamicLink = FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse("https://play.google.com/store/apps/details?id=com.example"))
.setDynamicLinkDomain("abc.app.goo.gl")
.setAndroidParameters(new DynamicLink.AndroidParameters.Builder().build())
.buildDynamicLink();
Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLongLink(dynamicLink.getUri())
.buildShortDynamicLink()
.addOnCompleteListener(ReferrerActivity.this, new OnCompleteListener<ShortDynamicLink>() {
#Override
public void onComplete(#NonNull Task<ShortDynamicLink> task) {
if (task.isSuccessful()) {
Uri shortLink = task.getResult().getShortLink();
Uri flowchartLink = task.getResult().getPreviewLink();
Log.i(TAG, "onComplete: SHORTLINK " + shortLink.toString());
Log.i(TAG, "onComplete: FLOW LINK " + flowchartLink.toString());
} else {
Log.i(TAG, "onComplete: ERROR " + task.isSuccessful() + " " + task.isComplete());
}
}
});
Once you received the short link in onComplete method, share it using intent.
Firebase Invites are an out-of-the-box solution for app referrals and sharing via email or SMS.
Connect your app to your Firebase project from Firebase console
Enabled Firebase Dynamic Links from the Firebase console by opening the Dynamic Links section and accepting the terms of service if prompted.
Add Firebase to your Android project
Add the dependency for Firebase Invites to your app-level build.gradle file:
compile 'com.google.firebase:firebase-invites:10.0.1'
Send invitations:
Start by building an Intent using the AppInviteInvitation.IntentBuilder class:
Intent intent = new AppInviteInvitation.IntentBuilder(getString(R.string.invitation_title))
.setMessage(getString(R.string.invitation_message))
.setDeepLink(Uri.parse(getString(R.string.invitation_deep_link)))
.setCustomImage(Uri.parse(getString(R.string.invitation_custom_image)))
.setCallToActionText(getString(R.string.invitation_cta))
.build();
startActivityForResult(intent, REQUEST_INVITE);
Launching the AppInviteInvitation intent opens the contact chooser where the user selects the contacts to invite. Invites are sent via email or SMS. After the user chooses contacts and sends the invite, your app receives a callback to onActivityResult:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "onActivityResult: requestCode=" + requestCode + ", resultCode=" + resultCode);
if (requestCode == REQUEST_INVITE) {
if (resultCode == RESULT_OK) {
// Get the invitation IDs of all sent messages
String[] ids = AppInviteInvitation.getInvitationIds(resultCode, data);
for (String id : ids) {
Log.d(TAG, "onActivityResult: sent invitation " + id);
}
} else {
// Sending failed or it was canceled, show failure message to the user
// ...
}
}
}
Check out here for more details about Send and Receive Firebase Invites from Your Android App
Update:
Use Branch sdk to support invite feature on another platform like WhatsApp, Facebook and other social media apps.
Check out here to know How branch link works?
Checkout here for Install guide & code example
If I understand the question correctly, you want to make the share differentiate when the user clicks share and if he selects to invite via WhatsApp, for example, it will show only Whatsapp as a medium option to share the invite through.
If that is what you want, you should to set the package in the intent you will use for sharing, so if we add to #Vishal answer above
sendIntent.setPackage("com.whatsapp");
You should do the same for any needed social media
You need to add Firebase Dynamic link. Earlier it was Firebase Invites but it is depreciated now. Firebase Dymanic Link is build over Firebase Invites So you can see the invites dependency on gradle file.
You can follow this tutorial for complete example about "How to Create Refer a friend Link"
There is Two ways to create "Refer a Friend Link"
Using Firebase base Dynamic Object
Manually Create Refer a Link
1) Option :-
DynamicLink dynamicLink = FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse("https://www.example.com/"))
//.setDomainUriPrefix("https://example.page.link") // no longer in user please
.setDynamicLinkDomain("example.page.link") // use this code and don't use https:// here
// Open links with this app on Android
.setAndroidParameters(new DynamicLink.AndroidParameters.Builder().build())
// Open links with com.example.ios on iOS
.setIosParameters(new DynamicLink.IosParameters.Builder("com.example.ios").build())
.buildDynamicLink();
Uri dynamicLinkUri = dynamicLink.getUri();
2) Option:-
String sharelinktext = "https://referearnpro.page.link/?"+
"link=https://www.blueappsoftware.com/"+
"&apn="+ getPackageName()+
"&st="+"My Refer Link"+
"&sd="+"Reward Coins 20"+
"&si="+"https://www.blueappsoftware.com/logo-1.png";
Then Call ShortDynamicLink Object
Refer Link will be look like this :
https://referearnpro.page.link?apn=blueappsoftware.referearnpro&link=https%3A%2F%2Fwww.blueappsoftware.com%2F
You can check complete example here
a custom method to send invites, also according to the best practice in Android Developers
fun inviteToDownloadApp(context: Context) {
val intent = Intent(Intent.ACTION_SEND)
intent.type = "text/plain"
intent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.app_name))
intent.putExtra(Intent.EXTRA_TEXT, context.getString(R.string.invite_to_download_app))
context.startActivity(Intent.createChooser(intent, context.getString(R.string.invite_to_download_app)))
}

Weird URI behavior java/setDataSource/MediaPlayer

I am using a URI that i pass to a MediaPlayer on android like this:
mediaPlayer.setDataSource(context, Uri.parse(<uri>));
When I get it using Intent.createChooser, it plays once then trying to make it play it again result in java.io.IOException: setDataSource failed.: status=0x80000000.
When i pass the URI as a string directly, it results in java.io.IOException: setDataSource failed.: status=0x80000000, despite the URI outputed by the selector being always the same.
The uri look like this: "content://com.android.providers.media.documents/document/audio%3A21739".
Can someone please enlighten on why does this happen?
Turns out android required some weird permissions shenanigans, the solutions was using a different opening coupled with using some sort of permission requirement that somehow output the same uri, but with a persistent access:
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(Intent.createChooser(intent, "Select file to add"), ADD_2);
In onActivityResult:
if (resultCode == RESULT_OK) {
Uri uri = data.getData();
final int takeFlags = data.getFlags() & Intent.FLAG_GRANT_READ_URI_PERMISSION;
getContentResolver().takePersistableUriPermission(uri, takeFlags);
Log.d(TAG, "Added track uri: " + uri);
playlist.add(uri.toString());
adapter.notifyDataSetChanged();
}

Android how to open Deezer from URI

I want to open the Deezer Android Application from URI using Android Intent.
My code is:
try {
uri = "deezer://track/"+track_id;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
activity.startActivity(intent);
} catch (Exception e) {
uri = "http://www.deezer.com/track/"+track_id;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
activity.startActivity(intent);
}
However, the URI "deezer://track/track_id is never detected by Deezer and doesn't work.
Anybody knows the correct URI syntax for that ?
(I use the same code for Spotify and it works with the URI: spotify:track:track_id)
If you really want to use the deezer:// scheme, you can use the following uri :
uri = "deezer://www.deezer.com/track/"+track_id;
Edit :
You can also use some query parameters to add behavior to your link, for instance the following uri : deezer://www.deezer.com/album/10596327?autoplay=true&start_index=13 will open the deezer app on the album's page immediately and will start playing with the 14th track (0 based index).

How to start a Skype call from an Android app?

I'm trying to start a Skype intent from my Android App, passing a phone number. So far, thanks to other people who ad similiar needs here on stackoverflow, I've managed to start skype, but still I can't pass the phone number. This is the code I'm using:
Intent sky = new Intent("android.intent.action.CALL_PRIVILEGED");
sky.setClassName("com.skype.raider",
"com.skype.raider.Main");
sky.setData(Uri.parse("tel:" + number));
Log.d("UTILS", "tel:" + number);
ctx.startActivity(sky);
What's happening is that skype starts, but gives me a toast saying that the number is not valid, and suggests me to add the international prefix.
The Log.d gives me tel:+39........ (the number works, I'm using it also for
public static void call(String number, Context ctx) {
try {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + number));
ctx.startActivity(callIntent);
} catch (ActivityNotFoundException e) {
Log.e("helloandroid dialing example", "Call failed", e);
}
}
In fact, when I go to the Skype's view for calling, I see it's been composed +0
So what it seems to me is that I'm passing the phone number in the wrong way, or to the wrong Activity....any help would be very appreciated!
In the meantime, I just want to say that StackOverflow simply rocks.
See this answer: https://stackoverflow.com/a/8844526/819355
Jeff suggests using a skype:<user name> instead of tel:<phone number>
After some studing of the skype apk with apktool, as suggested in that answer, I came up with this code, for me it's working:
public static void skype(String number, Context ctx) {
try {
//Intent sky = new Intent("android.intent.action.CALL_PRIVILEGED");
//the above line tries to create an intent for which the skype app doesn't supply public api
Intent sky = new Intent("android.intent.action.VIEW");
sky.setData(Uri.parse("skype:" + number));
Log.d("UTILS", "tel:" + number);
ctx.startActivity(sky);
} catch (ActivityNotFoundException e) {
Log.e("SKYPE CALL", "Skype failed", e);
}
}
Refer to Skype developer: Skype URI tutorial: Android apps
Also remember to add "?call" in your url. E.g
intent.setData(Uri.parse("skype:" + phoneNumber + "?call"));
Without it, Skype may not dial the number.
You should not include a specific class when calling an external app. Let the user decide of the application he/she wants to use. That's the way android has been designed and it's a better solution than obliging people to use a soft (moreover quite a slow, closed and inconvenient app to my mind).
In other words, just use the Uri, that's the job of skype of declaring its ability to capture such intents.
Refer this skype doc link Skype URI tutorial: Android apps
First need to check skype is installed or not using
/**
* Determine whether the Skype for Android client is installed on this device.
*/
public boolean isSkypeClientInstalled(Context myContext) {
PackageManager myPackageMgr = myContext.getPackageManager();
try {
myPackageMgr.getPackageInfo("com.skype.raider", PackageManager.GET_ACTIVITIES);
}
catch (PackageManager.NameNotFoundException e) {
return (false);
}
return (true);
}
initiate skype uri using
/**
* Initiate the actions encoded in the specified URI.
*/
public void initiateSkypeUri(Context myContext, String mySkypeUri) {
// Make sure the Skype for Android client is installed.
if (!isSkypeClientInstalled(myContext)) {
goToMarket(myContext);
return;
}
// Create the Intent from our Skype URI.
Uri skypeUri = Uri.parse(mySkypeUri);
Intent myIntent = new Intent(Intent.ACTION_VIEW, skypeUri);
// Restrict the Intent to being handled by the Skype for Android client only.
myIntent.setComponent(new ComponentName("com.skype.raider", "com.skype.raider.Main"));
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Initiate the Intent. It should never fail because you've already established the
// presence of its handler (although there is an extremely minute window where that
// handler can go away).
myContext.startActivity(myIntent);
return;
}
if Skype is not installed then redirect to market place using
/**
* Install the Skype client through the market: URI scheme.
*/
public void goToMarket(Context myContext) {
Uri marketUri = Uri.parse("market://details?id=com.skype.raider");
Intent myIntent = new Intent(Intent.ACTION_VIEW, marketUri);
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
myContext.startActivity(myIntent);
return;
}

Categories