2016-08-15 72 views
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(); 
    } 
} 

回答

0

在哪个设备你测试?代码似乎没问题。对于多个动作,你可以使用这个,来指定个人动作

@Override 
public void onReceive(Context context, Intent intent) { 
    String action = intent.getAction(); 
    if(action != null) { 
     if(action.equals("action1") { 
      // CODE 
     } else if (action.equals("action2") { 
      // CODE 
     } 
    } 
} 
+0

我被测试TECHNO C8 –

+0

感谢您的回答,但问题是没有收到重新启动。我添加警报(吐司),但不显示。 –

+0

我想在处理某个操作之前先收到警报。这是接着启动正在工作 –