broadcastreceiver

How to disconnect incoming call in android by programatically

允我心安 提交于 2019-12-03 17:25:14
I want to disconnect incoming call for a particular time. How can i do this is it impossible ? I searched and i find it is impossible. please help me. public class Telephony3 extends Service { Context context; public IBinder onBind(Intent intent) { return null; } public void onCreate() { super.onCreate(); try { StateListener phoneStateListener = new StateListener(); TelephonyManager telephonymanager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE); telephonymanager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); }catch(Exception e) { e.printStackTrace(); } } class

Get WiFi Signal Strength of Connected Network

坚强是说给别人听的谎言 提交于 2019-12-03 17:25:06
I'm trying to display the signal strength of the connected WiFi network in my Android app. I've tried the following: //Receiver for information on the network info private BroadcastReceiver mNetworkReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.d("INFO", "onReceive()"); List<ScanResult> scanResult = mWifi.getScanResults(); for(ScanResult scan : scanResult) { Log.d("INFO","Network strength: " + String.valueOf(scan.level) + " dBm " + scan.SSID); } } }; And then I do the registering/unregistering of my receiver on the onResume()/onPause(

AlarmManager: how to schedule a daily alarm and deal with time changes

喜你入骨 提交于 2019-12-03 17:11:27
问题 I need to set up an alarm daily at a given hour. I'm programming the alarm using AlarmManager.RTC_WAKEUP , so it uses the system time as reference. I'm setting the alarm to first execute at the desired hour, then to repeat daily: alarmManager.setRepeating( AlarmManager.RTC_WAKEUP, getTimestampToday("12:00"), AlarmManager.INTERVAL_DAY, pendingIntent ); The getTimestampToday method returns a long timestamp for today at the desired hour. It does so by obtaining the local date for today, then

Broadcast receiver - monitoring the Battery Level and Charging State

梦想的初衷 提交于 2019-12-03 16:28:57
I am trying to make two toasts: one when the device is charging, and one when it`s not. But the receiver acting crazy, sending many toasts, and crashing the app. I can not find the problem. thnx! This is the receiver in Main activity: public class PowerConnectionReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1); boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL; if (isCharging){ Toast.makeText(context, "The

Android usb enumeration

心已入冬 提交于 2019-12-03 16:03:47
I am writing an android USB host application for which I am trying to enumerate the devices connected with tablet. I follow the code in the android USB host documentation in the developer site. My code is as follows AndroidUSBActivity public class AndroidUSBActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); USBClass usb = new USBClass(); ArrayList<String> deviceList = usb.GetUSBDevices(getBaseContext()); final CharSequence[] items =

Scheduled Alarm Manager not working Android

岁酱吖の 提交于 2019-12-03 15:39:29
I am trying to start an alarm service that repeats every day at a particular time. I have gone through a lot of threads on stack overflow regarding this but no luck. I followed a few tutorials: http://karanbalkar.com/2013/07/tutorial-41-using-alarmmanager-and-broadcastreceiver-in-android/ and http://javatechig.com/android/repeat-alarm-example-in-android My service is never started and I do not understand why. Below is my code: My Manifest file: <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses

Broadcast Receiver in kotlin

北慕城南 提交于 2019-12-03 15:22:14
问题 How to use register and create a Broadcast Receiver in Android in Kotlin. Any advice.... In Java, you can create it by declaring it as a Broadcast Receiver.But in Kotlin there is no Broadcast Receiver function...well if it is there then I am not able to find it or how to use it. 回答1: you can do it in the following way Create a broadcast receiver object in your activity class val broadCastReceiver = object : BroadcastReceiver() { override fun onReceive(contxt: Context?, intent: Intent?) { when

Problem acquiring wake lock from broadcast receiver

不羁的心 提交于 2019-12-03 15:13:22
I have a problem. I am trying to make a broadcast receiver acquire a wake lock so my alarm will wake the phone from sleep mode. In the broadcast receiver below, the program crashes with "source not found" on line "sCpuWakeLock.acquire(); when the class "AlarmAlertWakeLock" is called by AlarmReceiver. Any idea what's going on? Is there a better way to do what I'm trying to do? In one file: import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; public class AlarmReceiver extends BroadcastReceiver { @Override public void onReceive(final Context

How to send data to a running activity from Broadcast Receiver,

痞子三分冷 提交于 2019-12-03 14:42:01
I am able to receive C2DM message fine but I want to send the data to a running activity, i.e when the activity is running, if the receiver receives C2DM message it is to send the data to the running activity. The code of receiver is (no bugs in the code): public class C2dmreceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); Log.w("C2DM", "Message Receiver called"); if ("com.google.android.c2dm.intent.RECEIVE".equals(action)) { final String payload = intent.getStringExtra("key1"); Log.d("C2DM", "message = " +

List of Android task killers

北战南征 提交于 2019-12-03 14:04:50
问题 I am trying to do a list of Android task killers that are installed by default on the operating system. The problem is that Android is modified by the phone's manufacturer and it is hard to keep up with what everyone is doing. So far I have found this: Smart manager - On Samsung phones. Could not call alarm manager but you can avoid this if your package name contains "alarm" or "alert" Doze - On Android 6. should not interrupt the app but it may delay alarm manager or network processes