相关疑难解决方法(0)

系统重启后,在广播接收器中显示警告对话框

美好的一天,我试图在广播接收器中重新启动系统后显示一个警告对话框.我在清单中添加了接收器并调用了所需的权限,但在显示对话框时出错.请问我怎样才能正确实现这一点?...谢谢

我的代码:

public void onReceive(final Context context, Intent intent) {
    Log.d(TAG, "received boot completed broadcast receiver... starting settings");


    String settings = context.getResources().getString(R.string.restart_setting);
        String yes = context.getResources().getString(R.string.Settings);
        String no = context.getResources().getString(R.string.Cancel);

              final AlertDialog.Builder builder = new AlertDialog.Builder(context);
                builder.setMessage(settings)
                       .setCancelable(false)
                       .setPositiveButton(yes, new DialogInterface.OnClickListener() {
    public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id) 
   Intent config = new Intent(context, WeatherConfigure.class)
     context.startActivity(config);

    }
 })
    .setNegativeButton(no, new DialogInterface.OnClickListener() {
        public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
             dialog.cancel();
        }
    });
  final AlertDialog …
Run Code Online (Sandbox Code Playgroud)

android

31
推荐指数
4
解决办法
7万
查看次数

BroadcastReceiver中的AlertDialog ?? 可以吗?

BroadcastReceiver中的AlertDialog?可以吗?我正在开发一个应用程序,如果我收到短信,会弹出一个对话框.我试图在BroadcaseReceiver中编写代码.但我不能使用这行代码AlertDialog.Builder builder = new AlertDialog.Builder(this);.有人可以帮我提示一下!

public class SMSPopUpReceiver extends BroadcastReceiver {

    private static final String LOG_TAG = "SMSReceiver";
    public static final int NOTIFICATION_ID_RECEIVED = 0x1221;
    static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";

    public void onReceive(Context context, Intent intent) {
        Log.i(LOG_TAG, "onReceive");

        if (intent.getAction().equals(SMSPopUpReceiver.ACTION)) {
            StringBuilder sb = new StringBuilder();
            Bundle bundle = intent.getExtras();
            if (bundle != null) {
            Object[] pdus = (Object[]) bundle.get("pdus");

            for (Object pdu : pdus){
                    SmsMessage messages =
            SmsMessage.createFromPdu((byte[]) pdu);

            sb.append("Received SMS\nFrom: ");
            sb.append(messages.getDisplayOriginatingAddress());
            sb.append("\n----Message----\n");
            sb.append( …
Run Code Online (Sandbox Code Playgroud)

java android broadcastreceiver android-alertdialog

9
推荐指数
3
解决办法
2万
查看次数

如何从BroadcastReceiver类引发警报对话框?

我在Activity课堂上使用过计时器方法.在那个方法中,我有一个从Activity类到BroadcastReceiver类的意图.

BroadcastReceiver课程将使用后台每15分钟拨打一次AlarmManager.

当我打电话给BroadcastReceiver课时,我想提出一个AlertDialog.

public void timerMethod(){
    Intent intent = new Intent(Activity.this,
      BroadcastReceiverClass.class
    );

    PendingIntent sender = PendingIntent.getBroadcast(
      QualityCallActivity.this,0, intent, 0
    );

    // We want the alarm to go off 30 seconds from now.
    long firstTime = SystemClock.elapsedRealtime();

    AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
    am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
    firstTime, 60*1000, sender);
}
Run Code Online (Sandbox Code Playgroud)

BroadcastReceiverClass.java

public void onReceive(Context context, Intent intent)
{
    dialogMethod();
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能提高一个AlertDialogBroadcastReceiver类从后台进程?

android broadcastreceiver

4
推荐指数
2
解决办法
1万
查看次数

如何从Android广播接收器显示对话框?

理想情况下,我不想开展活动来做到这一点.当WiFi连接丢失时,我的应用程序需要关闭,因为这对我们来说是一个致命的错误.我想显示一条错误消息,让用户按下确定按钮,然后退出应用程序.最好的方法是什么?

谢谢!

android broadcastreceiver

3
推荐指数
1
解决办法
1万
查看次数

如何从BroadcastReceiver设置Alertbox

我在Android应用程序中实现了警报.报警工作正常.Toast消息是可见的. 现在我想向用户发出警报框通知.

这是来自ReceiverActivityClass的代码.我试过了

public class ReceiverActivity extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub

// Code....


    new AlertDialog.Builder(context)
    .setTitle("Alert Box")
    .setMessage("Msg for User")
    .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface arg0, int arg1) {
        // TODO Auto-generated method stub
            // some coding...
        }
    })
    .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface arg0, int arg1) {
            arg0.dismiss();
    }
}).create().show();
}
Run Code Online (Sandbox Code Playgroud)

}

android broadcastreceiver android-alarms android-alertdialog

0
推荐指数
1
解决办法
9636
查看次数