下面列出了android.support.v4.app.FragmentActivity#getSystemService ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void sendNotification() {
FragmentActivity activity = getActivity();
if (activity == null)
return;
NotificationManager manager = (NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE);
if (manager == null)
return;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel("1", "1", NotificationManager.IMPORTANCE_DEFAULT);
manager.createNotificationChannel(channel);
}
Notification notification = new NotificationCompat.Builder(activity, "1")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("title")
.setContentText("test")
.setDefaults(Notification.FLAG_ONLY_ALERT_ONCE)
.build();
manager.notify(12, notification);
}
/**
*
*/
public void displaySoftKeyboard() {
final FragmentActivity activity = mActionBarActivity;
// Display the soft keyboard
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethodManager != null) {
View localView = activity.getCurrentFocus();
if (localView != null && localView.getWindowToken() != null) {
inputMethodManager.toggleSoftInput(0,InputMethodManager.HIDE_NOT_ALWAYS);
}
}
}
private boolean isNotificationListenerWork() {
Log.d(TAG, "isNotificationListenerWork: clickTime: " + (new Date().getTime() - App.timeCheckNotificationListenerServiceIsWorking));
FragmentActivity activity = getActivity();
if (activity == null)
return false;
NotificationManager manager = (NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE);
if (manager == null)
return false;
manager.cancel(12);
return (new Date().getTime() - App.timeCheckNotificationListenerServiceIsWorking) < 5000;
}
public PortalAdapter(FragmentActivity context) {
this.context = context;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
new InitManager(context, new Runnable() {
@Override
public void run() {
configLoaded = true;
notifyDataSetChanged();
loadForum();
loadTopics();
}
}).init();
}
public PortalAdapter(FragmentActivity context) {
this.context = context;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
new InitManager(context, new Runnable() {
@Override
public void run() {
configLoaded = true;
notifyDataSetChanged();
loadForum();
loadTopics();
}
}).init();
}
public InstantAnswersAdapter(FragmentActivity context) {
this.context = context;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public MixedSearchAdapter(FragmentActivity context) {
this.context = context;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public KnockSequenceListAdapter(FragmentActivity activity, KnockSequence sequence) {
this.activity = new WeakReference<FragmentActivity>(activity);
this.sequence = sequence;
this.inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public InstantAnswersAdapter(FragmentActivity context) {
this.context = context;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public MixedSearchAdapter(FragmentActivity context) {
this.context = context;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}