gpt4 book ai didi

android - Boot 上的 Launch Activity 已完成,Mount 上的另一个 Activity 已完成

转载 作者:行者123 更新时间:2023-11-30 03:17:19 28 4
gpt4 key购买 nike

这是我的 Androidmanifest.xml

      <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.abc.testapp"
android:versionCode="1"
android:versionName="Pm61" >
<uses-sdk android:minSdkVersion="15"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<supports-screens android:anyDensity="true" />

<application android:label="@string/app_name" android:debuggable="true" android:largeHeap="true">

<activity android:name="com.abc.testapp.MainClass" android:label="@string/app_name" android:theme="@android:style/Theme.Translucent" android:hardwareAccelerated="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

.
.
.
.
.
.
<activity android:name="com.abc.testapp.BootLoad"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
</activity>

<activity android:name="com.abc.testapp.Rxmain" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" android:launchMode="singleTask">
</activity>

<receiver android:name="com.abc.testapp.MyReceiver" android:enabled="true">
<intent-filter android:priority="500">
<action android:name= "android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.MEDIA_MOUNTED"/>
<data android:scheme="file" />
</intent-filter>
</receiver>

</application>

</manifest>

这是我用于广播的 MyReceiver 类

      package com.abc.testapp;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class MyReceiver extends BroadcastReceiver
{

@Override
public void onReceive(Context context, Intent intent)
{
String action = intent.getAction();

if(Intent.ACTION_MEDIA_MOUNTED.equals(action))
{
Log.d("MYReceiver","Mounting Successfull");
Intent serviceActivity = new Intent(context, Rxmain.class);
serviceActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(serviceActivity);
}

if(Intent.ACTION_BOOT_COMPLETED.equals(action))
{
Log.d("MYReceiver","Boot Successfull");
Intent serviceActivity = new Intent(context, BootLoad.class);
serviceActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(serviceActivity);
}
}
}

我的设备是独立设备,只有我的应用程序会启动。

我希望在启动完成时启动 BootLoad Activity ,并在 MEDIA_MOUNTED 之后启动 Rxmain Activity 。

但是我的 bootLoad Activity 没有出现

所以我对此有些疑惑:

  1. 它有时有效但有时无效?

2.Intent-filter 中的优先级是什么?

  1. 这个数据方案是做什么的?

  2. 我这样做对不对?

请推荐我

最佳答案

问题在于您为广播接收器定义 Intent 过滤器的方式。这是你的定义:

<receiver  android:name="com.abc.testapp.MyReceiver" android:enabled="true">
<intent-filter android:priority="500">
<action android:name= "android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.MEDIA_MOUNTED"/>
<data android:scheme="file" />
</intent-filter>
</receiver>

您已经定义了一个单独的 Intent 过滤器,如果 ACTION 是 BOOT_COMPLETED 将被触发。或 MEDIA_MOUNTED .但是,通过指定 <data>标记,您将只会收到具有data with scheme=file 的广播 Intent。

BOOT_COMPLETED Intent 没有任何数据,所以你的接收者不会得到它。

您需要指定 2 个单独的 Intent 过滤器,如下所示:

<receiver  android:name="com.abc.testapp.MyReceiver" android:enabled="true">
<intent-filter android:priority="500">
<action android:name= "android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
<intent-filter android:priority="500">
<action android:name="android.intent.action.MEDIA_MOUNTED"/>
<data android:scheme="file" />
</intent-filter>
</receiver>

关于android - Boot 上的 Launch Activity 已完成,Mount 上的另一个 Activity 已完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19808702/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com