【问题标题】:App shouldnt start at Bootup BUT starting应用程序不应该在启动时启动,而是启动
【发布时间】:2014-10-05 09:13:37
【问题描述】:

我有这个设备管理员特权应用程序和一些广播公司(我正在适当的时间注册和取消注册!),问题是我的应用程序在设备启动时启动,我没有任何过滤意图这个意图并让我的应用程序启动! ,请看AndroidManifest.xml如下:

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

<!--uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /-->
<uses-sdk
    android:minSdkVersion="16"
    android:targetSdkVersion="19" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/Fullscreen" >

    <activity
        android:name="com.winacro.xyz.SplashScreen"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@style/Fullscreen" >

    </activity>

    <activity
        android:name="com.winacro.xyz.Boot"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@style/Fullscreen" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

    </activity>

    <activity
        android:name="com.winacro.xyz.Xyz"
        android:screenOrientation="portrait"
        android:theme="@style/Fullscreen"
        android:label="@string/app_name" />

    <activity
        android:name="com.winacro.xyz.Locked"
        android:screenOrientation="portrait"
        android:theme="@style/Fullscreen"
        android:label="@string/app_name" />


    <service
        android:name="com.winacro.xyz.xyzService"
        android:enabled="true" > 

    </service>

    <receiver android:name="com.winacro.xyz.MyBroadcastReceiver" >
        <intent-filter>
            <action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
        </intent-filter>

        <meta-data
            android:name="android.hardware.usb.action.USB_DEVICE_DETACHED"
            android:resource="@xml/device_filter" />
    </receiver>

     <receiver android:name="com.winacro.xyz.activateSERVICE" >
        <intent-filter>
            <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
        </intent-filter>

        <meta-data
            android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
            android:resource="@xml/device_filter" />
    </receiver>

    <!-- Device Admin Receiver -->
    <receiver
        android:name="com.winacro.xyz.DeviceAdminR"
        android:permission="android.permission.BIND_DEVICE_ADMIN" >
        <intent-filter>

            <!-- This action is required -->
            <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
        </intent-filter>

        <!-- This is required this receiver to become device admin component. -->
        <meta-data
            android:name="android.app.device_admin"
            android:resource="@xml/policies" />
    </receiver>

</application>

如您所见,我在清单中注释了 RECEIVE_BOOT_COMPLETED,因此它应该将引导事件路由到我,但我的应用程序仍然从 activateSERVICE.java 启动,如下所示:

public class activateSERVICE extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    Toast.makeText(context, "Boolean Set True", Toast.LENGTH_SHORT).show();
    //Intent startActSerIntent = new Intent(context, Boot.class);
    Intent i = new Intent();
    i.setClassName("com.winacro.xyz", "com.winacro.xyz.Boot");
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    Intent startService = new Intent(context, xyzService.class);
    context.startService(startService);
    context.startActivity(i);
    //context.startActivity(startActSerIntent);
    xyzService.USBpluggedIn = true;
}

}

请告诉我为什么我的应用程序启动?(我确认我的应用程序从 activateSERVICE 启动是因为只有此代码设置变量 USBpluggedIn = true;并且仅当设置了我的应用程序启动 xyzService。正在开始的课程。)

【问题讨论】:

    标签: android android-intent android-service


    【解决方案1】:

    您正在接收 android.hardware.usb.action.USB_DEVICE_ATTACHED 广播,因为某些 USB 设备在启动时连接到设备。

    【讨论】:

    • 不,它仍然会弹出,即使没有连接任何 USB 设备,解决方案也不是那么容易。
    • 您查看过日志吗?并检查传递给接收器的 Intent,这应该包含有关触发广播的信息。
    • 是的,但也许我会再次关注日志,问题是当手机启动并且应用程序在启动时立即打开时会发生这种情况,并且到那时 ADB 还没有被激活所以可以' t 使用 LOGCAT!
    • 意图包含什么?
    • 我明白了。如果所有其他方法都失败了,请在您的 onreceive 中创建一个纯文件并在那里写入您的信息。然后你可以稍后拉这个文件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-12
    • 1970-01-01
    • 2016-08-05
    • 2014-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多