public class Unistallreceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
String action = intent.getAction();
if (action == null)
Log.e("uninstall ", "Action==null!");
else if ("android.intent.action.BOOT_COMPLETED".equals(action)) {
Log.e("uninstall ", "action :"+action);
}
}
}
Doing something like this, but can't get notification.Reference said :
public static final String ACTION_PACKAGE_REMOVED
Since: API Level 1
Broadcast Action: An existing application package has been removed from the device. The data contains the name of the package. The package that is being installed does not receive this Intent
A need this intent to set uninstall password.
Any suggestions??
Get rid of the "set uninstall password" requirement.
Related
I am trying to code APK to identify the received calls are in sim 1 or sim 2. I have tried below solutions but in all devices, it is not working. Samsung and MI devices the below solution is not working. can you please suggest universal solutions. thanks
I tried below solutions
URL1
URL2
public class IncomingCallInterceptor extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
String callingSIM = "";
Bundle bundle = intent.getExtras();
callingSIM =String.valueOf(bundle.getInt("simId", -1));
if(callingSIM == "0"){
// Incoming call from SIM1
}
else if(callingSIM =="1"){
// Incoming call from SIM2
}
}
}
I have a service application. I need to send a string to any application (browser, word, ...wherever the keyboard cursor focused). How can I do this?
//onReceive of my service onStartCommand...
#Override
public void onReceive(Context context, Intent intent) {
String textToSend = intent.getStringExtra("data");
if(textToSend!=null && textToSend.length()>0) {
//Here I need send "textToSend" to another application
}else{
Toast.makeText(context, "Error! ", Toast.LENGTH_SHORT).show();
}
}
You can achieve it with Intents. Passing the string value in the URL, specifically: http://developer.android.com/training/sharing/send.html.
You can check this question for more info.
I'm trying to develop a simple app, which receives text from other android Apps and then open a browser.
I have implemented it as described in the documentation here:
https://developer.android.com/training/sharing/receive.html
It works, but only once.
The first time a text is shared from an other App, the browser is opened correctly.
But the second time only my app is opened, but not the browser.
What could be the reason for this?
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get the intent that started this activity
Intent intent = getIntent();
// Get the action of the intent
String action = intent.getAction();
// Get the type of intent (Text or Image)
String type = intent.getType();
// When Intent's action is 'ACTION+SEND' and Type is not null
if (Intent.ACTION_SEND.equals(action) && type != null) {
// When tyoe is 'text/plain'
if ("text/plain".equals(type)) {
handleSendText(intent); // Handle text being sent
}
}
}
private void handleSendText(Intent intent) {
// Get the text from intent
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText != null) {
openBrowser(sharedText);
}
}
private void openBrowser(String text) {
Toast.makeText(this, text, Toast.LENGTH_LONG).show();
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://example.com/api.php?text=" + text));
startActivity(browserIntent);
}
}
openBrowser method is called from the handleSendText method witch it is on the onCreate method , second time you open your app ( If you didnt press the back button ) your app is already created ! so the code will never execute.
Please check the life cycle of an android activity below
You may edit your code and call the openBrowser method on the onResume method or just make a button to call the method openBrowser Oncliking the button.
I have the following Reciever and I get an app crash on device boot.
Since it happens on boot I cannot attach the debug via eclipse nor see anything in the logcat.
How would you suggest for me to see the error causing the crash?
public class BootReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context arg0, Intent intent) {
// TODO Auto-generated method stub
if (intent != null) {
String action = intent.getAction();
if (action != null) {
if (action.equalsIgnoreCase(Intent.ACTION_BOOT_COMPLETED)) {
// GeoPushService geoPs = new GeoPushService();
ZoomerLocationService locService = new ZoomerLocationService();
locService.startService(new Intent());
// Log.d("receiver","action is: boot");
}
}
}
}
}
I have tried adding this try-catch
public class BootReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context arg0, Intent intent) {
// TODO Auto-generated method stub
if (intent != null) {
String action = intent.getAction();
try {
if (action != null) {
if (action.equalsIgnoreCase(Intent.ACTION_BOOT_COMPLETED)) {
// GeoPushService geoPs = new GeoPushService();
ZoomerLocationService locService = new ZoomerLocationService();
locService.startService(new Intent());
// Log.d("receiver","action is: boot");
}
}
} catch (Exception ex) {
Log.e(MyLogger.TAG, ex.getStackTrace().toString());
}
}
}
}
but it didn't help
I have tried to send BOOT_COMPLETE intent and i got permissions denial
You might be able to use ADB in a command line to record the logcat when your device is booting up.
http://developer.android.com/tools/help/logcat.html
http://www.herongyang.com/Android/Debug-adb-logcat-Command-Option-Log-Buffer.html
Make sure to increase the amount of data the command window can display or else use the options to save the log to a file.
Using this method you might be able to see the crash in the log on startup.
EDIT: I have tried this and it is possible, this should work for you
I used a Broadcast Receiver for listening the current wifi state.
So it sets the current state to the text (connected, connecting, disabled,...) of a togglebutton (setText).
It works fine!
But now I want to do the same thing with the mobile data state..
So I used TelephonyManager to setup the receiver:
this.registerReceiver(this.DataStateChangedReceiver,
new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED));
Then I copied the code from the wifi receiver and edited it:
private BroadcastReceiver DataStateChangedReceiver
= new BroadcastReceiver()
{
#Override
public void onReceive(Context context, Intent intent)
{
// TODO Auto-generated method stub
int extraDataState = intent.getIntExtra(TelephonyManager.EXTRA_STATE ,
TelephonyManager.DATA_DISCONNECTED);
switch(extraDataState){
case TelephonyManager.DATA_CONNECTED:
data_toggle.setChecked(true);
break;
case TelephonyManager.DATA_DISCONNECTED:
data_toggle.setChecked(false);
break;
case TelephonyManager.DATA_CONNECTING:
data_toggle.setChecked(true);
break;
case TelephonyManager.DATA_SUSPENDED:
data_toggle.setChecked(true);
break;
}
}
};
The app starts but nothing happened with the toogleButton..
Is TelephonyManager the wrong way to do this? ConnectivityManager?
I want to set an onclicklistener to turn on / off the mobile data.
How to do this is the next question..
In my work I have used a trick with ACTION_SCREEN_ON and _OFF...... So, the trick is in such thing.... you create boolean variable in Receiver.class, and then change it when connection state is changed.... And then in service (or activity), where you get intent do what to do.....
private boolean screenOff;
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
screenOff = true;
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
screenOff = false;
}
Intent i = new Intent(context, InternetService.class);
i.putExtra("screen_state", screenOff);
context.startService(i);
}