AlertBox无法在真正的手机中工作

时间:2014-11-19 10:56:00

标签: android android-alertdialog

我有一个应用程序,我从广播接收器中取3个字符串并将其传递给字符串。然后我将这些字符串从服务传递到带有theme.dialog的活动。警报框在模拟器中完美弹出,但警告框不会弹出一个真正的手机。 代码如下

public class AlarmReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
      String imagepath= intent.getStringExtra("image");
      String contactName= intent.getStringExtra("contactName");
      String event= intent.getStringExtra("event");



       Intent i = new Intent(context, MyService.class);
       i.putExtra("imagepath", imagepath);
       Log.e("imagepath",imagepath);
       i.putExtra("event", event);
       i.putExtra("contactName", contactName);

       context.startService(i);



    }

}

服务代码

@Override
protected void onHandleIntent(Intent intent) {
    imagePath =intent.getStringExtra("imagepath");
    event = intent.getStringExtra("event");
    contactName =intent.getStringExtra("contactName");


    Intent intent1 = new Intent(this, Notification.class);
    intent1.putExtra("imagePath", imagePath);
    Log.e("imagepath service",imagePath);

    intent1.putExtra("event", event);
    intent1.putExtra("contactName", contactName);
    intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent1);


}

提醒框活动代码

public class Notification extends Activity {
    String path,event,contactName;
    TextView tvimagePath,tvEventNoti,tvContactNameNoti;
    ImageView imagePathNoti;
    Bitmap bmp;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.notification);
        Intent intent=getIntent();
    path = intent.getStringExtra("imagePath");
    event = intent.getStringExtra("event");
    contactName = intent.getStringExtra("contactName");
    Log.e("path",path);
    Log.e("event",event);
    Log.e("contactName",contactName);

   imagePathNoti=(ImageView) findViewById(R.id.imagePathNoti);

    bmp = BitmapFactory.decodeFile(path);
    bmp = Bitmap.createScaledBitmap(bmp, 200,200, true);
    imagePathNoti.setImageBitmap(bmp);


    tvEventNoti=(TextView) findViewById(R.id.tvEventNoti);
    tvContactNameNoti=(TextView) findViewById(R.id.tvContactNameNoti);
//  tvimagePath.setText(imagePath);
    tvEventNoti.setText(event);
    tvContactNameNoti.setText(contactName);



    }


}

代码似乎可以在模拟器中运行,但不能在真正的手机中运行。你能建议为什么? 提前致谢

0 个答案:

没有答案