我有一个BroadcastReceiver叫AlarmReceiver那个ToastS"报警工作".我试图在5:45和17:30 设置一个重复PendingIntent触发器AlarmReceiver,但是在启动应用程序几秒钟后我看到"警报工作".为什么PendingIntent立刻发送?
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Calendar cal1 = Calendar.getInstance();
cal1.set(Calendar.HOUR_OF_DAY, 05);
cal1.set(Calendar.MINUTE, 45);
cal1.set(Calendar.SECOND, 00);
Calendar cal2 = Calendar.getInstance();
cal2.set(Calendar.HOUR_OF_DAY, 17);
cal2.set(Calendar.MINUTE, 30);
cal2.set(Calendar.SECOND, 00);
Intent intent = new Intent(this, AlarmReceiver.class);
PendingIntent pi = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, cal1.getTimeInMillis(),cal2.getTimeInMillis(), pi);
Toast.makeText(this, "Alarm set", Toast.LENGTH_LONG).show();
}
}
Run Code Online (Sandbox Code Playgroud)
AlarmReceiver:
public class AlarmReceiver extends BroadcastReceiver {
public void onReceive(Context …Run Code Online (Sandbox Code Playgroud) 我需要将一个字符串数组从AlarmReceiver.class传递给Notify.class,但该字符串始终为"null".现在,AlarmReceiver中的意图是一个问题吗?
public class AlarmReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
[...]
Intent notificationIntent = new Intent("com.example.myapp", null, context, Notify.class);
notificationIntent.putExtra("notify", not1[x]);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
Run Code Online (Sandbox Code Playgroud)
通知课程:
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Intent notificationIntent = getIntent();
String[] message = notificationIntent.getStringArrayExtra("notify");
Toast toast6=Toast.makeText(this,""+message,Toast.LENGTH_LONG);
toast6.show();
Run Code Online (Sandbox Code Playgroud) 我需要检查一个值并以编程方式启用或禁用"checkboxpreference".我使用此代码,但getPreferenceScreen()想要一个方法,我不知道使用哪种方法.(我在android 2.1上使用它).
<CheckBoxPreference
android:enabled="true"
android:title="Now"
android:defaultValue="false"
android:key="keep" />
protected void check(){
// read values
if (values){
getPreferenceScreen().findPreference("checkbox-preference-key").setEnabled(true);
}
else {
getPreferenceScreen().findPreference("checkbox-preference-key").setEnabled(false);
Run Code Online (Sandbox Code Playgroud) 我需要检查android的版本并使用if运行一个或其他alertdialog.使用此代码,如果不共享,"构建器"最后一个.什么是最好的方法呢?
我的代码:
int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk < android.os.Build.VERSION_CODES. HONEYCOMB)
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
}
else if (sdk >= android.os.Build.VERSION_CODES. HONEYCOMB)
{
AlertDialog.Builder builder = new AlertDialog.Builder(this, animazione);
}
builder.setView(view).create();
TextView text=(TextView) findViewById(R.id.infoView1);
builder.setCancelable(false);
builder.setPositiveButton("Chiudi", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
tips = 0;
dialog.cancel();
}
});
builder.show();
}
Run Code Online (Sandbox Code Playgroud) 我需要创建一个脚本来以编程方式为不同用户设置 sasldb 密码:
#!/bin/bash
passwd=test
saslpasswd -c -u domain.org user0
Run Code Online (Sandbox Code Playgroud)
如何将$passwd变量传递给该脚本?
关于密码的唯一选项是:
-p Pipe mode- saslpasswd2 既不会提示输入密码,也不会验证输入是否正确。当标准输入不是终端时,这是默认值。
我刚刚发现这个代码只在android 2.x上崩溃我的应用程序
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(textView1.getText());
Run Code Online (Sandbox Code Playgroud)
我想...我需要在运行此方法之前添加检查android版本,这是允许在Android 2.x上运行的正确代码吗?
谢谢!