带有contentprovider的接收器

时间:2014-05-22 10:47:11

标签: android android-contentprovider

MainActivity

public class SetTheTime extends Activity {

private TimePickerDialog timePickerDialog1;
int hour;
int min;
private TextView textView01;
private Button button01;
OnClickListener listener_set = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_set_the_time);

    GregorianCalendar calendar = new GregorianCalendar();
    textView01 = (TextView)findViewById(R.id.TextView01);
    timePickerDialog1 = new TimePickerDialog(this, new OnTimeSetListener() {    
        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
            hour=hourOfDay;
            min=minute;
            textView01.setText(hourOfDay+":"+minute);
            Calendar mCal = Calendar.getInstance();
            //mCal.set(Calendar.HOUR_OF_DAY, hour);
           // mCal.set(Calendar.MINUTE, min);
            mCal.add(Calendar.SECOND, 15);
            Intent intent = new Intent(SetTheTime.this, PlayReceiver.class);
            intent.putExtra("msg", "play_music");
            PendingIntent pi = PendingIntent.getBroadcast(SetTheTime.this, 1, intent, PendingIntent.FLAG_ONE_SHOT);       
            AlarmManager am = (AlarmManager) getSystemService(SetTheTime.this.ALARM_SERVICE);
            am.set(AlarmManager.RTC_WAKEUP, mCal.getTimeInMillis(), pi);
        }       
    }, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), false);

    listener_set = new OnClickListener(){
        public void  onClick(View v){
            timePickerDialog1.show();
        }
    };

    button01 = (Button)findViewById(R.id.Button01);
    button01.setOnClickListener(listener_set);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.set_the_time, menu);
    return true;
}

}

接收机     公共类PlayReceiver扩展BroadcastReceiver {     @覆盖     public void onReceive(Context context,Intent intent)     {         Bundle bData = intent.getExtras();         getIntent().setData(Uri.parse("内容://com.example.brainclock"));     final Uri uri_test = getIntent()。getData();     } }

我尝试使用内容提供程序在Receiver上保存数据,但它不起作用!

有没有解决这个问题的方案?

0 个答案:

没有答案