如何启动我的应用程序当过手机重新启动或开启 [英] how to start my application when ever mobile restart or turn on

查看:169
本文介绍了如何启动我的应用程序当过手机重新启动或开启的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置我的应用程序,启动应用程序,所以当移动过断电或重新启动,我的应用程序启动。

 < XML版本=1.0编码=UTF-8&GT?;
 <舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
 包=com.example.installedapps22
 安卓版code =1
 机器人:VERSIONNAME =1.0>

 <用途-SDK
    安卓的minSdkVersion =8
    机器人:targetSdkVersion =8/>

 <应用机器人:图标=@可绘制/ cherry_icon机器人:标签=@字符串/ APP_NAME>
    <活动机器人:名称=。MainActivity
              机器人:标签=@字符串/ APP_NAME>
        <意向滤光器>
            <作用机器人:名称=android.intent.action.MAIN/>
            <类机器人:名称=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>
    < /活性GT;
<活动机器人:ListInstalledAppsNAME => < /活性GT;


<活动机器人:TabsLayoutActivityNAME = />
< /用途>
   < /舱单>
 

修改这是我更新code和它仍然没有工作:

清单:

 < XML版本=1.0编码=UTF-8&GT?;

 <舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
 包=com.example.installedapps22
安卓版code =1
 机器人:VERSIONNAME =1.0>

 <用途-SDK
    安卓的minSdkVersion =8
    机器人:targetSdkVersion =8/>
    <使用-权限的Andr​​oid:名称=android.permission.RECEIVE_BOOT_COMPLETED/>
 <应用机器人:图标=@可绘制/ cherry_icon机器人:标签=@字符串/ APP_NAME>
    <活动机器人:名称=。MainActivity
              机器人:标签=@字符串/ APP_NAME>
        <意向滤光器>
            <作用机器人:名称=android.intent.action.MAIN/>
            <类机器人:名称=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>
    < /活性GT;


    <接收器的android:启用=真正的机器人:NAME =com.app.reciever.BootU preciever>
  <意向滤光器>
        <作用机器人:名称=android.intent.action.BOOT_COMPLETED/>
        <类机器人:名称=android.intent.category.DEFAULT/>
  &所述; /意图滤光器>
 < /接收器>
  <活动机器人:ListInstalledAppsNAME => < /活性GT;


  <活动机器人:TabsLayoutActivityNAME = />
  < /用途>
 < /舱单>
 

BroadcastReciever:

 包com.example.installedapps22;
 公共类BootU preciever延伸的BroadcastReceiver
 {

    @覆盖
    公共无效的onReceive(最终上下文的背景下,意图意图){
        意图I =新的意图(背景下,MainActivity.class);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(ⅰ);
    }
 }
 

解决方案

这是设置应用程序在你的设备的启动应用程序创建一个类继承广播Reciever

 公共类BootU preciever延伸的BroadcastReceiver
{

@覆盖
公共无效的onReceive(最终上下文的背景下,意图意图){
        意图I =新的意图(背景下,服务器preferenceActivity.class);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(ⅰ);
}
}
 

添加权限清单文件访问启动接收器

 <使用-权限的Andr​​oid:名称=android.permission.RECEIVE_BOOT_COMPLETED/>
 

填写您的接收器,它扩展了广播接收器中的manifest.xml

 <接收器的android:启用=真正的机器人:NAME =com.app.reciever.BootU preciever>
    <意向滤光器>
            <作用机器人:名称=android.intent.action.BOOT_COMPLETED/>
            <类机器人:名称=android.intent.category.DEFAULT/>
    &所述; /意图滤光器>
< /接收器>
 

How do i set my application as startup application, so when ever mobile restarts or turned ON, my application starts.

  <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.example.installedapps22"
 android:versionCode="1"
 android:versionName="1.0" >

 <uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="8" />

 <application android:icon="@drawable/cherry_icon" android:label="@string/app_name">
    <activity android:name=".MainActivity"
              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=".ListInstalledApps" > </activity> 


<activity android:name=".TabsLayoutActivity" />
</application>
   </manifest>

EDIT Here is my updated code and it is still not working:

Manifest:

 <?xml version="1.0" encoding="utf-8"?>

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.example.installedapps22"
android:versionCode="1"
 android:versionName="1.0" >

 <uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="8" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
 <application android:icon="@drawable/cherry_icon" android:label="@string/app_name">
    <activity android:name=".MainActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>


    <receiver android:enabled="true" android:name="com.app.reciever.BootUpReciever">
  <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
        <category android:name="android.intent.category.DEFAULT" />
  </intent-filter>
 </receiver>
  <activity android:name=".ListInstalledApps" > </activity> 


  <activity android:name=".TabsLayoutActivity" />
  </application>
 </manifest>

BroadcastReciever:

 package com.example.installedapps22; 
 public class BootUpReciever extends BroadcastReceiver
 {

    @Override
    public void onReceive(final Context context, Intent intent) {
        Intent i = new Intent(context, MainActivity.class);  
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
    }
 }

解决方案

This is to set the app as the startup application in your device Create a Class extends BroadCast Reciever

public class BootUpReciever extends BroadcastReceiver
{

@Override
public void onReceive(final Context context, Intent intent) {
        Intent i = new Intent(context, ServerPreferenceActivity.class);  
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
}
}

Add permissions to manifest file to access bootup receiver

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

Register your receiver which extended the Broadcast receiver in manifest.xml

<receiver android:enabled="true" android:name="com.app.reciever.BootUpReciever">
    <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</receiver>

这篇关于如何启动我的应用程序当过手机重新启动或开启的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆