broadcastreceiver

PendingIntent get requestCode

∥☆過路亽.° 提交于 2019-12-01 16:03:43
I use an AlarmManager to start a service. When i set up the AlarmManager i use the PendingIntent and use a unique requestCode which is equal to a id row in my database. PendingIntent pendingIntent = PendingIntent.getBroadcast(SettingsActivity.this, lecture.getId(), myIntent, 0); How can I retrieve that id in my service when it starts? I basically need only the requestCode parameter. I want to use that id to retrieve data from my database and show it in a notification. I have implemented all the stuff, I just need that requestCode. Is it possible to get it? Thanks You need to put lecture.getId(

How to programmatically answer a call in Android 4.0.3?

拈花ヽ惹草 提交于 2019-12-01 15:02:53
So as the subject states I need to be able to answer a phone call programmatically in Android 4.0.3 on an HTC OneX. I have read several places that the MODIFY_PHONE_STATE permission has been revoked by Google so to do this task you need a work around. I have looked into two avenues so far: (1) Following Guy's post here and using a BroadcastReceiver (2) Using the following code to try and hit a key event through a shell command. final Runtime r = Runtime.getRuntime(); try { Process process = r.exec("input keyevent 5"); InputStream stream = process.getErrorStream(); log.v("Process Error Stream:

Android - Bluetooth device connected broadcast

霸气de小男生 提交于 2019-12-01 14:55:43
I want to have a broadcast receiver listening for BT devices connecting. Could anybody tell me which broadcast I have to listen to? I tried android.bluetooth.device.action.ACL_CONNECTED but it doesn't seem to work. Thank you. If you are looking whether the device is "connecting" then you'd want android.bluetooth.adapter.action.CONNECTION_STATE_CHANGED However, this does not get triggered when the device is STATE_CONNECTED. So what I did was when the state is connecting, to send a broadcast in a few seconds. if (bluetoothAdapter .getProfileConnectionState(BluetoothProfile.HEADSET) ==

Can't call a Bluetooth BroadcastReceiver method in a Service

拈花ヽ惹草 提交于 2019-12-01 14:41:53
I have this Service class: public class BluetoothService extends Service { private static Activity mActivity; @Override public IBinder onBind(Intent intent) { return null; } @Override public void onCreate() { IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); this.registerReceiver(bluetoothReceiver, intentFilter); } @Override public void onDestroy() { if (bluetoothReceiver != null) { this.unregisterReceiver(bluetoothReceiver); } } @Override public void onStart(Intent intent, int startid) { // } @Override public int onStartCommand

how to fire notification from BroadcastReceiver?

送分小仙女□ 提交于 2019-12-01 14:25:41
how to fire notification from BroadcastReceiver (can't use most methods and can't use "this")? I need it to open a activity with info from the DB I already did it but now must of the methods dosen't work and I cant use "this" In the onReceive method you get a Context object. So use it to get the NotificationManager and fire your notification. public void onReceive(Context ctx, Intent intent) { NotificationManager nm = (NotificationManager)ctx.getSystemService(Context.NOTIFICATION_SERVICE); //Create the notification here. nm.notify(NOTIFICATION_ID, notification); } An Activity and a Service are

Broadcast Receiver not processing SMS's

青春壹個敷衍的年華 提交于 2019-12-01 14:06:18
I've seen on SO that @Commonsware states that all that is needed to receive SMS's is a Broadcast Receiver (i.e., without the use of a service). I'd like to employ that approach since it makes sense to me. Unfortunately it does not appear as if SMS's are being received/processed in my Broadcast Receiver. The apk is being installed successfully but no log entries are being generated when I send test SMS's. What am I doing wrong? Here's the Manifest: <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="net.oheller.pete2" android:versionCode="1" android:versionName="1.0" >

Android, How to receive home button click through broadcast receiver?

ぐ巨炮叔叔 提交于 2019-12-01 13:39:40
In my application I need to send log-out request to server when ever user goes out of application via clicking on log-out button or closing application by pressing home button key. There is no problem with button and result is as I expect. The problem is how to get home button. Based on my research it is not possible to use onKeyDown(int keyCode, KeyEvent event) as we can use for getting back button. The solution that I'm thinking about is registering a receiver and sending a broadcast whenever Home button clicked. So through receiver I can launch a service to send log-out request to server.

BroadcastReceiver with a Listener drains battery when not in use

◇◆丶佛笑我妖孽 提交于 2019-12-01 13:03:10
I have a receiver which waits for TelephonyManager.ACTION_PHONE_STATE_CHANGED : public void onReceive(Context context, Intent intent) { String theAction = intent.getAction(); if (theAction != null && theAction.equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) { CONTEXT = context; startListening(); } When it gets it, I register the listener (for orientation sensor): public void startListening() { sensorManager = (SensorManager) CONTEXT.getSystemService(Context.SENSOR_SERVICE); List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ORIENTATION); if (sensors.size() > 0) { sensor =

Broadcast Receiver not processing SMS's

不打扰是莪最后的温柔 提交于 2019-12-01 12:58:08
问题 I've seen on SO that @Commonsware states that all that is needed to receive SMS's is a Broadcast Receiver (i.e., without the use of a service). I'd like to employ that approach since it makes sense to me. Unfortunately it does not appear as if SMS's are being received/processed in my Broadcast Receiver. The apk is being installed successfully but no log entries are being generated when I send test SMS's. What am I doing wrong? Here's the Manifest: <manifest xmlns:android="http://schemas

BroadcastReceiver with intent-filter for them?

混江龙づ霸主 提交于 2019-12-01 12:44:22
Her is what I'm trying to accomplish: When user tries to share some text from any app (Like sharing a tweet or a link), my app will appear in the sharing list. If he select my app, some simple code will be run (like showing a Toast) then that's it. No interface or UI is needed. Here is how I did it: AndroidManifest.xml <receiver android:name=".MyBroadcastReceiver" > <intent-filter android:label="select my app"> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="text/plain" /> </intent-filter> </receiver>