我想开发一个应用程序,可以接收有关正在安装或删除的其他应用程序的广播.到目前为止,我尝试了下面的代码,但是,它仅在删除安装时提供广播事件,它不提供有关安装或删除的其他应用程序beibg的信息.那么,有没有办法获取新安装的应用程序的包名称.
在表现:
receiver android:name=".apps.AppListener">
<intent-filter android:priority="100">
<action android:name="android.intent.action.PACKAGE_INSTALL"/>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
<data android:scheme="package"/>
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
在AppListener中:
public class AppListener extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// there is a broadcast event here
// but how to get the package name of the newly installed application
Log.v(TAG, "there is a broadcast");
}
}
Run Code Online (Sandbox Code Playgroud)
增加: 对于Api 14或更高版本,不推荐使用此功能.
<action android:name="android.intent.action.PACKAGE_INSTALL"/>
Run Code Online (Sandbox Code Playgroud) 下面,我有绘制李克特图的 R 代码。
set.seed(1234)
library(e1071)
probs <- cbind(c(.4,.2/3,.2/3,.2/3,.4),c(.1/4,.1/4,.9,.1/4,.1/4),c(.2,.2,.2,.2,.2))
my.n <- 100
my.len <- ncol(probs)*my.n
raw <- matrix(NA,nrow=my.len,ncol=2)
raw <- NULL
for(i in 1:ncol(probs)){
raw <- rbind(raw, cbind(i,rdiscrete(my.n,probs=probs[,i],values=1:5)))
}
r <- data.frame( cbind(
as.numeric( row.names( tapply(raw[,2], raw[,1], mean) ) ),
tapply(raw[,2], raw[,1], mean),
tapply(raw[,2], raw[,1], mean) + sqrt( tapply(raw[,2], raw[,1], var)/tapply(raw[,2], raw[,1], length) ) * qnorm(1-.05/2,0,1),
tapply(raw[,2], raw[,1], mean) - sqrt( tapply(raw[,2], raw[,1], var)/tapply(raw[,2], raw[,1], length) ) * qnorm(1-.05/2,0,1)
))
names(r) <- c("group","mean","ll","ul")
gbar <- tapply(raw[,2], list(raw[,2], raw[,1]), length)
sgbar <- …Run Code Online (Sandbox Code Playgroud) 我有一个主要活动类并找到课程.我需要从find类访问主要活动变量的变量,即"name".我尝试使用下面的代码段访问但我收到错误.如何从其他类访问主要活动变量?
public class main extends Activity {
public static String name=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button1=(Button)findViewById(R.id.button1);
final EditText edittext = (EditText) findViewById(R.id.editText1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
name=edittext.getText().toString();
}
});
}
Run Code Online (Sandbox Code Playgroud)
我的第二课......
public class find {
public void finder(){
main mainactivity=new main();
String incoming_name =mainactivity.name;//I can not use like that ?
// do something
}
Run Code Online (Sandbox Code Playgroud)
}
public class test extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
String extra = "test";
NotificationManager myNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Intent intent = new Intent(this, another.class);
Notification notification = new Notification(R.drawable.ic_launcher, extra,
System.currentTimeMillis());
PendingIntent pendingIntent = PendingIntent.getActivity(this,
0,
intent,
PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(getApplicationContext(), "title", "text", pendingIntent);
notification.defaults|= Notification.DEFAULT_SOUND;
notification.defaults|= Notification.DEFAULT_LIGHTS;
notification.defaults|= Notification.DEFAULT_VIBRATE;
notification.flags |= Notification.FLAG_INSISTENT;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
myNotificationManager.notify(1, notification);
}
}
Run Code Online (Sandbox Code Playgroud)
这段代码工作正常,事情是,当我运行它时,通知声音不断响起,直到我在状态栏上检查它.有没有办法让它只响一次,而不是不断响?
Cursor cursor = db.rawQuery("SELECT id,lastname FROM people WHERE lastname=null; ",null);
Run Code Online (Sandbox Code Playgroud)
此查询不返回lastname为空的成员.该查询有什么问题?我应该检查那个WHERE lastname =""吗?