how to remove notification fired after application data is cleared from mobile - java

I am new to android i would like to know how to disable receiving notification after application is uninstalled, whether any event or something to detect that app is uninstalled ???
i have tried this but not working for me
if(intent.getAction().equals("android.intent.action.PACKAGE_REMOVED")) {
Intent i = new Intent(context,BootReceiver.class);
Identifier = i.getStringExtra("Recognition_flag");
serverUrl = Constants.urlAll + "uninstall.php";
LongOperation serverRequest = new LongOperation();
// serverRequest.execute(serverUrl, user, pass,
// deviceIMEI);
serverRequest.execute(serverUrl, user);
GCMRegistrar.setRegisteredOnServer(context, true);
Log.e(" BroadcastReceiver ", "onReceive called " + " PACKAGE_REMOVED ");
Toast.makeText(context, " onReceive !!!! PACKAGE_REMOVED", Toast.LENGTH_LONG).show();
}
// when package installed
else if (intent.getAction().equals("android.intent.action.PACKAGE_ADDED")) {
Log.e(" BroadcastReceiver ", "onReceive called " + "PACKAGE_ADDED");
Toast.makeText(context, " onReceive !!!!." + "PACKAGE_ADDED", Toast.LENGTH_LONG).show();
}

You cannot detect app uninstalls on Android in any easy way. The broadcast
android.intent.action.PACKAGE_REMOVED is sent to all the app present in the mobile but yours once the app is removed.
Sure there are ways my company has tracked when the app is uninstalled but thats something very tricky and deep.

Related

Spotify's Android SDK returns a Type.EMPTY Authentication Response only when the Spotify App is installed

Below is the code I am running:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent resultIntent) {
super.onActivityResult(requestCode, resultCode, resultIntent);
Log.e("Spotify Auth", "Running login activity pt 2. result code: " + resultCode + " Request Code: " + requestCode);
if(requestCode == 200){
AuthenticationResponse response = AuthenticationClient.getResponse(resultCode, resultIntent);
//log and store for later use
if(response.getType() == AuthenticationResponse.Type.TOKEN) {
Log.e("Access Token Received", response.getAccessToken());
getSharedPreferences("appPrefs", getApplicationContext().MODE_PRIVATE)
.edit().putString("spotify_token", response.getAccessToken()).apply();
} else if(response.getType() == AuthenticationResponse.Type.ERROR)
Log.e("Spotify Access Token", "Code: " + response.getCode() + " Token failure: " + response.getError());
else
Log.e("Spotify Access Token", response.getType().name() + " " + response.getError() + " Token: " + response.getAccessToken());
} else {
Log.e("Spotify Access Token", "Token failure: " + resultCode + " " + requestCode);
}
}
public void getSpotifyAuth() {
//spotify token setup
AuthenticationRequest.Builder builder =
new AuthenticationRequest.Builder(
getString(R.string.spotify_keys).split(":")[0],
AuthenticationResponse.Type.TOKEN,
"com.lattestudios.musicpal://auth");
builder.setShowDialog(true);
AuthenticationRequest request = builder.build();
AuthenticationClient.openLoginActivity(this, 200, request);
}
Everything works fine when the spotify app is not installed. It gives a popup asking for login, then the user clicks agree and the SDK returns a token. When the spotify application is installed, however, a very quick loading screen pops up instead of the login screen because it is trying to get the token from the app. When this goes away, the response given in the onActivityResult function is of type EMPTY. The request code is correct, the result code is -1, and the error message and access token is null.
If you would like to see the rest of my code you can find it here on my GitHub. Thank you!
I had the same issue and found that it was caused by attempting to use SSL proxying with Charles Proxy across all *.spotify.com domains. After I changed that to api.spotify.com the login started working.
I had the same issue, I messed up the strings according to this GitHub documentation https://github.com/spotify/android-auth
<resources>
<string name="com_spotify_sdk_redirect_scheme">yourscheme</string>
<string name="com_spotify_sdk_redirect_host">yourhost</string>
</resources>
Make sure to put the scheme and host properly
e.g if the redirect url is playlists/callback, then set com_spotify_sdk_redirect_scheme to playlists and com_spotify_sdk_redirect_host to callback
Or also you can create the redirect host using these two strings
private fun getRedirectUri(): Uri {
return Uri.Builder()
.scheme(getString(R.string.com_spotify_sdk_redirect_scheme))
.authority(getString(R.string.com_spotify_sdk_redirect_host))
.build()
}
Also make sure that the redirect URI on Spotify dashboard matches these two and the one in the Manifest.

How to know if app/game was launched via notification on Android?

I'm making a game in Unity for Android. I have implemented a notification system. Notifications show and clicking on them opens the game. The thing I'm stuck on is how to know if the game/app is launched by tapping the notification?
Here is the java code for the notification plugin I'm using https://github.com/GoShikhar/unity-android-notifications/blob/master/PluginSrc/app/src/main/java/net/agasper/unitynotification/UnityNotificationManager.java
This is my manifest https://github.com/GoShikhar/unity-android-notifications/blob/master/UnityProject/Assets/Plugins/Android/AndroidManifest.xml
In my unity start scene I use this to check for intent messages.
void Start(){
AndroidJavaClass unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
var activityObject = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject intent = activityObject.Call<AndroidJavaObject>("getIntent");
int NotificationID = intent.Call<int>("getIntExtra", "id", -1);
print("NOTIFDICATION ID " + NotificationID);
bool hasExtra = intent.Call<bool>("hasExtra", "arguments");
string arguments = null;
if (hasExtra)
{
AndroidJavaObject extras = intent.Call<AndroidJavaObject>("getExtras");
arguments = extras.Call<string>("getString", "title");
print("title : " + arguments);
arguments = extras.Call<string>("getString", "message");
print("message: " + arguments);
}
if (arguments != null)
{
print("App opened via notification");
}
}
This not working. The default notification ID is being printed i.e. -1. Also title and message are null. Even though the notification has the title and message parameter.
I have seen lots of examples for Android Studio but not for Unity. So any help will be appreciated.
Thanks in advance.
Do you mean deep linking? Perhaps this Github project would be helpful: https://github.com/TROPHiT/UnityDeeplinks.

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)))
}

Block sent SMS from being logged in default messaging app

I have an auto reply sms Android application I built and I don't want the auto reply (sent sms) to show in the default messaging app. I have searched and searched and couldn't find an answer. Is there a way to bypass writing the sent sms into the default messaging app?
Here my BroadcastReciever I am using to get the data and send out the message
public class SmsReceiver extends BroadcastReceiver {
ParseUser user = ParseUser.getCurrentUser();
// Auto reply message composed of the current reply and url from that business
String msg = user.getString("myCurrentReply") + " " + user.getString("couponUrlChosen");
List smsFromList = user.getList("smsFrom");
String userName = (String) user.get("username");
#Override
public void onReceive(final Context context, Intent intent) {
Bundle bundle = intent.getExtras();
Object messages[] = (Object[]) bundle.get("pdus");
SmsMessage smsMessage[] = new SmsMessage[messages.length];
for (int n = 0; n < messages.length; n++) {
smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
}
final String pno = smsMessage[0].getOriginatingAddress();
user.put("lastSmsFrom", pno);
user.saveInBackground();
// show first message
Toast toast = Toast.makeText(context, "Received SMS: " + smsMessage[0].getMessageBody(), Toast.LENGTH_LONG);
toast.show();
// Check Phone Number from SMS Received against Array in User Row
ParseQuery<ParseObject> query = ParseQuery.getQuery("_User");
Log.d("Username: ", userName);
query.whereEqualTo("username", userName);
query.whereContainedIn("lastSmsFrom", smsFromList);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> smsList, ParseException e) {
if (e == null) {
Log.d("Errors", "none");
if (smsList.size() == 0) {
// Send SMS
sendSms(pno, msg);
// Add Phone number to smsFrom in currentUsers Row
user.addUnique("smsFrom", pno);
// Save Phone Number in Array
user.saveInBackground();
Log.d("List size: ", " " + smsList.size());
}
} else {
Log.d("Error Message: ",
e.getMessage());
}
Log.d("Already sent to this number today. ", " " + smsList.size());
}
});
}
private void sendSms(String phonenumber, String message) {
SmsManager manager = SmsManager.getDefault();
manager.sendTextMessage(phonenumber, null, message, null, null);
}
}
Prior to KitKat, SMS sent using SmsManager require the app sending the message to insert it into the Provider, so it would just be a matter of omitting that.
Starting with KitKat, any app that is not the default SMS app and uses SmsManager to send messages will have the messages automatically written to the Provider for it by the system. There's no way to prevent this, and, furthermore, the app won't be able to delete those messages, either, as it won't have write access to the Provider.*
The app that is the default SMS app is responsible for writing its outgoing messages, so it would be able to omit that step. The system does no automatic writes for the default SMS app.
* There is a security hole in 4.4 only, by which a non-default app can gain write access to the Provider. It is detailed in my answer here, but it will not work in versions after KitKat.

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