Broadcast Receiver not working when app is not running - java

My broadcast receiver does not work when the application is not running in the background.
Tried with different intent filters
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme.NoActionBar" >
<receiver android:name=".network.NetworkChangeReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
<activity
android:name=".view.activity.MainActivity"
android:label="#string/app_name">
</activity>
<activity android:name=".view.activity.BarLoginActivity"
android:label="#string/app_name">
<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.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
My receiver works fine when the app is running in the background but as soon as I remove my recent apps it does not work.
Running on API 19

Finally it worked in other android phones.
as broadcast receivers and services are by default not allowed in Xiaomi phones

I would try putting a android:process=":remote" in the Manifest definition of the receiver so that it will run on a separate task.

Haven't seen your entire AndroidManifest but my first suspect is that you're lacking the proper permission.
In order to listen to network changes you must declare that you are using this permission in the manifest like this
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
the next suspect is the name you gave, maybe try giving the full path to the reciever name

Related

I set android:exported but I am still getting error: android:exported needs to be explicitly specified for <receiver>

I am moving from SDK version 30 to 31 and I add android:exported in intent-filter but still I am getting this error:
Merging Errors: Error: android:exported needs to be explicitly specified for . 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. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.
<?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.mycompany.webviewapp">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:name=".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">
<!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>
<activity android:name="com.mycompany.webviewapp.SplashActivity"
android:exported="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.mycompany.webviewapp.MainActivity"
android:exported="true"
android:screenOrientation="portrait">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.VIEW"></action>
</intent-filter>
</activity>
<service android:name="com.mycompany.webviewapp.FCM.MyFirebaseMessagingService">
</service>
<meta-data android:name="applovin.sdk.key"
android:value="sdk api here"/>
</application>
</manifest>
The reason is because some of the dependency libraries that you're using have elements which do not have "android:exported" attribute.
You need to do this:
Lower the version in your gradle to 30 and sync and build.
Go to your AndroidManifest.xml file and click on "Merged Manifest".
Find items such as Activity, Receiver, Service, etc that don't have "android:exported" attribute.
Then add them to your AndroidManifest.xml file in this way.
<activity
android:name="SomeActivity"
android:exported="false"
tools:node="merge"
tools:replace="android:exported" />
Now you can increase your version to 31.
I resolve my issue. I just check the merged manifest and look for reciver. In onesignal, I found out reciver with intent filter defined without android:exported. I just add android:exported="false".

Android Deeplink opens application twice

i used webview to create app and implemented deep linking like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ariagp.myapplication">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<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>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="mysitename.com" />
</intent-filter>
</activity>
</application>
</manifest>
it will asking my for open with my application before open the links, but the problem is:
two applications will open in the phone task manager (the application does not open in the previous application which is running):
what is the solution?
Add android:launchMode="singleTask" in declared activity in AndroidManifest.xml.
And then, in your activity, you should override onNewIntent() method and you will get arguments there.
Ok, so you don't actually have a problem here.
This is just how deep links work. If you open one in a certain app, the deep link will open your app but in the same window the deep link was originally in.
Your app will have two instances in a way.
You could go to you web brower app and click share and any app that pops up. They all open in the web browsing app window. So there is nothing to worry about. I had the same problem myself before I realised that it is just how things work.
Some apps are just verified to open other apps if they implement the browsability.
Add android:launchMode="singleTask" in declared activity in AndroidManifest.xml.
And then, in your activity, you should override onNewIntent() method and call mNavController.handleDeepLink(intent) there.
It is worth mentioning that you are now able to get your arguments using, private val args: XFragmentArgs by navArgs()in your fragment.

Java: Android App works on virtual device but crashes on real one

I'm working on fall detection app. I was testing it on virtual devices API: 23,28,29 and app works fine but when I run this app on my phones with Android 6 and 9 it crash
immediately.
What are the solutions ?
Thanks in Advance.
Run desription
I checked MainActivity line from errors window but i have no suggestion what I can do.
MainActivity line175
Logcat errors after open app: Logcat
My manifest
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_falling_down_stairs"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<receiver android:name=".MyLocationService"/>
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version"/>
<activity android:name=".CaretakersList"></activity>
<activity android:name=".settingContact" />
<service
android:name=".AlertService"
android:enabled="true"
android:exported="true" />
<activity android:name=".MainActivity" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
This is because DecimalFormat generate localized string, and the decimal separator can be different in some locale.
You can force the good locale like this :
DecimalFormat precision = new DecimalFormat("0.00", new DecimalFormatSymbols(Locale.US));
More info here
From your stacktrace there is error in Real number format in method of your MainACtivity onSensorChanged with value "9,35". In java all floating numbers use dot like this "9.35". Check this method and use correct format of Real number

Flurry integration Android throwing errors

I'm trying to integrate flurry into my android app. I'm using the recommended setting and have repositories{jcenter()} and
// Required for Flurry Analytics integration
compile 'com.flurry.android:analytics:8.2.0#aar'
// Optional - If you want to use the Ads SDK
compile 'com.flurry.android:ads:8.2.0#aar'
in the gradle as the docs suggest. I keep getting errors in the that Application is not resolved. The docs really blow and I'm not 100% sure what going on. I've never integrated flurry before can someone please help! I put the manifest and the class i'm using below. I know it doesn't have a key I'm still working on removing errors. I'm dumping the that class in the main file for simplicity for now.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tempconversion.october.com.myapplication">
<!-- Required permissions - Internet access -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!-- Highly Recommended permission - External memory pre-caching -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- Optional permission - Location based ad targeting -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="F to C and K"
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>
</application>
</manifest>
class in main file
public class MyApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
new FlurryAgent.Builder()
.withLogEnabled(true)
.withCaptureUncaughtExceptions(true)
.withContinueSessionMillis(10)
.withLogLevel(VERBOSE)
.build(this, FLURRY_API_KEY);
}
}
Declare the application name in manifest.xml file.
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="F to C and K"
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>
</application>

Android AWS Security Credential Issue

I am having a problem integrating the AmazonS3PersonalFileStore demo app login into my App
I have set up my TVM and everything works fine on the demo app, it also runs correctly when I copy/paste the project and rename it.
The issue comes when I begin pasting my .javas from my main app into the pasted Demo app, now when I login, I get the error
Credential Problem!
AWS Credentials not configured correctly. Please review the README file.
the readme refers to project setup and the .properties file, all of which I did not touch
Here is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.amazonaws.demo.personalfilestore"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".S3PersonalFileStore"
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=".Login"></activity>
<activity android:name=".s3.S3BucketView"></activity>
<activity android:name=".s3.S3ObjectView"></activity>
<activity android:name=".s3.S3AddObjectView"></activity>
<activity
android:screenOrientation="portrait"
android:name="com.example.indrive.MainMenu"
android:label="#string/main_menu" />
<activity
android:screenOrientation="portrait"
android:name="com.example.indrive.TripMain"
android:label="#string/trips"/>
<activity
android:screenOrientation="portrait"
android:name="com.example.indrive.TripView"
android:label="#string/trip_view"/>
<activity
android:screenOrientation="portrait"
android:name="com.example.indrive.DiagnosticsMain"
android:label="#string/diagnostics"/>
<activity
android:screenOrientation="portrait"
android:name="com.example.indrive.DtcListView"
android:label="#string/dtcs"/>
<activity
android:screenOrientation="portrait"
android:name="com.example.indrive.RpmComparison"
android:label="#string/rpm_distribution"/>
<activity
android:screenOrientation="portrait"
android:name="com.example.indrive.UbiMain"
android:label="#string/ubi"/>
<activity
android:screenOrientation="portrait"
android:name="com.example.indrive.UbiView"
android:label="#string/ubi_view"/>
<activity
android:screenOrientation="portrait"
android:name="com.example.indrive.UsageMain"
android:label="#string/usage"/>
<activity
android:screenOrientation="portrait"
android:name="com.example.indrive.EnvironmentalMain"
android:label="#string/environmental_main"/>
<activity
android:screenOrientation="portrait"
android:name="com.example.indrive.ComparisonMain"
android:label="#string/vehicle_comparison"/>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="xxxxxxxx"/>
</application>
</manifest>
Although I have added new code, I am pretty sure that none of it is running, since none of my activities are being created
Update: I tried adding an EC2 role to the TVM Elastic Beanstalk with the same permissions as the IAM TVMUser, but the demo app wouldn't even work
Update 2: Tried a bunch of different IAM configurations for the TVM IAM User / Elastic Beanstalk, nothing worked
I had the same issue when integrating the AmazonS3PersonalFileStore demo app login into my app.
The problem was that the request to the TVM via the HTTP request was blocked. This is due to the android sdk's StrictMode.ThreadPolicy which does not allow network operations to execute on the UI thread.
This restriction can be changed, using:
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
Add the above code into your main activity's onCreate() method.
In addition, it is always recommended to move network operation off the UI thread, for example, using AsyncTask.
I am confident this will fix your problem.

Categories

Resources