0
我想在设备启动时开始一项活动。Android - 无法在设备启动时自动启动活动?
Stranege的事情是,我的代码在仿真器上工作,但不是在实际设备上。
我有一个名为preferences.xml的文件,它有一个CheckBoxPreference来设置自动启动和关闭。
这里是我的代码: -
public class AutoStartUp extends BroadcastReceiver
{
private static final String TAG = "AutoStartUp";
public void onReceive(Context context, Intent intent)
{
String action = intent.getAction();
if(action.equals(Intent.ACTION_BOOT_COMPLETED))
{
SharedPreferences sp = context.getSharedPreferences("preferences", 0);
if(sp.getBoolean("autostartup", false))
{
Log.e(TAG, "I AM HERE");
Intent startupIntent = new Intent(context, CompleteTaskManager.class);
context.startActivity(startupIntent);
}
}
}
}
这里是我的这个接收器清单部分: -
<receiver android:name=".AutoStartUp" android:enabled="true" android:exported="false" android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
请帮助!
吉姆,你的答案是不对的,但我仍接受它,因为至少你试图帮助我。谢谢 :) – Varundroid 2011-06-20 17:02:16