我正在尝试遍历页面上的所有元素,所以我想检查此页面上存在的每个元素是否有特殊类.
那么,我怎么说我想检查每个元素?
所以我的sdk从15到21,当我打电话时setBackgroundDrawable(),Android Studio告诉我它已被弃用.
我想过用它来绕过它:
int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
layout.setBackgroundDrawable(getResources().getDrawable(R.drawable.img_wstat_tstorm));
} else {
layout.setBackground(getResources().getDrawable(R.drawable.img_wstat_tstorm));
}
Run Code Online (Sandbox Code Playgroud)
但是,我在"setBackground()"收到错误.
那么,你会如何应对呢?
我有一个活动和许多碎片在同一个膨胀 FrameLayout
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Run Code Online (Sandbox Code Playgroud)
示例:mainActivity>任何片段(按后退按钮)>活动为空.
在onCreate:
layout = (FrameLayout)findViewById(R.id.content_frame);
layout.setVisibility(View.GONE);
Run Code Online (Sandbox Code Playgroud)
当我开始片段时:
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.content_frame, profileFragment);
ft.addToBackStack(null);
ft.commit();
layout.setVisibility(View.VISIBLE);
Run Code Online (Sandbox Code Playgroud)
我想我需要GONE在后退时再次使frameLayout的可见性,但我该怎么做?
我尝试onBackPressed并设置layout.setVisibility(View.GONE);但我无法通过片段返回,因为我直接进入主页.
我有一点问题.
在我的应用程序中,在用户成功登录后启动服务.以前,如果应用程序被杀,该服务需要停止.(比如,通过滑动从最近的应用程序列表中删除.)所以我们使用过android:stopWithTask="true".现在我们需要服务按原样运行,即使启动它的任务从最近的应用程序列表中删除.所以我把服务改为包含android:stopWithTask="false".但这似乎不起作用.
相关代码:
这是与服务相关的明显部分:
<service
android:enabled="true"
android:name=".MyService"
android:exported="false"
android:stopWithTask="false" />
Run Code Online (Sandbox Code Playgroud)
在MyService.java中:
public class MyService extends AbstractService {
@Override
public void onStartService() {
Intent intent = new Intent(this, MyActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification notification = new Notification(R.drawable.ic_launcher, "My network services", System.currentTimeMillis());
notification.setLatestEventInfo(this, "AppName", "Message", pendingIntent);
startForeground(MY_NOTIFICATION_ID, notification);
}
@Override
public void onTaskRemoved(Intent rootIntent) {
Toast.makeText(getApplicationContext(), "onTaskRemoved called", Toast.LENGTH_LONG).show();
System.out.println("onTaskRemoved called");
super.onTaskRemoved(rootIntent);
}
}
Run Code Online (Sandbox Code Playgroud)
AbstractService.java是扩展的自定义类Sevrice:
public abstract class …Run Code Online (Sandbox Code Playgroud) 我想要以毫秒为单位的当前时间然后以12小时格式存储它,但是使用这段代码我得到24小时格式时间.
long timeInMillis = System.currentTimeMillis();
Calendar cal1 = Calendar.getInstance();
cal1.setTimeInMillis(timeInMillis);
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/mm/yyyy HH:mm:ss a");
dateforrow = dateFormat.format(cal1.getTime());
Run Code Online (Sandbox Code Playgroud)
任何人都可以提出修改以获得理想的结果?
首次将iOS应用程序提交到应用程序商店后,是否可以更新文件?
我们有一个稳定版本的新应用程序可以提交,但想知道我们是否可以发布具有新功能的更新,即使在初次提交几天后应用程序正在审核中.或者我们是否必须先等待应用程序获得批准才能提交更新?
我想在我的非root用户设备上使用WIFI连接ADB.目前我有3个Android设备,其中2个在Android 4.0.4上运行,1个在2.3上运行.我的设备IP是192.168.2.122,192.168.2.131,192.168.2.115
我已对所有这些程序启用了USB调试,并按照此处列出的所有步骤操作
在命令行上,我执行了以下操作
adb tcpip 5555
restarting in TCP mode port:5555
adb connect 192.168.2.131
Run Code Online (Sandbox Code Playgroud)
我的问题出在我的某个设备上(Android 4.0.4),ADB正在接收消息说
connected to 192.168.2.122:5555
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试连接其他时,它说
unable to connect to 192.168.2.131:5555
Run Code Online (Sandbox Code Playgroud)
终端页面的屏幕截图:

连接设备上终端的图像:

设备上没有连接的终端图像:

Stack Over Flow上的许多帖子都表示我需要根据我的手机设置相同的功能,但ADB连接的设备也没有根源.
可能是设备未连接的问题是他们的端口没有被收听.
任何帮助赞赏.
我正在尝试访问我的Gmail帐户并从中检索所有未读电子邮件的信息.
我在引用很多链接后编写了我的代码.我给出了一些链接供参考.
为了测试我的代码,我创建了一个Gmail帐户.所以我从Gmail收到了4封邮件.我在检查邮件数量后运行我的应用程序.这显示了正确的结果.4封未读邮件.显示所有信息(例如日期,发件人,内容,主题等)
然后我登录到我的新帐户,阅读其中一封电子邮件并重新运行我的应用程序.现在未读消息的计数应为3,但显示"未读消息数:0"
我在这里复制代码.
public class MailReader
{
Folder inbox;
// Constructor of the calss.
public MailReader() {
System.out.println("Inside MailReader()...");
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
/* Set the mail properties */
Properties props = System.getProperties();
// Set manual Properties
props.setProperty("mail.pop3.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.pop3.socketFactory.fallback", "false");
props.setProperty("mail.pop3.port", "995");
props.setProperty("mail.pop3.socketFactory.port", "995");
props.put("mail.pop3.host", "pop.gmail.com");
try
{
/* Create the session and get the store for read the mail. */
Session session = Session.getDefaultInstance(
System.getProperties(), null);
Store store = session.getStore("pop3");
store.connect("pop.gmail.com", 995, "abc@gmail.com", …Run Code Online (Sandbox Code Playgroud) 我的应用程序在10秒内加载起始页面.在那个10秒的时间内,android屏幕是空白的.那时我想添加加载屏幕.如何添加?并在应用程序中告诉我如何知道起始页面正在加载?并告诉我如何在我的应用程序中做?
我有一个Android应用程序与3 acitivtys:
A1 - 开始 - > A2 - 开始 - > A3 - 完成他的过程:开始 - > A1
(所以我不"完成();"一个应用程序.我用"startActivity(..);"用户交互后的整个时间开始下一个活动)
所以这3个活动中有一个循环.在每个活动中,我显示位于SD卡上的3-9张图片,我使用以下功能加载:
try
{
Uri selectedImageURI = Uri.parse(strImagePath);
File imgFile = new File(getRealPathFromURI(selectedImageURI, c));
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
ivTmp.setImageBitmap(myBitmap);
}catch (Exception e)
{
return null;
}
Run Code Online (Sandbox Code Playgroud)
这一切都有效.但有时候(通过我的活动循环几次后),我的应用程序崩溃了..
Logcat告诉我:
01-16 13:42:15.863: DEBUG/dalvikvm(23161): GC_BEFORE_OOM freed 10K, 9% free 59019K/64400K, paused 29ms, total 30ms
01-16 13:42:15.863: ERROR/dalvikvm-heap(23161): Out of memory on a 8018704-byte allocation.
01-16 13:42:15.863: ERROR/AndroidRuntime(23161): FATAL EXCEPTION: main
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at …Run Code Online (Sandbox Code Playgroud) android ×7
java ×2
adb ×1
app-store ×1
bitmap ×1
deprecated ×1
dom ×1
ios ×1
jakarta-mail ×1
javascript ×1
pop3 ×1
port ×1