我希望检查手机中没有的应用程序的名称,并相应地发送Toast消息。例如 ;我手机上有Twitter应用程序,但ABC应用程序不在我的手机上。通过在字符串中输入值,应用程序将以名称写入,并且应用程序将不会有此类应用程序。我怎样才能做到这一点?例如,我的手机上没有ABC应用程序,我没有这样的应用程序。我需要听一听手机上的流程,但我可以听吗?我在下面编写的代码中写了一些关于服务的内容,但它并不完整。我应该为此查看ActivityManager或getRunningProcess吗?我希望我能说出来。
MainActivity.java
public class MainActivity extends Activity {
String msg = "Twitter : ";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(msg, "The onCreate() event");
}
public void startService(View view) {
startService(new Intent(getBaseContext(), MyService.class));
}
// Method to stop the service
public void stopService(View view) {
stopService(new Intent(getBaseContext(), MyService.class));
}
}
MyService.java
public class MyService extends Service {
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// Let it continue running until it is stopped.
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show();
}
}