我收到创建闹钟的意图错误

时间:2019-02-05 10:24:18

标签: java android android-intent

我将创建一个闹钟,我编写了此代码,但返回了此错误:

  

2019-02-05 10:58:13.902 2663-10077 / com.google.android.gms   E / ChromeSync:[Sync,SyncIntentOperation]处理意图时出错:   意图{act = android.intent.action.PACKAGE_ADDED   dat = package:com.example.iacopo.alarmgroup flg = 0x4000010   cmp = com.google.android.gms / .chimera.GmsIntentOperationService(具有   额外))。

我该如何解决?谢谢 而且此代码不会在时钟附近的通知面板中创建图标af警报

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(System.currentTimeMillis());
        cal.clear();
        cal.set(2018,1,5,10,0);

        AlarmManager alarmMgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(MainActivity.this, AlarmReceiver.class);
        this.startService(intent);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, intent, 0);
        alarmMgr.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
    }
}

和接收者

public class AlarmReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i("test","ok");
    }
}

0 个答案:

没有答案