Broadcast receiver is not stopping - android

i am working on an app that will automatically decline incoming calls from specific numbers and send an sms in return.my broadcast receiver should be enabled from my app only.
so, i added ( android:enabled="false" ) this. but, the receiver is still on by default. i'm struck here.
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.sifydy.automsgr.Automsgr"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name="com.sifydy.automsgr.Receiver"
android:label="#string/app_name"
android:enabled="false">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
</application>
wen i switch on my mobile, my receiver is also activated wen ever there is an incoming call.
i am able disable it from my app. everything is fine once i am in my app. how to disble it by default?

Related

Android PHONE_STATE not fired if phone is inactive for a night

My Android app invokes a webservice or sends SMS when a new incoming call received. I use android.intent.action.PHONE_STATE intent for this.
Everything works fine, except: the app must be restarted every morning.
It looks like if something prevents the app from receiving this broadcast if it is not used for hours, for a night.
What can cause this kind of behavior?
<application>
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".CallReceiver">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE"/>
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_CALL_LOG"/>

Intercept button on bluetooth headset

I am trying to intercept the only one button on a bluetooth headset. I have tried many things found on the site but none worked. The main activivity manages the bluetooth connection (using a code from https://github.com/sauravpradhan/AnySound2BT).
I have the following manifest file :
...
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppBaseTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:priority="2147483647">
<action android:name="android.intent.action.VOICE_COMMAND"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<receiver android:name=".MyReceiver" >
<intent-filter>
<action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED" >
</action>
</intent-filter>
</receiver>
...
When I click once, nothing happens and the second time the phone asks me to start "S voice" or "Google appli".
Thanks for any hint
Karim
Their are many methods to intercept the button function if this button really did something.
According to your description, the phone asks you to start "S voice" or "Google appli" then I assume one of the button's combined function is "Voice Recognition Activation".
You can export the btsnoop log of the Android, then click the HFP tab, to find out the AT command, then you can understand what the button sends.
Note that for all of the button on the headset, the long press,short press, and continue short press, the the press during calling or not calling,might have different meaning.

How to intercept incoming sms with my custom sms app?

I've almost made my sms app, only one bug still remains. When phone receives incoming sms it somehow goes to my app and to default one. I thought that problem was in action of intent, but changing it does nothing. The question is - how to intercept incoming sms and forbid default app to do the same?
AndroidManifest:
<manifest package="lexzcq.com.smska"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission
android:name="android.permission.SET_PREFERRED_APPLICATIONS"
tools:ignore="ProtectedPermissions"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:launchMode="singleTask"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
<intent-filter android:priority="999">
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.APP_MESSAGING"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<receiver
android:name=".SmsReceiver"
android:permission="android.permission.BROADCAST_SMS"
>
<intent-filter android:priority="999">
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
<category android:name="android.intent.category.APP_MESSAGING"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</receiver>
<activity android:name=".ChatWindow">
<intent-filter>
<action android:name="com.lexzcq.com.lexzcq.sms_receive_intent"/>
</intent-filter>
</activity>
<application android:name=".MyApp">
</application>
</application>
</manifest>
SmsReceiver.class
public class SmsReceiver extends BroadcastReceiver {
#Override
public void onReceive (Context context, Intent intent) {
*//here I handle sms from pdus*
Intent broadcastIntent = new Intent ()
.putExtra ("address", address)
.putExtra ("body", body)
.setAction ("com.lexzcq.sms_receive_intent");
*//here I'm writing sms to database*
context.sendBroadcast (broadcastIntent);
abortBroadcast ();
}
}
}
If needed - I can provide broadcast receivers from MainActivity.class
P.S. Most weird part - that when I'm sending sms it somehow saves to default app but I didn't broadcast it with SMS_RECEIVED_ACTION.

Is there any way to intercept Android M Bluetooh off scanning data?

I just have read that Android M performs bluetooth scanning even when the bluetooth is off
(Here is the first question: Is it only BLE scanning?).
So i thought it would be reallly nice to intercept that scanning data to discover the beacons.
I tried to register a broadcast receiver for android.bluetooth.device.action.FOUND in Manfest.
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".BluetoothReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.bluetooth.device.action.FOUND" />
</intent-filter>
</receiver>
</application>
Unfortunetally that broadcast only comes on Android 5.1 and less but not the M.
Is there any way to intercept that scnanning data in order to save a battery and not running a service that manually performs scans, as the Android Beacon Library from Radius Network does?

time since factory reset android

I'm trying to log time reliable how long a device is run. I've tried my best with BOOT_COMPLETED BroadcastReceiver. Due to the fact that all receiver are removed if an app is force stopped this method is not working for me.
I was wondering if there is a way to get the uptime of an Android device since the last factory reset has been performed?
The Manifest:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".TestReceiver"
android:enabled="true"
android:exported="true"
android:label="Test Receiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
Receiver Code:
public class TestReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Log.i("bootreceiver", intent.toString());
}
}
For anyone reaching this actually looking for a answer to the title question:
You can try getting the install time for one of the system packages, for instance:
long curTime = System.currentTimeMillis();
long installTime = getPackageManager().getPackageInfo("com.android.providers.applications", 0).firstInstallTime;
long timeDiff = curTime - installTime;
I'm not pretty sure how do you want to calculate uptime from factory reset, not from last reboot. However, if you are storing some of your data and checking was it erased on boottime - it might work.
However, I think here is a good idea to use BroadcastReceiver for BOOT_COMPLETED. And it's generally false that receivers are deleted after force close. It applies only for receivers from code.
Instead, you can define your receiver in Manifest - http://developer.android.com/guide/topics/manifest/receiver-element.html
If you'll do - it will be executed each reboot, regardless of anything.
Good luck
You have a problem defining permission in your Manifest.
It should look like that:
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".TestReceiver"
android:enabled="true"
android:exported="true"
android:label="Test Receiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
You should define you app's permission in Uses block. And the permssion that you'd added to your Broadcast - it does not add you a permission to receive it, it just forces any other app, that can trigger your broadcast, to have this permission. So unuseful in your case.
Hope it helps

Categories

Resources