在我的应用程序中,我有一个ViewPager,其中包含许多带有Fragments的可滑动Tabs.我使用该setUserVisibleHint方法来检测何时Fragment进入屏幕.当用户在选项卡之间滑动但在第一次加载时它不起作用时,这非常有效.要在方法中运行代码,我必须向左滑动然后再回到第一个,Fragment因为在setUserVisibleHint方法之前调用该onCreateView方法.
你知道如何在第一个片段可见后运行此代码吗?是否有其他方法ViewPager?
我反编译我的系统音乐应用程序(来自索尼爱立信Android版2.3.7),因为我想更改通知布局.我找到了使用此代码创建通知的方法:
private void sendStatusBarNotification(Track paramTrack)
{
if (paramTrack != null)
{
NotificationManager localNotificationManager = (NotificationManager)this.mContext.getSystemService("notification");
String str = paramTrack.getArtist();
if ((str == null) || (str.equals(this.mContext.getString(2131361954))))
str = this.mContext.getString(2131361798);
Notification localNotification = new Notification(2130837696, paramTrack.getTitle() + " - " + str, System.currentTimeMillis());
localNotification.flags = (0x2 | localNotification.flags);
localNotification.flags = (0x20 | localNotification.flags);
PendingIntent localPendingIntent = PendingIntent.getActivity(this.mContext, 0, new Intent(this.mContext, MusicActivity.class), 268435456);
localNotification.setLatestEventInfo(this.mContext, paramTrack.getTitle(), str, localPendingIntent);
localNotificationManager.notify(0, localNotification);
}
}
Run Code Online (Sandbox Code Playgroud)
我现在的问题是:如何更改通知布局?我想构建一个看起来像原始Android通知布局但在通知右侧有一个额外图像的布局.我怎样才能做到这一点?
在我的应用程序中,我使用底部工作表(来自支持库),它非常有用.现在,我想在拖动工作表时设置布局更改动画.为此,我创建了一个子类BottomSheetCallback(这通常是片段的内部类,所以不是这个calss中使用的所有对象都在这里初始化):
public class MyBehavior extends BottomSheetBehavior.BottomSheetCallback {
Transition transition;
float lastOffset = 0;
Scene scene;
public PlayerBehavior() {
TransitionInflater inflater = TransitionInflater.from(getContext());
transition = inflater.inflateTransition(R.transition.player);
//transition.setDuration(300);
scene = fullLayout;
transition.setInterpolator(new Interpolator() {
@Override
public float getInterpolation(float v) {
return lastOffset;
}
});
}
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
if(newState == BottomSheetBehavior.STATE_DRAGGING) {
TransitionManager.go(scene, transition);
}
}
@Override
public void onSlide(View bottomSheet, final float slideOffset) {
scene = (slideOffset > lastOffset) ? smallLayout : fullLayout; …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我希望每天在特定时间运行一些代码AlarmManager.在android文档中我发现了这个:
设备处于睡眠状态时会保留已注册的警报,但如果已关闭并重新启动,则会将其清除.
这就是问题所在.即使用户重新启动手机,我也想运行代码.如果用户重新启动手机,他当前必须重新启动我的应用以再次启动闹钟.我怎么能阻止这个?我应该使用更好的机制吗?
我尝试使用此代码创建通知:
private void setNotificationAlarm(Context context)
{
Intent intent = new Intent(getApplicationContext() , MyNotification.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 , pendingIntent);
Log.d("ME", "Alarm started");
}
public class MyNotification extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Log.d("ME", "Notification started");
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("My notification")
.setContentText("Hello World!");
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
}
}
Run Code Online (Sandbox Code Playgroud)
在这里,我的Mainfest宣言:
<receiver
android:name=".MyNotification"
android:enabled="true"
android:exported="false" >
</receiver>
Run Code Online (Sandbox Code Playgroud)
我现在的问题是,生成了警报,但未显示通知.BroadcastReceiver在mainfest文件中声明,没有编译器或运行时错误.
我的第二个问题是setLatestEventInfo …
我有一个GridLayout(不是GridView),我想添加一些特殊的行和列的视图.在XML中,我可以使用以下命令设置View:
<TextView
android:id="@+id/textView1"
android:layout_column="2"
android:layout_row="4"
android:text="Large Text" />
Run Code Online (Sandbox Code Playgroud)
但我怎么能设置的属性layout_column和layout_row程序?我想要这样的东西:
GridLayout grid = new GridLayout(getActivity());
grid.setColumn(2);
grid.setRow(4);
grid.addView(new Button(getActivity());
Run Code Online (Sandbox Code Playgroud) 目前我正在开发一个支持Android磨损的应用程序,但我没有智能手表.现在我想在模拟器上测试我的应用程序但这就是问题所在.模拟器需要长达1.5小时才能启动.我用以下设置创建了一个:
<!-- language: lang-none -->
Target Google APIs (Google Inc.) API lev 22
CPU/ABI Google APIs Intel Atom (x86)
Device 5.1" WVGA (480x800: mdpi)
Skin No Skin
RAM 512 //also tried with 768
VM Heap 32
Internal Storage 200
Use Host GPU true //also tried with false
Run Code Online (Sandbox Code Playgroud)
我安装了HAXM,在BIOS设置中启用它并运行
sc query intelhaxm
Run Code Online (Sandbox Code Playgroud)
我得到了状态4,就像它写在这里一样.我将HAXM内存设置为2GB,因此应该使用它.我也没有运行任何其他VM软件,我甚至重新安装了我的Windows.LogCat唯一有趣的信息是有很多行(最多70%)Suspending all threads
我的电脑有以下硬件:
<!-- language: lang-none -->
Windows 7 x64
Intel Core 2 Quad Q6600
8GB RAM
Run Code Online (Sandbox Code Playgroud)
你有什么想法为什么我的模拟器这么慢?
编辑:在这里我发布了智能手机设备的目标,但它对于可穿戴设备也是如此之慢,因此Genymotion不是真正的替代品,因为它没有图像.
在我目前的android项目中,我正在使用新的Retrofit 2.0库向我的Web服务器发送一些数据.我只想在那里运行一个脚本,服务器不会返回任何内容.我以为我可以用这种方法做到这一点:
@POST("persons/insert.php")
Call<Void> insert(@Field("Name") String name);
Run Code Online (Sandbox Code Playgroud)
我现在的问题是,onFailure虽然服务器返回200 ,但Retrofit会跳转到该方法.这是因为没有任何东西可以转换为Void.那我该怎么办呢?我希望onResponse如果服务器发回200并且onFailure发生错误,则调用该方法.我怎样才能做到这一点?
我目前正在将我的应用程序迁移到 Android Q。我想列出所有已配置的 WiFi 网络,并且在 QI 能够使用WiFiManager 中的getConfiguredNetworks函数执行此操作之前。遗憾的是,此方法在 API 级别 29 上已弃用,并在 Android Q 设备上返回空列表。
弃用评论仅指我也想连接到这些网络的情况。我不想这样做,我只想列出带有名称的网络并获取其内部id. 你有什么想法我应该如何在 Q 中做到这一点吗?
在我当前的Android项目中,我使用Butterknife库来绑定视图并onClick为它们使用注释.这一切在片段中都很有效,但现在我无法找到解决方案:
我使用新的ToolBaras ActionBar并用其中的一个菜单充气SearchView.为此,SearchView我想使用@OnTextChanged注释但是当我用ActionView菜单项调用bind方法时,Butterknife尝试再次重新注册所有视图,当然在ActionView它中找不到任何其他视图RootLayout.
那么,有没有办法只能添加一个View带有Butterknife或者我可以得到一个视图包含所有意见我RootLayout和ToolBarView这样我就可以通过这个视图的绑定方法?例如,在Activites中,我也可以调用findViewById菜单ID,但是如果我使用getView()我的Fragment它不起作用.有什么想法吗?
android ×10
android-10.0 ×1
android-wifi ×1
android-xml ×1
butterknife ×1
reboot ×1
restart ×1
retrofit ×1