Uninstall App from device - android

I want to remove app from device, as i perform uninstall , app must removed from the ArrayList and update the app drawer like wise.
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_PACKAGE_ADDED);
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
filter.addDataScheme("package");
registerReceiver(new RefreshApps(), filter);
}
public class RefreshApps extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Toast.makeText(context, "App Installed/Removed" ,Toast.LENGTH_SHORT).show();
}
}

You can find out that an app is being removed via a BroadcastReceiver listening for ACTION_PACKAGE_REMOVED. You can find out one has been installed by listening for ACTION_PACKAGE_ADDED. Obviously these work for anything except your own app.

Related

Android close application on stand by

How can I close my application when the Android goes to stand by either by user pressing the button or screen timeout?
I've tried onResume(), onPause and onRestart() methods but I already use then in another context.
Regards
In your application class onCreate() method register receiver for Screen Off Event
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
registerReceiver(new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
Log.d(TAG, Intent.ACTION_SCREEN_OFF);
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
Log.d(TAG, Intent.ACTION_SCREEN_ON);
}
}
}, intentFilter);
like this.

Unable to catch SMS received with android.provider.Telephony.SMS_RECEIVED

I am not able to catch the intent when a SMS is received. Below is my code of the service. I am able to catch the "Intent.ACTION_SCREEN_ON" and "Intent.ACTION_SCREEN_OFF" but I am NOT able to catch the SMS_RECEIVED intent "android.provider.Telephony.SMS_RECEIVED".
Sincerely appreciate any hints on what I am doing wrong here?
public class SmsCatcher extends Service{
BroadcastReceiver myBroadcast = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
Log.i("myBroadcast SmsCatcher", "Entered onReceive method");
if(intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
Log.i("myBroadcast SmsCatcher", "Caught SCREEN_OFF");
}
if(intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
Log.i("myBroadcast SmsCatcher", "Caught SCREEN_ON");
}
if(intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
Log.i("myBroadcast SmsCatcher", "SMS_RECEIVED");
}
}
};
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public void onCreate() {
super.onCreate();
Log.i("neil SmsCatcher", "Entered onCreate() in 'SmsCatcher extends Service'");
Toast.makeText(this, "Entered onCreate() in 'SmsCatcher extends Service'", Toast.LENGTH_LONG).show();
registerReceiver(myBroadcast, new IntentFilter(Intent.ACTION_SCREEN_ON));
registerReceiver(myBroadcast, new IntentFilter(Intent.ACTION_SCREEN_OFF));
}
#Override
public void onDestroy() {
super.onDestroy();
Log.i("neil SmsCatcher", "Entered onDestroy() in 'SmsCatcher extends Service'");
Toast.makeText(this, "Entered onDestroy() in 'SmsCatcher extends Service'", Toast.LENGTH_LONG).show();
}
}
UPDATE 1: Adding some more information from my ongoing debug:
I used the App Internal Broadcasts Monitor to see there is a broadcast when there is a text message received and I dont see anything, very strange. What could be the reason?
I have other SMS apps installed (Hangout, AT&T Messages) - these cant suppress the broadcast can they?
UPDATE 2: FOUND PROBLEM BUT DONT KNOW HOW TO SOLVE
I uninstalled the Google Hangouts (replaces Talk) app and it WORKS!!!
Any solution around this? (should i be opening a separate thread as per stackoverflow rules?)
UPDATE 3: FOUND ROOTCAUSE (with help below of course, thank you)
It turns out that because of the new Google Hangouts App, I needed to setPriority(int). I found the solution at Enabling SMS support in Hangouts 2.0 breaks the BroadcastReceiver of SMS_RECEIVED in my app
You need to register the android.provider.Telephony.SMS_RECEIVED intent filter,only if you have registered it you can able to check the intent in the onRecive like
IntentFilter filter = new IntentFilter(android.provider.Telephony.SMS_RECEIVED);
this.registerReceiver(myBroadcastReceiver, filter);
Update From the question:
It turns out Google Hangouts App aborts the sms broadcast as soon as it receives it,So disabling SMS support in Hangouts 2.0 may fix the issue.
You did not register the intent-filter:
#Override
public void onCreate() {
// ..
registerReceiver(myBroadcast, new IntentFilter(Intent.ACTION_SCREEN_ON));
registerReceiver(myBroadcast, new IntentFilter(Intent.ACTION_SCREEN_OFF));
registerReceiver(myBroadcast, new IntentFilter("android.provider.Telephony.SMS_RECEIVED")); // missing in your code
}
And please check your permissions for android.permission.RECEIVE_SMS in AndroidManifest.xml.

Android How does PACKAGE_RESTARTED intent work?

I am new to Android development.
I want to get a notice when the operating system (because of lack of memory) or other application (Task killer e.g. ZDbox) restart other applicatoin (not mine).
I tried BroadcastReceiver. It did not get any Intent when an app was killed and the user started it manually. I have used PACKAGE_RESTARTED intent but BroadcastReceiver did not get any Intent.
Any suggestions?
public class MyService extends Service {
public void onCreate() {
super.onCreate();
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_PACKAGE_RESTARTED);
filter.addDataScheme("package");
BroadcastReceiver pkgRemoveReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
// do my stuff
}
};
registerReceiver(pkgRemoveReceiver, filter);
}

BroadcastReceiver in Service is not working after boot completed

I am using a Service to listen for a broadcast after boot completed. But the BroadcastReceiver is not registering when boot completed. If instead of a Service I use a BroadcastReceiver to listen for boot completed it works. It doesn't when I register it with a Service. What am I doing wrong? Code is given below.
private BroadcastReceiver sim_change;
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
IntentFilter filter = new IntentFilter();
filter.addAction(action);
sim_change = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Boradcast Receiver registered successfully", Toast.LENGTH_LONG).show();
}
};
registerReceiver(sim_change, filter);
}#Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
unregisterReceiver(sim_change);
Toast.makeText(getApplicationContext(), "Boradcast Receiver unregistered successfully", Toast.LENGTH_LONG).show();
}
You have to register for BOOT_COMPLETED in your Manifest. It doesn't make sense to register for it from a Service, because the Service won't be running at boot in order to register for it.
You can't register for BOOT_COMPLETED from within a Service because the reboot removes that registration.
You must do it from your BroadcastReceiver.
There are many ways to handle the enable/disable feature - either using the suggested setComponentEnabledSetting(), or just by storing a value in the app's shared preferences, which you can check when your service starts.

POWER connected and disconnected listeners

I am listening to both connecting and disonnecting the power for my galaxy.
I have creatd 2 BroadCastReceivers, one for connect, and one for disconnect.
When I try to implement, I only get the connected data, even when disconnecting the power cable.
The intent is sent, but looks like it's the wrong one.
Here is the activity code:
// Handle Power On
PowerConnectedBCReceiver myPowerConnectedBCReceiver = new PowerConnectedBCReceiver();
IntentFilter intentPowerOnFilter = new IntentFilter();
intentPowerOnFilter.addAction("android.intent.action.ACTION_POWER_CONNECTED");
registerReceiver(myPowerConnectedBCReceiver, intentPowerOnFilter);
BroadcastReceiver PowerConnectedReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
showToast("connected");
}
};
// Handle Power Off
PowerConnectedBCReceiver myPowerDisonnectedBCReceiver = new PowerConnectedBCReceiver();
IntentFilter intentPowerDisconnectedOnFilter = new IntentFilter();
intentPowerDisconnectedOnFilter.addAction("android.intent.action.ACTION_POWER_DISCONNECTED");
registerReceiver(myPowerDisonnectedBCReceiver, intentPowerDisconnectedOnFilter);
BroadcastReceiver PowerDisconnectedReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
showToast("disconnected");
}
};
Registering both BC to do the work
registerReceiver(PowerDisconnectedReceiver, new IntentFilter("com.neglected.POWER_DISCONNECTED"));
registerReceiver(PowerConnectedReceiver, new IntentFilter("com.neglected.POWER_CONNECTED"));
BroadCast connected code:
public class PowerConnectedBCReceiver extends BroadcastReceiver
{
#Override
public void onReceive(Context context, Intent intent)
{
Toast.makeText(context, "Phone was connected to power" , Toast.LENGTH_LONG).show();
Intent tIntent = new Intent("com.neglected.POWER_CONNECTED");
context.sendBroadcast(tIntent);
}
}
Broadcast disconnected code:
public class PowerDisconnectedBCReceiver extends BroadcastReceiver
{
#Override
public void onReceive(Context context, Intent intent)
{
Toast.makeText(context, "Phone was disconnected from power" , Toast.LENGTH_LONG).show();
Intent tIntent = new Intent("com.neglected.POWER_DISCONNECTED");
context.sendBroadcast(tIntent);
}
}
IS the code wrong?
Can I listen to both actions? seperately?
I can't see extra been sent with the CONNNECTED Action, is there?
Not sure what your last two classes (*BCReeivers) are supposed to be doing. Your first block of code looks ok. It will be limited to the lifecycle of the enclosing Activity if that matters.
For the Galaxy S, you may not be able to rely on those Intents. In particular, I have found that the Verizon Fascinate (their version of the Galaxy S) to be very buggy. See here: http://devblog.bu.mp/how-to-ddos-yourself
There was an error in my Broadcast instantiation. I mistakenly used the PowerConnectedBCReceiver instead of PowerDisconnectedBCReceiver
problem solved.

Categories

Resources