I am building a simple sms app , i want to open my app automaticaly when ever a new sms is received? is it even possible?
i am using broadcast receiver for this
what changes should i made in manifest?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.message"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".MessageActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<receiver android:name=".SmsReceiver" >
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</activity>
<activity android:name=".Reply" >
</activity>
</application>
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
</manifest>
you should move the receiver outside from the activity like this:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".MessageActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Reply" >
</activity>
<receiver android:name=".SmsReceiver" >
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
Under Android 3.0 and later, your broadcast is not guaranteed to be received unless the user has opened your application. The application does not have to remain opened, just to have been started once. This is caused by a flag (FLAG_EXCLUDE_STOPPED_PACKAGES) which is now part of most system broadcasts, which says the broadcast should not start a stopped application.
This was already answered in How to make android launch an application on received specific sms to keep it short: it is possible with BroadcastReceiver.
Related
I have an App that uses a Service that I've added by a Bindable Jar.
Current state:
this Jar has an own Manifest (see below), when I don't touch anything on this Manifest everything works as it should.
Problem:
This Jar lets on Deployment to Device always its launer AppIcon on Device.
So my App leaves finaly two launcher icons, the one desired and the other from the Jar.
My Approach was to delete follow Part from Manifest:
android:theme="#style/AppTheme">
<activity
android:name=".ScanDemoActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Doing this the App Crashed on BootUp with Error: BootReceiver not found ...
Deleting the next few Lines:
<receiver android:name="com.company.scandemo.BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<category android:name="android.intent.category.HOME"/>
</intent-filter>
</receiver>
caused started correctly on bootUp, but the Service didn't come up on BOOT_COMPLETED, when I start the App via Launcher icon everything worked.
Wished Behaviour:
I want the Main App to leave only one launch Icon and startup correctly on Boot
Here is the Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.company.scandemo"
android:versionCode="1"
android:versionName="2.2" >
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name=".ScanDemoActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.company.scandemo.FloatingService" />
<receiver android:name="com.company.scandemo.BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<category android:name="android.intent.category.HOME"/>
</intent-filter>
</receiver>
</application>
</manifest>
This is how my Manifest looks like:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lcukerd.earphonereminder">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<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="ConnectivityActionReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="android.net.wifi.WIFI_STATE_CHANGE" />
</intent-filter>
</receiver>
</application>
</manifest>
My Receiver works fine when registering from activity but I want to register from manifest so that it can run even when the app is closed. What is the issue? Why is it not working?
Since Android Oreo, receivers must be registered in runtime using
context.registerReceiver(receiver, intentFilter);
to receive implicit intents
You can still receive explicit intents and some special implicit actions, as boot_completed or locale_changed for example
More information look below link
https://developer.android.com/about/versions/oreo/background.html#broadcasts
Try Using .ConnectivityActionReceiver instead of ConnectivityActionReceiver. when you Call ConnectivityActionReceiver The Receiver won't be Registered Since No Class is Found
<receiver
android:name=".ConnectivityActionReceiver"
android:enabled="true"
android:exported="true">
<intent-filter android:priority="100">
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="android.net.wifi.WIFI_STATE_CHANGE" />
</intent-filter>
</receiver>
Refer This Question to know More
I have an app I'm working on where I have a broadcast receiver for outgoing calls. It works fine on the emulator, but not my Galaxy Note 2. It appears that either the Outgoing Call broadcast is never issued, or it's being consumed before I can get a hold of it.
I've heard rumours that Samsung does this funny. Hope someone knows specifically what.
Android Manifest follows.
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<receiver android:name="OutgoingCallHandler" android:exported="true" android:enabled="true" >
<intent-filter android:priority="1">
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
<activity
android:name="MainActivity"
android:label="#string/title_activity_main"
android:theme="#android:style/Theme.NoDisplay" >
</activity>
<activity
android:name="SettingsActivity"
android:label="#string/title_activity_settings" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
in writing a widget and after i tried to add a setting activity for my widget , i got the error "No Launcher activity found!"
this is my AndroidManifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.persianweather"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<receiver android:name="com.example.persianweather.Main" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<!-- This specifies the widget provider info -->
<meta-data
android:name="android.appwidget.provider"
android:resource="#xml/widget" />
</receiver>
<activity
android:name="com.example.persianweather.SettingActivity"
android:label="#string/title_activity_setting" >
<intent-filter >
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>
</application>
No Launcher activity found! means that you not mentioned any activity on launching the application. Try to add these lines in manifest. To specify these MAIN and LAUNCHER in the the intent filter for the activity you want to start on launch like:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Note: Multiple action tags in a single intent-filter tag will also cause the same error.
Make your SettingActivity as launcher activity, Only then you will be able to proceed further,
<activity
android:name="com.example.persianweather.SettingActivity"
android:label="#string/title_activity_setting" >
<intent-filter >
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I want to start BroadcastReceiever on installation of my application. I found some Thread over stackoverflow that this could be done by using Boot Complete BroadCastReceiever.
But After writing code we could not get success because my receiver did not call at all.
Manifest File:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.broadcastdemo"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.broadcastdemo.MainActivity"
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.example.broadcastdemo.BootReceiver"
android:enabled="true"
android:exported="false"
>`
`
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
</manifest>
Did you register the receiver in manifest.xml
<receiver
android:name="YOUR_ACTION_STRING.BootCompletedReceiver"
android:enabled="true"
android:exported="false" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>