I am new to android and I'm having this problem
if the app is in the foreground the notification shows normally
if I put the app in the background the notification will show and it works normally also
BUT the problem is -> when I close the application(the app is killed) the notification does not show <-
solutions I tried
only send notification
only send data
not putting a custom view for the notification
what I understand is if I send only notification without data it will show when the app is in the foreground AKA when it's open and you can see it and
if I only send data without notification it will show in the background and when the app is killed and the data will be found in the main activity intent (but clearly this is NOT the case for me)
I am using an android 10 Infinix Note 5 stylus just in case there is something with this model
but I still can see notifications from any other app normally
edit
so I tried to run the app on other phones and it works as it supposed to but on my phone all the notifications that is sent when the app is closed will only show when I open the app
I close the app -> send some notifications -> no thing on the phone ->
open the app again -> all the notifications I sent are are now there
it still works fine when i send the notifications when the app is on foreground and when i put it in the backgorund
code:
public class FirebasePushNotificationConfig extends FirebaseMessagingService {
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
sendNotification(remoteMessage);
}
private void sendNotification(RemoteMessage remoteMessage) {
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(AppStrings.MSG.name(), "Testing", NotificationManager.IMPORTANCE_DEFAULT);
channel.enableVibration(false);
channel.enableLights(true);
manager.createNotificationChannel(channel);
}
PendingIntent pendingIntent = getPendingIntent(remoteMessage);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, AppStrings.MSG.name())
.setSmallIcon(R.drawable.ic_notifications_black_24dp)
.setVibrate(null)
.setContentTitle(remoteMessage.getData().get(AppStrings.MSG.name()))
.setContentText(remoteMessage.getData().get(AppStrings.MSG.name()))
.setAutoCancel(true)
.setWhen(System.currentTimeMillis())
.setContentIntent(pendingIntent);
Notification n = mBuilder.build();
manager.notify(1, n);}
private PendingIntent getPendingIntent(RemoteMessage remoteMessage) {
Intent intent = new Intent(this, LoginActivity.class);
intent.putExtra(AppStrings.Notifications_Data.name(), remoteMessage.getData().get(AppStrings.Notifications_Data.name()));
intent.putExtra(AppStrings.Is_There_Notification.name(), AppStrings.YES.name());
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra(AppStrings.Notifications_Destination.name(), remoteMessage.getData().get(AppStrings.Notifications_Destination.name()));
return PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
}
#Override
public void onNewToken(String token) {
super.onNewToken(token);
System.out.println("log Token is " + token);
Log.d("Test", "token: " + token);
}}
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.test">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_NUMBERS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.SET_ALARM " />
<uses-permission android:name="android.permission.READ_PHONE_STATE " />
<uses-permission android:name="android.permission.READ_PHONE_NUMBERS " />
<uses-permission android:name="android.permission.READ_SMS " />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:name=".Config.App"
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"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".LocationActivity"></activity>
<activity android:name=".MapsActivity" />
<!-- <activity android:name=".ProfileActivity" />-->
<activity android:name=".ChatManagerActivity" />
<activity android:name=".RegisterActivity" />
<activity android:name=".MainActivity" />
<activity android:name=".AuthActivity" />
<activity android:name=".ChatActivity" />
<activity android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name=".LoginActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<receiver
android:name=".broadcastRecivers.AlertReciver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<receiver
android:name=".broadcastRecivers.LoginReciver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service
android:name=".Config.FirebasePushNotificationConfig"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="key" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.example.test.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths" />
</provider>
</application>
</manifest>`
the data I send looks like this
{"to":"key"
,"notification":{
"title":"hello it's test"
,"body":"still a test"
},
"data": {
"Notifications_Destination" : "direction"
,"MSG":"this is a test notifiation",
"Notifications_Data":5
}}
create FcmHelper class with extends FirebaseMessagingService.
<!--Fcm Starts-->
<service
android:name="google_classes.FcmHelper"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/ic_noti" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="#color/black" />
<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="#string/default_notification_channel_id" />
<meta-data
android:name="firebase_messaging_auto_init_enabled"
android:value="true" />
<!--Fcm End-->
Try this:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
and under application tag add:
<service android:name=".FirebaseService"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
</intent-filter>
</service>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Change class names as per requirements.
Related
I integrated OneSignal push notification into my app and everything worked perfectly well until I upgraded to Android 12 (31). When I upgraded, AndroidStudio reports this error to me, I really don't know what I need to do to avoid it:
Manifest merger failed : android:exported needs to be explicitly specified
for <service>. Apps targeting Android 12 and higher are required to specify
an explicit value for `android:exported` when the corresponding component
has an intent filter defined.
AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.my.app">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-permission android:name="oppo.permission.OPPO_COMPONENT_SAFE"/>
<uses-permission android:name="com.huawei.permission.external_app_settings.USE_COMPONENT"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:name="com.my.app.MainApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:networkSecurityConfig="#xml/network_security_config"
android:theme="#style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="#string/admob_app_ID" />
<activity
android:name="com.my.app.activity.StepActivity"
android:screenOrientation="portrait"
android:theme="#style/Splash">
</activity>
<activity android:name="com.my.app.activity.PrivacyPolicyActivity"
android:screenOrientation="portrait"/>
<activity android:name="com.my.app.activity.TermsToUseActivity"
android:screenOrientation="portrait"/>
<activity android:name="com.my.app.activity.SplashActivity"
android:screenOrientation="portrait"
android:exported="true"
tools:node="merge">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.my.app.activity.MainActivity"
android:screenOrientation="portrait"/>
<activity android:name="com.my.app.activity.PremiumActivity"
android:screenOrientation="portrait"/>
<activity android:name="com.my.app.activity.ChooseServerActivity"
android:screenOrientation="portrait"/>
<service
android:name="com.my.app.OneSignal.MyNotificationExtenderService"
android:exported="true"
tools:node="merge"
android:permission="android.permission.BIND_JOB_SERVICE">
<intent-filter>
<action android:name="com.onesignal.NotificationExtender" />
</intent-filter>
</service>
<service
android:name="com.my.app.service.BackgroundJobService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:enabled="true"
android:exported="true"
tools:node="merge"/>
<service
android:name="com.my.app.service.MyService"
android:exported="false"
tools:node="merge">
<intent-filter>
<action android:name="androidsrc.intent.action.PICK_PLUGIN" />
<category android:name="androidsrc.intent.category.ADD_PLUGIN" />
</intent-filter>
</service>
<receiver android:name="com.my.app.service.BootCompletedReceiver"
android:enabled="true"
android:exported="true"
tools:node="merge">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
</intent-filter>
</receiver>
</application>
build.gradle (app):
manifestPlaceholders = [onesignal_app_id : "xxxxx-xxxx-xxxx-xxx-xxxxxxxx",
onesignal_google_project_number: "REMOTE"]
I have tried every solution on the internet. But none of them worked for me. Could you check where I am doing wrong?
Maybe it no longer works in higher Api.
Here is my broadcastReceiver class :
public class ReceiverToStartAnApp extends BroadcastReceiver {
#Override
public void onReceive(final Context context, Intent intent) {
Toast.makeText(context, "Home Task 3 Version ", Toast.LENGTH_LONG).show();
Intent myIntent = new Intent(context, CameraRecorderActivity.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(myIntent);
}
}
Here is my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hometaskversion3">
<uses-permission android:name="android.permission.RECORD_VIDEO" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:requestLegacyExternalStorage="true"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.HomeTaskVersion3">
<activity
android:name=".ui.CameraRecorderActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".service.RecorderService" />
<receiver
android:name=".receiver.ReceiverToStartAnApp"
android:directBootAware="true"
android:enabled="true"
android:exported="true">
<intent-filter android:priority="1000">
<action android:name="android.intent.action.BOOT" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
</manifest>
First of all, apps that have never been started in some way do not receive system broadcasts. So you need some activity of your app to start before you receive ACTION_BOOT_COMPLETED.
Second, as noted in the comments, it is no longer allowed to start an activity from a receiver unless some conditions are met. The preferred way to do it is to show a notification with a pending intent for the activity you need to start. This approach will be less intrusive for the user.
My app is a launcher that I make the default right after the installation and it does read NFC tags without problems on the first launch but if I lock the phone and them unlock it (at this point my app is already on screen and onResume() is called) the app stops to read the tags (a different sound is played when an tag is read by the phone, I guess it's the NFC fail sound) and the onNewIntent(Intent intent) is not called.
I already tried to make my filters and intents being activity scoped instead of local (removed from setupForegroundDispatch) but stills the same problem. If I reopen the app (kill and start again) then the NFC reader does read right.
So below is my logic:
NfcAdapter nfcAdapter;
#Override
protected void onResume() {
super.onResume();
if (nfcAdapter == null){
nfcAdapter=NfcAdapter.getDefaultAdapter(this);
}
setupForegroundDispatch(this, nfcAdapter);
}
public static void setupForegroundDispatch(Activity activity, NfcAdapter adapter) {
final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass());
final PendingIntent pendingIntent = PendingIntent.getActivity(
activity.getApplicationContext(), 0, intent, 0);
IntentFilter[] filters = new IntentFilter[2];
String[][] techList = new String[][]{};
filters[0] = new IntentFilter();
filters[0].addAction(NfcAdapter.ACTION_TAG_DISCOVERED);
filters[1] = new IntentFilter();
filters[1].addAction(NfcAdapter.ACTION_TECH_DISCOVERED);
adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);
}
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
String action = intent.getAction();
if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action) ||
NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)) {
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
if (tag != null) {
//do my logic here
}
}
}
#Override
protected void onPause() {
super.onPause();
nfcAdapter.disableForegroundDispatch(this);
}
My manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="br.org.company.app">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.CALL_PRIVILEGED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_NUMBERS" />
<uses-permission android:name="android.permission.STATUS_BAR" />
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.PREVENT_POWER_KEY" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
<uses-permission android:name="android.permission.REORDER_TASKS" />
<uses-permission android:name="android.permission.NFC" />
<uses-feature
android:name="android.hardware.nfc"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:sharedUserId="android.uid.system"
android:supportsRtl="true"
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
android:versionName="1.2.1xdk"
android:usesCleartextTraffic="true">
<meta-data
android:name="com.google.android.actions"
android:resource="#xml/actions" />
<receiver android:name=".receivers.GpsLocationReceiver">
<intent-filter>
<action android:name="android.location.PROVIDERS_CHANGED" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.location.LocationManager.KEY_LOCATION_CHANGED" />
</intent-filter>
</receiver>
<receiver
android:name=".receivers.PassiveLocationChangedReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.location.LocationManager.KEY_LOCATION_CHANGED" />
</intent-filter>
</receiver>
<receiver
android:name=".receivers.BootReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.BOOTUP_COMPLETE" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
<receiver android:name=".receivers.MyWakefulReceiver" />
<receiver android:name=".receivers.InternetConnectionReceiver">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="android.net.wifi.WIFI_STATE_CHANGE" />
</intent-filter>
</receiver>
<receiver android:name=".receivers.IncomingCall">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
<activity
android:name=".FirstScreenActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:sharedUserId="android.uid.system"
android:soundEffectsEnabled="true"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".FullscreenActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:sharedUserId="android.uid.system"
android:soundEffectsEnabled="true"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.CALL_BUTTON" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<data android:mimeType="text/pg" />
</intent-filter>
<meta-data
android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="#xml/nfc_type" />
</activity>
<receiver
android:name=".AppDeviceAdmin"
android:description="#string/app_name"
android:label="#string/app_name"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data
android:name="android.app.device_admin"
android:resource="#xml/app_device_admin" />
<intent-filter>
<action android:name="android.app.action.PROFILE_PROVISIONING_COMPLETE" />
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
</application>
</manifest>
On logcat there's no exceptions, seens that the NFC reads are not even delivered to my application. (After it gets back from the background and the phone reads a NFC not even the onPause(), onResume() are triggered on my application)
So far seens it's related to my application being a launcher, although I didn't find anything about this restriction.
So I found an answer to my problem; This app is a total fullscreen (internal app of the company) so in my onCreate() I had various flags to keep the app on screen and to avoid the keyguard on lock screen whenever possible (to avoid users to go to other apps) and that was the problem, my app had
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
WindowManager.LayoutParams.FLAG_FULLSCREEN
and for some reason preventing the keyguard to show up (run the app over the lock screen) disables the NFC delivery to the app (for security reasons, I guess). Since this is an internal app (and all the phones are pre seted by the I.T team) the solution was to manually remove the keyguard from lock screen by phone settings and remove the flags
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
so everytime the user locks and unlocks the phone the sistem enables the NFC reader again.
Below is my manifest.xml
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19" />
<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=".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.tcl.receiver.BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name="com.tcl.factoryresetservice.SystemMessageService" android:exported="false">
<intent-filter>
<action android:name="com.tcl.factoryresetservice.SystemMessageService" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</service>
Below is my receive code:
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
//start the service at boot completed
if(intent.getAction().equals(BOOT_COMPLETED))
{
long curTime = System.currentTimeMillis();
Log.e(TAG,"Start SystemMessageService Service , curTime="+curTime);
Intent i = new Intent(context,SystemMessageService.class);
context.startService(i);
}
}
after factory reset the device, the system run, but my service doesn't run. if I reboot, it runs successfully. Why it happen like this, please help us, thanks.
Your UserPermission is correct
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Your receiver should be like this
need to add permission in receiver
<receiver
android:name="com.tcl.receiver.BootReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
I am trying to remove a shortcut from the home screen that my app has already added. I have tried the methods in these links but I can't figure out how to adapt their solutions to my code. I dont have a rooted device so I cant find the URI.
https://codinggeekorg.wordpress.com/2011/01/31/android-home-screen-shortcuts-part-iii-remove-shortcuts/
Trying to UNINSTALL_SHORTCUT but shortcut won't go away
Android: Remove app shortcut from home screen
Here is where I create the shortcut:
protected void ShortcutCreatorActivity(String number, String message, String name) {
Intent shortcutIntent = new Intent(getApplicationContext(), ShortCutActivity.class);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
shortcutIntent.putExtra("number", number);
shortcutIntent.putExtra("message", message);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);
}
This is my manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.abezukor.autosms" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
<uses-permission android:name="android.permission.SEND_SMS" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".RelativeLayoutActivity"
android:label="#string/app_name" >
</activity>
<activity
android:name=".ListViewActivity"
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=".ShortCutActivity"
android:label="AutoSms">
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Thanks for your help in advance.