0
我在開機時開發了一個啓動應用程序,我從網絡上獲取了一些代碼,但仍未成功。此代碼似乎在模擬器,Bluestacks和Android版本5.1中工作,但不適用於Android 5.0.2版本。 我不知道我的錯誤,請任何人幫助我。 這是我的代碼。清單 // // boot_completed上的自動啓動服務
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.darcity.justshop"
android:allowBackup="true"
android:hardwareAccelerated="false"
android:icon="@drawable/darcity_logo"
android:label="@string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/darcity_logo1"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<service
android:name=".index.notify.ChatService"
android:enabled="true"
android:exported="true" />
<receiver
android:name=".index.notify.BroadcastReceiverNew"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.SCREEN_OFF" />
<action android:name="android.intent.action.SCREEN_ON" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<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=".index.Index"
android:label="@string/title_activity_index" />
<activity
android:name=".index.category.FirstCategory"
android:label="@string/title_activity_first_category" />
<activity
android:name=".index.details.Details"
android:label="@string/title_activity_details" />
<activity
android:name=".index.full.Full"
android:label="@string/title_activity_full" />
<activity
android:name=".messages.chating.Messages"
android:label="" />
<activity
android:name=".messages.setting.MessageSetting"
android:label="@string/title_activity_message_setting" />
<activity
android:name=".messages.users.Users"
android:label="@string/title_activity_users" />
<activity
android:name=".messages.customers.Customers"
android:label="@string/title_activity_customers" />
<activity
android:name=".messages.MessageBody"
android:label="@string/title_activity_message_body" />
<activity
android:name=".index.search.Search"
android:label="@string/title_activity_search" />
<activity
android:name=".Website"
android:label="@string/title_activity_website" />
<activity
android:name=".crop.CropActivity"
android:label="@string/title_activity_crop" />
<activity
android:name=".crop.lib.CropImageActivity"
android:label="@string/title_activity_crop" />
</application>
</manifest>
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
import android.widget.Toast;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
import net.darcity.justshop.net.utils.Module;
public class BroadcastReceiverNew extends BroadcastReceiver {
public BroadcastReceiverNew() {
}
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Boot completed", Toast.LENGTH_LONG).show();
}
}
我被測試TECHNO C8 –
感謝您的回答,但問題是沒有收到重新啓動。我添加警報(吐司),但不顯示。 –
我想在處理某個操作之前先收到警報。這是接着啓動正在工作 –