i want "start in Background" permission for open incoming and outgoing call screen when app close.
public class CallReciver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Log.e("onReceive","=========>>>>");
//start activity
Intent i = new Intent(context.getApplicationContext(), OngoingCallActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addCategory(Intent.CATEGORY_LAUNCHER);
context.startActivity(i);
}
}
receiver is opening incoming or outgoing UI screen.but receiver is able to open activity when app in foreground. onReceive method call but receiver not able to open activity when app in background, i try lot's of solution for that but nothing to work.
when manually allow start in background permission it work fine.
so,how to allow start in background permission in MIUI software.Please help me i spend lot's of day for that.sorry for bad english and thanks in advance.
For MI device follow below steps
Intent localIntent = new Intent("miui.intent.action.APP_PERM_EDITOR");
localIntent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.PermissionsEditorActivity");
localIntent.putExtra("extra_pkgname", getPackageName());
startActivity(localIntent);
Related
I'm trying to create an autorun service: so that the application launches every time after unlocking the screen, after entering the graphic key or password if it exists (on Android 7,8,9,10). I wrote the code dynamically through the borocast receiver (ACTION_SCREEN_OFF) but it works while the application is on the stack (running) and I want it to always start. The method through registering in the manifest in android 9 already does not work the listeners. How to implement this?
public class WordsBase extends AppCompatActivity {
ScreenReceiver resiverStart;
#Override
protected void onPause() {
super.onPause();
resiverStart= new ScreenReceiver();
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
registerReceiver(resiverStart,filter);
}
}
public class ScreenReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
Intent intent1 = new Intent(context, WordsBase.class);
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent1);
}
throw new UnsupportedOperationException("Not yet implemented");
}
}
I understand that you want to do the following:
If the user unlocks the device, you want to start your app.
Why don't you do the following:
Use the USER_PRESENT receiver (android.intent.action.USER_PRESENT). Please not that you have to register explicitly to this receiver, just registering it in the manifest is not enough
If the respective broadcast is fired, start your app and make sure you are still registered to the broadcast (to have your app started again the next time the user unlocks the device).
I need to make an alarm app that opens on a custom selected time (comes forward on the screen even if the app is closed ). Using alarm manager/ broadcast receiver i managed to show notification , but not to start the app.
You can start any activity like this from broadcast receiver:
public class Example extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context, Main.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
My application only have MainActivity with a ImageView.
BroadcastReceiver works. The Toast Message is displayed When I connect USB.
Now, I need start my application minimized and show the application only the USB cable was connected.
BroadcastReceiver broadcast_reciever = new BroadcastReceiver() {
#Override
public void onReceive(Context arg0, Intent intent) {
String action = intent.getAction();
if (action.equals("usb_detect")) {
Toast.makeText(arg0,"Atenção!",Toast.LENGTH_SHORT).show();
finish();
startActivity(getIntent());
//startActivity(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER));
}
}
};
Manifest is here: https://i.stack.imgur.com/sa3Pe.jpg
To bring your application to the foreground, add the following to onReceive():
Intent launchIntent = getPackageManager().
getLaunchIntentForPackage("your.package.name");
startActivity(launchIntent);
This will not start a new Activity, it will simply bring the existing task containing your application to the foreground in whatever state it was in when it got moved to the background.
Also, remove the call to finish() from your BroadcastReceiver. finish() is only used on an Activity.
I have an application that using "AlarmService". For handling alarms i have a Broadcast receiver. That receiver has to start certain activity. Code i'm using for achieving that is following:
#Override
public void onReceive(Context context, Intent intent) {
...other code....
Intent intIntent = new Intent(context, MainActivity.class);
intIntent .putExtra("IsAlarm", true);
Intent alarmChooser = Intent.createChooser(intIntent , "Alarm");
alarmChooser.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(alarmChooser);
}
That works but only if activity isn't shown already (if it's not in the foreground). If called activity is already opened nothing happens. How can i overcome that?
Is there a flag that will start the activity if it's not started OR send intent to it even if it's in the foreground?
P.S. i tried using dedicated "broadcast" above the provided code. Reciever for that broadcast is registered programmatically in the MainActivity: "onResume" would register dedicated receiver, "onPause" would unregister it. That way in case MainActivity is already on it will receive a broadcast but then i have a problem when phone goes to "stand by" - "dedicated" receiver is unregistered.
Check in the activity onNewIntent callback
there should be the new intent from the receiver
I think you don't need the chooser:
#Override
public void onReceive(Context context, Intent intent) {
Intent intIntent = new Intent(context, MainActivity.class);
intIntent.putExtra("IsAlarm", true);
context.startActivity(intIntent);
}
I need to launch/open one installed apk in my device from a BroadcastReceiver.
Here is the code:
public class C2DMMessageReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.w("C2DM", "Message Receiver called");
if ("com.google.android.c2dm.intent.RECEIVE".equals(action)) {
Log.w("C2DM", "Received message");
ComponentName toLaunch = new ComponentName("es.mypackage","es.mypackage.myapplication");
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(toLaunch);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(intent);
My device receives the broadcast but fails with an unexpected problem.
The code to launch other apk works fine in other part of the application.
Is possible to launch other application from a broadcast?
Thank you very much.
As per my experience , you can not start activity from the C2DM Receiver, I found work around for that, Create one service and start activity from that service, stop service after you start the activity.
Thank You,