I want my Android Application to Launch Automatically when My Mi 4 A TV Boots Up - java

I am trying to build a android app that will launch automatically when android MI 4A TV Boots Up
I'm using this in AndroidMenifest.xml
ANODROIDMENIFEST.XML
<receiver android:name=".StartActivityOnBoot">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
</intent-filter>
</receiver>
java file
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class StartActivityOnBoot extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if(Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction()))
{
Intent i =new Intent(context,MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
}

Related

Can i create apk to send command or activity?

I'm really new with java but was playing a little around in Android Studio and have create a small app (my own Launcher).
My Question:
On Andorid OS - In terminal i use this command to deactive the Installed Launcher
pm disable com.android.launcher3
Is it possible, to create an App that can do the same?
I need that app on system startup. I can only use my own launcher after i have deactive the launcher3.
I have put this code inside my apk i have created. But the launcher i will disable still working. What did i wrong?
Have i to create a new app with this code:
Process su = Runtime.getRuntime().exec("pm ...your cmd");
su.waitFor();
or can i integrate this code inside my own app like i tried?
This is my MainActivity.xnml
package com.example.max.col2boot;
import android.Manifest;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
public void openCOL(View view) {
Intent openCOLapp = getPackageManager().getLaunchIntentForPackage("com.igg.clashoflords2"); //open col2
startActivity(openCOLapp);
moveTaskToBack(true);
}
public void openCOLapp() {
this.finish(); //exit app col2 to start game
}
public void exitCOL(View view) {
moveTaskToBack(true);
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1); //close app col2boot
}
private void runShellCommand(String command) throws Exception {
Process process = Runtime.getRuntime().exec("pm disable com.android.launcher3"); //disable Launcher3
process.waitFor();
}
}
This is my Android Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.max.col2boot">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<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" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<receiver
android:name=".BootReceiver"
android:enabled="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
</manifest>
This is my BootReceiver.java
package com.example.max.col2boot;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class BootReceiver extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
To start your activity on start, you can place a receiver in your Manifest (there are other questions how to launch your app on system start).
To execute a shell command, just use
Process su = Runtime.getRuntime().exec("pm ...your cmd");
su.waitFor();

Start App when Android Start

AndroidManifest.xml
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
{...}
<receiver
android:enabled="true"
android:exported="true"
android:name="com.example.richard.Test.StartMyServiceAtBootReciever"
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>
{...}
StartMyServiceAtBootReciever.java
package com.example.richard.Test;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
/**
* Created by Richard on 23/03/2016.
*/
public class StartMyServiceAtBootReciever extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Intent serviceIntent = new Intent(context, MainActivity.class);
serviceIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startService(serviceIntent);
}
}
}
Details: When I restart the phone, the App don't start together. Someone can help me, please?
If you're going to start an Activity then use
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Intent serviceIntent = new Intent(context, MainActivity.class);
serviceIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(serviceIntent);
}

Application android start without icon [closed]

I want to build a application in android and it is not started by clicking the icon but by type ##8888## from numpad of the Phone. I read and follow this tutorial but I don't know how to implement class Launch. Can you help me?
First Create a DialerReceiver extends BroadcastReceiver
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class DialerReceiver extends BroadcastReceiver {
String dialedno;
#Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
dialedno=arg1.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
if(dialedno.equals("##8888##"))
{
Intent callConnekt=new Intent(arg0, YourActivity.class);
callConnekt.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
arg0.startActivity(callConnekt);
setResultData(null);//To Close USSD Dialing
}
}
}
Register the DialerReceiver inside Manifest file
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<receiver android:name="DialerReceiver" android:exported="true" android:enabled="true" >
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
If you don't want show App icon in Launcher then remove below line
<category android:name="android.intent.category.LAUNCHER" />

Android app crashes on boot

I am new to Eclipse and Java development and I am trying to start an activity on boot. I've read multiple threads discussing this topic and while I have managed to start the application on boot, it crashes.
This is my code:
AndroidManifest.xml :
<!--
Below the <manifest> opening tag:
-->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<!--
Inside the <application> tag:
-->
<receiver android:name="com.example.Autostart">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name="com.example.service" android:enabled="true" />
Autostart.java :
package com.example;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class Autostart extends BroadcastReceiver{
#Override
public void onReceive(Context arg0, Intent arg1)
{
Intent intent = new Intent(arg0, service.class);
arg0.startService(intent);
}
}
service.java :
package com.example;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.widget.Toast;
public class service extends Service{
#Override
public IBinder onBind(Intent arg0) {
return null;
}
#Override
public void onStart(Intent intent, int startid)
{
Intent intents = new Intent(getBaseContext(),checker.class);
intents.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intents);
Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
}
}
My checker class has an OnCreate function which alters some settings values.
The only thing that I see when I start my phone is that "YourAppName has stopped working", which means that the application has crashed. I do not see any Toast message.
When I normally open my application and I read the settings that ought to be written on startup, nothing is there.
Change like this in your manifest and try it:
<receiver android:enabled="true" android:name=".Autostart"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
The problem was that I hadn't declared my activity to the manifest file.

Start Flex Mobile Application on Android startup

I am having an issue to start the application on android startup, the problem is how to put the listeners on the "android.permission.RECEIVE_BOOT_COMPLETED" from the manifest ( on the mobile application project from Flash builder) to the native extension ??
basically on the manifest I have something like this :
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application>
<receiver android:enabled="true" android:name="EXTENSION_PACKAGE.application.receivers.ApplicationStartupReceiver" android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
And on the native side : the listener should be like :
package EXTENSION_PACKAGE;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREObject;
public class ApplicationStartupReceiver extends BroadcastReceiver implements FREFunction {
#Override
public void onReceive(Context context, Intent intent) {
if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
Intent serviceIntent = new Intent("com.myapp.MySystemService");
context.startService(serviceIntent);
}
}
#Override
public FREObject call(FREContext arg0, FREObject[] arg1) {
// TODO Auto-generated method stub
return null;
}
}
My questions are :
The "EXTENSION_PACKAGE" is the package name from the native project or the extension id ?
The ".application" refers to the application or I don't need it ?
I hope that you understand this situation and Thank you in advance.
-----------------------------------------EDIT----------------------------------------
After few attempts and tests, I have changed these values :
<receiver android:enabled="true" android:name="NATIVEPROJECTPACKAGE.application.receiver.ApplicationStartupReceiver" android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
And :
Intent serviceIntent = new Intent("air.APPLICATION_ID"); // from the APPLICATION.XML
and now it seems to work, the only problem now, is that it crashes on the android startup, I recieve an alert saying : "Unfortunately the application 'APPLICATION NAME' has stopped"
And of course, if I launch the application, it works, ...
Firstly just double check that you're using the correct package names as you've got the package listed as EXTENSION_PACKAGE but then add application.receivers to the definition in your manifest. It probably should read like the following:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application>
<receiver android:enabled="true" android:name="EXTENSION_PACKAGE.ApplicationStartupReceiver" android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
Now when the receiver is called I'm assuming you want to simply start your AIR application? To do this is a little more complex than just creating an Intent with the actions you are specifying. Android hasn't got way of handling the actions you are calling. What you need to do is find your application entry from the context and start an intent with that, as below:
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction()))
{
String componentName = context.getPackageName() + "/.AppEntry";
Intent i = new Intent( Intent.ACTION_MAIN );
i.setComponent(ComponentName.unflattenFromString( componentName ));
i.addCategory( Intent.CATEGORY_LAUNCHER );
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity( i );
}

Resources