Android-Launching an application when tablet boot up is completed - java

i am using Android 3.2, i created my android application and that will start automatically when my tablet start booting is completed.
Everything works fine except the activity is running twice when apps is start running automatically (after boot completed).
This problem is not raised when i start the app manually.
public class BootStartUpApp extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Intent startUpApps = new Intent(context, StartMainActivity.class);
startUpApps.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(startUpApps);
}
}
in Manifest file i added below code :
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver android:name="com.logica.eHealthBox.tab.activity.BootStartUpApp" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>

here's how to do it:
public class BootReceiver extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context, TestReceiversActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
put an entry in the manifest:
<receiver android:name=".BootReceiver" />
and have the activity too.
for more info , check this link and this link

Related

Why an activity doesn't start?

I call an aidl method that calls me back after some logic, in this callback method I try to start an Activity, but the activity doesn't start and there are no exceptions. Interesting fact, it works on Android 9, but on 10 and 6 doesn't.
Manifest
<activity
android:name=".views.ReceiptsActivity"
android:launchMode="singleInstance"
android:windowSoftInputMode="stateHidden|adjustPan">
<intent-filter>
<action android:name="com.bifit.cashdesk.mobile.views.ReceiptsActivity" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
StartActivity() Method
private void showActivity() {
Intent intent = new Intent(context, context.getClass());
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
context.startActivity(intent);
}
Aidl callback method
aidlService.cancel(new IOperationResponse.Stub() {
#Override
public void onResponse(String resultCode, String responseData, String rrn, String billJson) {
showActivity();
}
}, "com.bifit.cashdesk.mobile.views.ReceiptsActivity", rrn);
I have tried to resolve this by user-permissions, but it haven't led to success
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
It was on the side of aidl app, this app didn't close when used callback. We resolved it by closing aidl app on callback on it's side

onReceive method not called when i removed app , and i write code in right way

i add android.intent.action.PACKAGE_FULLY_REMOVED as action
and this my receiver
<receiver android:name=".MyBroadcastReceiver" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_FULLY_REMOVED"/>
<data android:scheme="package"/>
</intent-filter>
</receiver>
and my MyBroadcastReceiver here
public class MyBroadcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context,"app Removed",Toast.LENGTH_LONG).show();
Log.e("MyBroadcastReceiver","app Removed");
}
}
so i want to notify when app is removed from Device but is not working
You can't listen to android.intent.action.PACKAGE_FULLY_REMOVED/android.intent.action.PACKAGE_REMOVED on your all package because your own BroadcastReceiver is removed when your package is removed.

Unable to start receiver (Activity Not Found)

I developed an application and put that on app store. Afterwords i wanted to change the package name so i just changed the application ID in build.gradle so that it looks appropriate in link. I didn't change anything else not the package name, not the manifest file etc. Application worked fine but now it's showing an error of ActivityNotFound exception on the launcher activity which is called through a broadcast receiver although that activity is defined in manifest file. May i know where am i wrong at?
This is the manifest file coding:
<receiver android:name=".PowerConnectionReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
</intent-filter>
</receiver>
<activity
android:name=".BatteryChargerFast"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:label="#string/app_name"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
And below is the coding of broadcast Receiver:
public class PowerConnectionReceiver extends BroadcastReceiver {
private String TAG="PowerConnectionReceiver";
#Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent();
i.setClassName("packagename",
"packagename.BatteryChargerFast");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra("fast", true);
context.startActivity(i);
}
}
the error states:
java.lang.RuntimeException: Unable to start receiver
packagename.PowerConnectionReceiver:
android.content.ActivityNotFoundException: Unable to find explicit
activity class {packagename/packagename.BatteryChargerFast}; have you
declared this activity in your AndroidManifest.xml?
When you change applicationId in gradle, it overrides the Manifest's id.
so you need to change your code from:
Intent i = new Intent();
i.setClassName("packagename",
"packagename.BatteryChargerFast");
To:
Intent i = new Intent();
i.setClassName("your.new.app.id",
"packagename.BatteryChargerFast");
or may be even simpler where you don't need to consider all this:
#Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context.getApplicationContext(), BatteryChargerFast.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra("fast", true);
context.startActivity(i);
}

Android service crashing on boot

I have an android foreground service that is supposed to start running when the device boots up. At the boot the banner rolls by signaling that the service has started, however the banner does not stay in the notification bar after the initial notification runs buy. Additionally the service does not continue to run.Below is my manifest, broadcast receiver, and service.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.copyright.Going_Plaid"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED"
>
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
/>
<application
android:allowBackup="true" android:label="Going_Plaid"
android:icon="#mipmap/ic_launcher" android:theme="#style/AppTheme">
<receiver android:name="com.example.copyright.Going_Plaid.autostart">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<activity
android:name="com.example.copyright.Going_Plaid.MainActivity"
android:label="Going_Plaid">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<service
android:name="com.example.copyright.Going_Plaid.Scan"
android:exported="false"
android:enabled="true"
/>
</application>
autostart.java:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class autostart extends BroadcastReceiver {
public void onReceive(Context arg0, Intent arg1){
Intent intent = new Intent(arg0, Scan.class);
arg0.startService(intent);
Log.v("autostart", "service should be started");
}
}
Scan.java:
public IBinder onBind(Intent mServiceIntent){return null;}
#Override
public void onCreate(){
startInForeground();
notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
#Override
public int onStartCommand( Intent mServiceIntent,int flags, int startId) {
executorService.execute(new Runnable() {
Most of the code has been redacted because I did not think it was relevant. The service does run fine when started through the UI but runs into issues when starting from boot without the user manually starting it. If you need any other information I would be happy to add it. Thank you in advance for your assistance.

Home button listener in background

I want to create service (?), which would be running in the background all the time and start when system starts. Also, I want it to detect double home button press and then launch a specified activity. Is it possible?
1. When system starts you can do like this:
public class PhoneStateReceiver extends BroadcastReceiver{
#Override
public void onReceive(final Context context, Intent intent) {
if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
Intent launch = new Intent(context, ServiceToLaunch.class);
launch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startService(launch);
}
}
}
In your manifest add this:
<receiver android:name=".receiver.PhoneStateReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Add permission:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
2. There is no Home key event available.

Categories