Tag: 安卓

Android – 应用程序关闭时从另一个类调用方法(使用AlarmManager)

我试图使用AlarmManager从另一个类调用我的MainActivity类中的方法。 我发现这个问题帮助我调用了方法但是当应用程序关闭时,AlarmManager仍在运行,它会产生NullPointerException错误。 另一个对我有用的解决方案是在我的AlarmRec类中包含getBatteryLevel()。 当我尝试这个时,我得到错误 – 无法解析方法registerReceiver(null,android.content.IntentFilter)。 我的MainActivity类: package com.ds.shutdown; import android.app.Activity; import android.app.AlarmManager; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.os.BatteryManager; import android.os.Bundle; import android.preference.PreferenceManager; import android.support.v4.app.NotificationCompat; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import java.util.Calendar; public class MainActivity extends Activity { […]

如何在android中为应用程序的背景着色

我添加了一个颜色文件夹,这个xml文件: #FF9912 但是当我在我在values文件夹中创建的screen_display.xml中输入值时。 它给了我一个错误: true true @colors/color/orange UPDATE

将Android应用程序连接到Google Cloud Endpoints时出错:无法找到课程

我已经使用Google Cloud Endpoints构建了一个API,我正在尝试连接到它编写Android应用程序。 我按照以下教程: https://developers.google.com/appengine/docs/java/endpoints/consume_android 所以,我在我的“src”文件夹中添加了jar的内容,我将列出的库复制到lib并添加了代码。 当我尝试启动应用程序时,它崩溃了以下错误: 02-26 12:19:52.874: E/dalvikvm(17558): Could not find class ‘com.google.api.services.utenteendpoint.Utenteendpoint$Builder’, referenced from method com.example.androidgcetest.MainActivity.onCreate 02-26 12:19:53.004: E/AndroidRuntime(17558): FATAL EXCEPTION: main 02-26 12:19:53.004: E/AndroidRuntime(17558): java.lang.NoClassDefFoundError: com.google.api.services.utenteendpoint.Utenteendpoint$Builder 02-26 12:19:53.004: E/AndroidRuntime(17558): at com.example.androidgcetest.MainActivity.onCreate(MainActivity.java:22) 02-26 12:19:53.004: E/AndroidRuntime(17558): at android.app.Activity.performCreate(Activity.java:4465) 02-26 12:19:53.004: E/AndroidRuntime(17558): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 02-26 12:19:53.004: E/AndroidRuntime(17558): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931) 02-26 12:19:53.004: E/AndroidRuntime(17558): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992) […]

如何在Android中使用Microsoft Translator API

用于Android示例的Microsoft Translator API自2017年3月起已被弃用(仅此一年)。 所以我很难在android上翻译文本。 任何人都可以帮我在android上做这个工作吗? 只是我已经在java中使用它,但我无法在Android上运行它。 我已经尝试过使用asynctask,但无济于事,没有翻译出来。 或者我刚刚做了一个错误的asyc任务? 应用程序的界面是这样的: 它只有一个简单的文本字段,其翻译应该在另一个文本字段中输出。 翻译是从韩语到英语。 Github项目文件在这里 https://github.com/iamjoshuabcxvii/MSTranslateAPIforAndroid Android代码是这样的。 import android.os.AsyncTask; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.TextView; import org.apache.commons.io.IOUtils; import java.net.URL; import java.net.URLEncoder; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.net.ssl.HttpsURLConnection; public class MainActivity extends AppCompatActivity { //MS Translator Key is in here public static String key = “”; private […]

Google Maps API v2多个地图片段问题

我已经尝试了新的谷歌地图api v2的几个问题 我有一个包装mapFragment的片段,这是在应用程序的乞讨时创建的。 在用户单击按钮时创建的另一个片段,此内容为另一个mapFragment。 但是这张地图显示了第一个片段上显示的第一张地图。 它也冻结了,不能对它采取行动…… 我已经读过一些用户在显示多地图时遇到问题。 知道怎么解决这个问题? 这是我创建地图的方式: mMapFragment = (SupportMapFragment) this.getActivity().getSupportFragmentManager() .findFragmentByTag(MAP_FRAGMENT_TAG); // We only create a fragment if it doesn’t already exist. if (mMapFragment == null) { // To programmatically add the map, we first create a // SupportMapFragment. mMapFragment = SupportMapFragment.newInstance(); mMapFragment.setRetainInstance(false); // Then we add it using a FragmentTransaction. FragmentTransaction […]

如何在Android(9)Pie中允许所有网络连接类型HTTP和HTTPS?

从Android 9 Pie开始,没有加密的请求永远不会起作用。 默认情况下,系统会指望您默认使用TLS。 您可以在此处阅读此function。因此,如果您只通过HTTPS发出请求,那么您就是安全的。 但是那些通过不同网站提出请求的应用程序呢,例如类似浏览器的应用程序。 如何在Android 9 Pie中启用对HTTP和HTTPS的所有类型连接的请求?

有没有办法在使用getResources()时避免大小限制.openRawResource()

我正在尝试在应用程序首次运行时从我的Android项目中的res / raw文件夹加载XML文件。 我用这一行做到这一点: InputStream xmlStream = getResources().openRawResource(R.raw.xmlfile); 然后我想使用SAX Parser从XML文件中获取数据。 执行此操作时LogCat显示以下错误: Data exceeds UNCOMPRESS_DATA_MAX (1290892 vs 1048576) 反正这个1MB的限制吗? 经过几次谷歌搜索后,我发现有人将文件分成1MB块,但这些文件不是XML文件,所以我不确定在为SAX Parser制作InputSource之前我会如何重新加入它们。 我的文件不是由我创建的,所以我无法真正编辑它(虽然我可能不得不),如果我从Internet检索它,我的代码就可以了。 它的大小约为1,300KB,因此我希望每次app运行时都不必下载它

setAlarmClock无法正常工作

我正在使用IntentService准备警报并在其中使用IntentService来设置警报。 IntentService始终在适当的时间运行并设置警报(图标将显示)但警报将在100次中运行约99次。当一个警报失败时,具有类似Intent每个警报将失败,直到您完全关闭应用程序(在PendingIntent是什么并不重要)。 无论如何,在预定的闹钟时间之前的微秒,这称为: 09-19 16:10:59.996 1374-2126/? V/AlarmManager: Expired Alarm result :4 09-19 16:11:00.046 1374-2126/? D/VirtualScreenPolicy: applyVirtualScreenAttrs attrs=VirtualScreenAttrs{mDisplayId=0, mBaseDisplayId=0, mBaseActivity=false} 09-19 16:11:00.046 1374-2126/? D/GameManagerService: identifyGamePackage. com.simplyneededapps.ridealarm 09-19 16:11:00.046 1374-2126/? D/MultiWindowPolicy: Gamemode – return 0, when calling identifyForegroundApp(com.simplyneededapps.ridealarm) 09-19 16:11:00.066 1374-2126/? D/ActivityManager: mDVFSHelper.acquire() 09-19 16:11:00.066 1374-2126/? W/ActivityManager: startActivity called from non-Activity context; forcing Intent.FLAG_ACTIVITY_NEW_TASK for: Intent { […]

错误NullPointerException:lock == null

任何人都可以帮助我解决这个错误,当我运行应用程序并搜索ID时,从MySQL数据库选择值到Android,它总是说(无效的IP地址)… 我的Web服务器上有一个PHP文件,它连接到WampServer数据库并检索返回到Android应用程序的值。 String id String name; InputStream is=null; String result=null; String line; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final EditText e_id=(EditText) findViewById(R.id.editText1); Button select=(Button) findViewById(R.id.button1); select.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub id=e_id.getText().toString(); select(); } }); } public void select() { ArrayList nameValuePairs = new ArrayList(); […]

使用Oauth将Java应用程序与GAE应用程序连接起来

我有一个Java应用程序和一个GAE应用程序,它将C2DM消息发送到Android设备。 现在我想让java应用程序的用户能够通过他们的Google帐户登录到GAE应用程序。 我是否正确,我需要使用oauth来实现这一点? 一点点背景: +———–+ +———-+ | JAVA App | send Message to —> | GAE App | +———–+ +———-+ ^ | | Notify Client | —————————- | | [YES] —> Start delivering C2DMessage 我希望我的ASCII图片更容易理解;) 不知何故,我需要允许用户使用他们的google凭据登录java应用程序,如果我向服务器发送消息,则将用户数据与消息一起发送到服务器。 我真的不知道如何做到这一点。 如果你能告诉我,那么我是在正确或错误的轨道上会很棒。 任何建议我都会很高兴。 谢谢,马克