如何添加AlertDialog广播接收器类的Android? [英] How to add AlertDialog in broadcast receiver class in android?
问题描述
我开发一个SMS的应用程序。在一旦短信涉及到收件箱就应该显示一些警告。
我想在下面的code添加报警。这可能吗?
公共类SMSReceiver扩展广播接收器
{
@覆盖
公共无效的onReceive(上下文的背景下,意图意图)
{
捆绑包= intent.getExtras();
SmsMessage []封邮件= NULL; 如果(NULL!=束)
{ [对象]的PDU =(对象[])bundle.get(的PDU);
封邮件=新SmsMessage [pdus.length]
字节[]数据= NULL; 的for(int i = 0; I< msgs.length;我++){
封邮件[I] = SmsMessage.createFromPdu((字节[])的PDU [I]);
}
}
}}
在应用程序中创建一个活动
并启动活动
从广播接收器
和现在推出 AlertDialog
在的onCreate
活动的方式
创建 style.xml
在 RES /值
文件夹,并把这个里面
<样式名称=Theme.Transparent父=安卓主题>
<项目名称=机器人:windowIsTranslucent>真< /项目>
<项目名称=机器人:windowBackground>#000000< /项目>
<项目名称=机器人:windowNoTitle>真< /项目> < /风格>
请 Activty
透明通过把安卓主题=@风格/ Theme.Transparent
作为一个属性活动
在的AndroidManifest.xml
文件,以便仅 AlertDialog
将被显示。
I'm developing one sms application. In that once the SMS comes to inbox it should display some alert. I want to add alert in the following code. Is it possible?
public class SMSReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
if(null != bundle)
{
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
byte[] data = null;
for (int i=0; i<msgs.length; i++){
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
}
}
}
}
Create a Activity
in your application and start Activity
from your BroadcastReceiver
and now launch AlertDialog
within onCreate
method of Activity
create style.xml
inside res/values
folder and put this inside it
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#000000</item>
<item name="android:windowNoTitle">true</item>
</style>
make Activty
Transparent by putting android:theme="@style/Theme.Transparent"
as a attribute of Activity
in your AndroidManifest.xml
file so only AlertDialog
will be shown.
这篇关于如何添加AlertDialog广播接收器类的Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!