我想在另一个活动之上创建一个透明的Activity.
我怎样才能做到这一点?
我正在开发一个广播接收器,用于Android中的来电和接听来电,我想在本地来电屏幕上弹出一个弹出窗口.
我完成了那段代码.但现在的问题是,在Android 4.1(Jelly Bean)API级别17中,当电话响铃时,它PHONE_STATE就会出现OFF HOOK,如果我正在调用一个活动,它会被调用,但它下面的代码不会被执行.我列出了代码:
package com.example.popwindowonincomingcallscreen;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.util.Log;
public class IncomingBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("IncomingBroadcastReceiver: onReceive: ", "flag1");
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
Log.d("IncomingBroadcastReceiver: onReceive: ", state);
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)
|| state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
Log.d("Ringing", "Phone is ringing");
Intent i = new Intent(context, IncomingCallActivity.class);
i.putExtras(intent);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
Wait.oneSec();
context.startActivity(i);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我正在打电话的活动:
import android.app.Activity; …Run Code Online (Sandbox Code Playgroud) android broadcastreceiver android-widget android-layout android-broadcast
我想通过AlertDialogManager类向一个non-activity类DeviceAdminReceiverSample的方法显示一个Alert Dialog onDisabled,但每当我alertDialog通过该方法调用它时,它会生成以下文本的错误
错误
06-12 12:01:19.923: E/AndroidRuntime(468): FATAL EXCEPTION: main
06-12 12:01:19.923: E/AndroidRuntime(468): java.lang.RuntimeException: Unable to start
receiver com.android.remotewipedata.DeviceAdminReceiverSample:
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not
for an application
Run Code Online (Sandbox Code Playgroud)
我知道这个问题与context事情有关,但我不知道该放什么,以便它起作用,我试过this,getApplicationContext()但都是徒劳的.我的两个类的代码如下
AlertDialogManager
public class AlertDialogManager {
public void showAlertDialog(Context context, String title, String message,
Boolean status) {
final AlertDialog alertDialog = new AlertDialog.Builder(context).create();
alertDialog.setTitle(title);
alertDialog.setMessage(message);
if (status != null)
alertDialog.setButton("OK", new DialogInterface.OnClickListener() { …Run Code Online (Sandbox Code Playgroud) 我正在构建一个Android应用程序,BroadcastReceiver我想在onReceive启动时显示一个对话框.我想在手机上显示对话框(无论他在哪里,都会向用户显示一个对话框,比如收到消息时的whatsapp对话框).
我怎么能这样做?
谢谢!
当很少有参数不满足时,我试图从 Retrofit 拦截器显示一个对话框。但是android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?在尝试显示对话框时出现异常。
这是我的代码。
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(ShieldSquare.applicationContext)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle("Are you sure to Exit")
.setMessage("Exiting will call finish() method")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
})
//set negative button
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//set what should happen when negative button is clicked
Toast.makeText(ShieldSquare.applicationContext,
"Nothing Happened", Toast.LENGTH_LONG).show(); …Run Code Online (Sandbox Code Playgroud)