我最近尝试使用读取传入通知AccessibilityService.我知道阅读通知使用NotificationListenerService,但这不是我需要的(为了兼容较低的Android版本).我的问题是,OnServiceConnected()永远不会被调用,即使在我的设置中,我已经为我的应用程序提供了必要的预测.这是我的代码:
public class NotificationAccessibilityService extends AccessibilityService{
protected void onServiceConnected() {
Log.d("Tortuga", "AccessibilityService Connected");
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED;
info.feedbackType = AccessibilityServiceInfo.FEEDBACK_ALL_MASK;
info.notificationTimeout = 100;
setServiceInfo(info);
}
@Override
public void onAccessibilityEvent(AccessibilityEvent e) {
Log.d("Tortuga","FML");
if (e.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
Log.d("Tortuga","Recieved event");
Parcelable data = e.getParcelableData();
if (data instanceof Notification) {
Log.d("Tortuga","Recieved notification");
Notification notification = (Notification) data;
Log.d("Tortuga","ticker: " + notification.tickerText);
Log.d("Tortuga","icon: " + notification.icon);
Log.d("Tortuga", "notification: "+ e.getText());
}
}
} …Run Code Online (Sandbox Code Playgroud) xml notifications android accessibility accessibilityservice
在android/java中,我试图用a替换某些字符串中的空格+,但它似乎不起作用.我做错了吗?
String string="Hello world";
string.replace(" ", "+");
Run Code Online (Sandbox Code Playgroud) 我有一个扩展ListActivity的类,其中列表项响应OnClick事件.添加OnItemLongClickListener不起作用.不调用onItemLongClick()函数(没有日志输出或Toast显示),而是处理正常的OnClick()事件.
我想在长按一下显示上下文操作栏.在新项目中使用我的代码的最小示例工作正常.所以我的问题是:什么可能阻止触发onItemLongClick()触发器?
我的最小API是11.我也将listView设置为longClickable="true".
活动代码(选定的功能):
public class EventListActivity extends ListActivity {
private ArrayList<Event> arrEvents = null;
private ArrayAdapter<Event> adpEvents = null;
private ActionMode mActionMode = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// only create list adapter and set it
arrEvents = new ArrayList<Event>();
adpEvents = new ArrayAdapter<Event>(this, android.R.layout.simple_list_item_activated_2, android.R.id.text1, arrEvents) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView text1 = (TextView) view.findViewById(android.R.id.text1);
TextView text2 = (TextView) view.findViewById(android.R.id.text2); …Run Code Online (Sandbox Code Playgroud) 我正在写一个Android库项目.我尝试注册Google地图并获取API密钥.我使用my certificate information,意思是我SHA1从我的库中取指纹,并获得API密钥.
问题是我需要在宿主应用程序清单中写下这些信息:
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="API_KEY" />
Run Code Online (Sandbox Code Playgroud)
此API密钥适合我的库,而不适合主机应用程序.当我像单独的应用程序一样运行我的库项目时,它可以正常工作
有谁知道我如何使用我api_key作为图书馆项目?
谢谢
android google-maps android-library google-maps-android-api-2
我正在尝试从我的Android客户端发送HTTP/HTTPS发布请求.
为什么我的代码失败了?
我创建了一个apache类/ HttpClient调用.一切都很好:
HttpClient httpClient = new DefaultHttpClient();
Run Code Online (Sandbox Code Playgroud)
我已经读过这个方法已被弃用,所以我已经切换到新推荐的方法:
HttpClient httpClient = HttpClientBuilder.create().build();
Run Code Online (Sandbox Code Playgroud)
Eclipse没有这个类,所以我不得不下载Apache HttpClient 4.3.3.我通过将其复制到libs文件夹并将其添加到我的构建路径(导入的httpclient,httpclient-cache,httpcore,httpmime,fluent-hc,commons-logging,commons-codec)将其导入到我的项目中.
06-05 02:15:26.946: W/dalvikvm(29587): Link of class 'Lorg/apache/http/impl/conn/PoolingHttpClientConnectionManager;' failed
06-05 02:15:26.946: E/dalvikvm(29587): Could not find class 'org.apache.http.impl.conn.PoolingHttpClientConnectionManager', referenced from method org.apache.http.impl.client.HttpClientBuilder.build
Run Code Online (Sandbox Code Playgroud)
static private String insertJson(String json,String url){
HttpClient httpClient = HttpClientBuilder.create().build();
String responseString = "";
try {
HttpPost request = new HttpPost(url);
StringEntity params =new StringEntity(json, "UTF-8");
request.addHeader("content-type", "application/json");
request.setEntity(params);
HttpResponse response = httpClient.execute(request);
HttpEntity entity = response.getEntity(); …Run Code Online (Sandbox Code Playgroud) 我有以下代码将图像从Android上传到Web服务器.
它工作正常,只是收到的图像是内容类型八位组流,我需要它是内容类型图像.知道如何设置内容类型吗?
public void sendImage(final Bitmap mBitmap, final String caption, final WebListener webListener) {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
AQuery aq = new AQuery(smApplication);
Map<String, Object> params = new HashMap<String, Object>();
params.put("file_name", "name" + (int) (Math.random() * 1000));
params.put("caption", caption);
ByteArrayOutputStream blob = new ByteArrayOutputStream();
mBitmap.compress(Bitmap.CompressFormat.PNG, 0 /*ignored for PNG*/, blob);
byte[] bitmapdata = blob.toByteArray();
params.put("photo", bitmapdata);
AjaxCallback<JSONObject> ac = new AjaxCallback<JSONObject>() {
@Override
public void callback(String url, JSONObject object, AjaxStatus status) { …Run Code Online (Sandbox Code Playgroud) 我真的不知道我正在构建的Android应用程序发生了什么.在它开发的某个时刻,我开始在模拟器中启动它,并显示消息"Foo stopped".这是错误日志,如果有人可以帮助我:
07-05 21:13:30.063 7647-7647/root.fazerumsom E/AndroidRuntime? FATAL EXCEPTION: main
Process: root.fazerumsom, PID: 7647
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{root.fazerumsom/root.fazerumsom.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.content.ContextWrapper.getResources(ContextWrapper.java:89)
at android.view.ContextThemeWrapper.getResources(ContextThemeWrapper.java:78)
at root.fazerumsom.MainActivity.<init>(MainActivity.java:31)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1208)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2101)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at …Run Code Online (Sandbox Code Playgroud) 使用Android Studio,我尽可能按照https://developer.android.com/tools/support-library/setup.html中的步骤操作,但它告诉我以下错误:
错误:无法在org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated@18899229上找到参数[com.android.support:appcompat-v7:18.0.+]的方法compile().
请从Android SDK Manager安装Android支持存储库.打开Android SDK Manager
但我已经安装了支持存储库和库!因为我也有错误说不compile属于dependencies块,所以我将其更改为classpath,并得到以下,类似的错误:
错误:找不到与com.android.support:appcompat-v7:18.0.+匹配的任何版本.要求:: ExpenseTracker:未指定
请从Android SDK Manager安装Android支持存储库.打开Android SDK Manager
正如你在这里看到的那样,它仍然认为ASR没有安装,但截图证明,它是.那么我在这里做错了什么?
android compiler-errors android-support-library android-gradle-plugin
我按照此链接中的说明在Android Studio中创建了一个简单的移动/可穿戴应用程序.但是,它不会识别任何特定于可穿戴SDK的类,会出现错误"无法解析符号______ ".这个链接的截图就是我所看到的.
以下是我的build.gradle文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion '20.0.0'
defaultConfig {
applicationId 'com.example.lsykora.androidwearwidget'
minSdkVersion 'L'
targetSdkVersion 'L'
versionCode 1
versionName '1.0'
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard- rules.pro'
}
}
productFlavors {}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
// You must install or update the Support Repository through the SDK manager to use this dependency.
// You must install or update the Support Repository through …Run Code Online (Sandbox Code Playgroud) 我想用Android的内置图标,我不知道怎么样,我试着用这两行:
android:background="@drawable/ic_lock_silent_mode_off"
android:background="R.drawable.ic_lock_silent_mode_off"
Run Code Online (Sandbox Code Playgroud)
这两行都不适用于我,如何将此图标用于我的按钮?
我收到此错误:
error: Error: No resource found that matches the given name (at 'background' with value '@drawable/ic_lock_silent_mode_off').
Run Code Online (Sandbox Code Playgroud)