Priority two apps use bootcompletedReceiver on android - android

recently I use BOOT_COMPLETED 2 app (A app, and B app)
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
A app is activity and B app is service app
when my device boot,
first A app launch and B app launch
so, show B app screen.
I want
first B app launch and A app launch showing A app screen
perhaps, Can I give BOOT_COMPLETED Priority is possible?
finally, I want when I boot my device, show A app screen
Thanks!
add
I try
B app(service)
public class BootCompletedReceiver extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED) {
Intent i = new Intent("A app package name.BOOT_COMPLETED");
context.sendBroadcast(i);
}
}
}
<receiver android:name=".BootCompletedReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
A app(activity)
public class BootSendReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context,Intent intent) {
if( intent.getAction().equals("B app packagename.BOOT_COMPLETED"));
Intent i = new Intent (context, MainActivity.class);
context.startActivity(i);
}
}
<receiver android:name=".BootSendReceiver">
<intent-filter>
<action android:name="blackeyeonandroid.iosystem.co.kr.simpleserviceexample.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
and I try boot .. but showing B app screen

I think you can not control that..
Instead, you can make APP1 start the APP2. This way, only APP1 receives the BOOT_COMPLETE message. Then, APP1 is responsible to send a new intent to start APP2:
Maybe, you can do as follows (note that APP2 does not receive android's default BOOT_COMPLETED message):
APP1
Manifest:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver android:name=".AppToStartFirstBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Receiver
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Intent i = new Intent("com.example.mytestapp.BOOT_COMPLETED");
context.sendBroadcast(i);
}
}
APP2
Manifest:
<receiver android:name=".AppToStartLaterBroadcastReceiver">
<intent-filter>
<action android:name="com.example.mytestapp.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Receiver
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("com.example.mytestapp.BOOT_COMPLETED")) {
// Do what you want in secundary APP
}
}
Note
This is an suggestion and you should adjust to your case. Since I don't have more details about your code, you may need to modify it to your case.. But you can use the idea.

Related

How to make a screen not fall asleep if the app runs on boot?

I have the app which must start on device' boot. It works well but the problem is that when the app finishes booting, the screen is already dark. How can I make it not fall asleep?
My Receiver:
<receiver
android:enabled="true"
android:exported="true"
android:name=".view.receivers.BootReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<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>
public class BootReceiver extends BroadcastReceiver {
private final static String LOG_TAG = BootReceiver.class.getSimpleName();
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Log.i(LOG_TAG, "Loading after booting...");
Intent startCalendarActivityIntent = new Intent(context, CalendarActivity.class);
startCalendarActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(startCalendarActivityIntent);
} else {
Log.e(LOG_TAG, "Error while restarting after boot.");
}
}
}
On this device is Android 6.0 .
You can either use wakelocks, which need certain permissions, or you can put a flag in your onCreate method, which according to the docs does not require a permission.
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
The wakelock documentation gave the example above.

Launch single BroadcastReceiver form another application

I created an Application that shares a BroadcastReceiver that launches a Service.
The app that holds the receiver doesn't have activities, there are the receiver class and the services.
Here are the manifest declaration:
<service
android:name=".services.PrintService"
android:enabled="true"
android:exported="true" />
<receiver
android:name=".receivers.MyReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="art.bridge.PRINT_MESSAGE" />
</intent-filter>
</receiver>
Receiver class
public class MyReceiver extends BroadcastReceiver {
public MyReceiver() {
}
#Override
public void onReceive(Context context, Intent intent) {
Log.d(ArtAppl.name , "Receiver reached");
Intent print = new Intent(context, PrintService.class);
if(intent.getStringExtra("message") != null)
print.putExtra("message",intent.getStringExtra("message"));
else
print.putExtra("message","Message not found");
context.startService(print);
}
}
Form an another app, i try to launch the receiver like following:
Intent bReceiver = new Intent("art.bridge.PRINT_MESSAGE");
sendBroadcast(bReceiver);
But the receiver doesn't run.
Am I missing something? Do I have to set another action in the manifest?
Could it be that you need to include Intent.FLAG_INCLUDE_STOPPED_PACKAGES as a flag?
See: How to Send BroadCast from one app to another app

Open Activity With Dial Code

I want to develop app that doesn't have icon launcher. The app will run alarmscheduler which triggered when app is installed or phone is rebooted.
The problem is how can I open the activity since the app doesn't have intent filter like below:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Is there a way to handle dial code such as ##4635*#*# to open the activity ?
or any other solutions are welcomed.
You can do it with two ways:
1) as answer by #KishuDroid
2) By define code in manifest
public class MySecretCodeReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals("android.provider.Telephony.SECRET_CODE")) {
Intent i = new Intent(context, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
}
In manifest file
<receiver android:name=".MySecretCodeReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SECRET_CODE" />
<data android:scheme="android_secret_code" android:host="4635" />
</intent-filter>
</receiver>
Note:
In Second method you must have to dial *#*#your_code#*#* and dont need to press call button
But in first method you can customise your prefix or postfix of code. For example *#your_code# or **your_code##. but you need to press call button.
You have to use Broadcast Receiver...
public class OutgoingCallReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if(null == bundle)
return;
String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Log.i("OutgoingCallReceiver",phonenumber);
Log.i("OutgoingCallReceiver",bundle.toString());
if(code.equals("#056700") {
intent.setComponent(new ComponentName("com.example", "com.example.yourActivity"));
And Your Android Manifest
<receiver android:name="com.varma.samples.detectcalls.receivers.OutgoingCallReceiver">
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
</intent-filter>
</receiver>
Also, include the permission:
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>

Call Broadcast Receiver from another process

In my application i have to use a BroadcastReceiver which must run in it's own process.
<receiver
android:name="com.greenroad.mobile.asimov.tiles.AsimoveTileRequestUpdateReceiver"
android:process="com.zonarsystems.Sample2020App.tile" >
<intent-filter>
<action android:name="com.zonarsystems.twenty20.tile.intent.action.TILE_REQUEST_UPDATE" />
</intent-filter>
</receiver>
The application sending data to this receiver in order to process them.
for calling this receiver the application using
Intent intent = new Intent("com.zonarsystems.twenty20.tile.intent.action.TILE_REQUEST_UPDATE");
intent.putExtras(indicationsBundle);
sendBroadcast(intent);
But i get nohing in
#Override
public void onReceive(Context context, Intent intent) { ... }
How it can be solved?
Thanks,
Eyal.

Android BroadcastReceiver in separate project

I'm developing two Android applications.
The first one calls broadcast receiver from activity.
The second one contains broadcast receiver that is called from first application.
I've manage to do broadcast call when it is in the same application with caller activity.
But when I take receiver to separate project it doesn't work. What should I change?
This is how I register receiver:
<receiver
android:name=".TestReceiver"
android:enabled="true"
android:exported="true"
android:process=":deltaFO">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="com.myapp.intent.action.FILE_OPERATION" />
</intent-filter>
</receiver>
This is how I send intent
Intent intent = new Intent("com.myapp.intent.action.FILE_OPERATION");
intent.putExtra("operation", operation);
context.sendBroadcast(intent);
This is class that receives intent:
public class TestReceiver extends BroadcastReceiver{
public final String TAG="TestReceiver";
#Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG,"EXTERNAL BROADCAST...");
}
}

Categories

Resources