这似乎是一个常见的问题,我经历了我已经找到的所有相关问题: 活动没有获得新意图,为什么在android通知意图中没有发送额外数据(整数)?,Notification传递旧的Intent Extras,不能为通知中的意图,android挂起意图通知问题添加额外内容 ; 但仍然无法弄清楚这一点.
问题是一样的.我设置了一个带有PendingIntent的通知,其中包含一些额外的信息,而我却没有在另一方面得到它.
以下是生成通知的代码:
Notification notification = new Notification(R.drawable.icon, getResources().getString(R.string.notification_ticker), System.currentTimeMillis());
notification.flags = Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONLY_ALERT_ONCE;
Intent start_test = new Intent(this, MyActivity.class);
start_test.putExtra("start_test", true);
start_test.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pi = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), start_test, PendingIntent.FLAG_CANCEL_CURRENT);
notification.setLatestEventInfo(this, getResources().getString(R.string.notification_title), getResources().getString(R.string.notification_content, expired), pi);
nm.notify(NOTIFICATION_ID, notification);
Run Code Online (Sandbox Code Playgroud)
另一方面:
boolean start_test=getIntent().getBooleanExtra("start_test", false);
Run Code Online (Sandbox Code Playgroud)
捆绑实际上不存在(getExtras()返回null).
我尝试了不同的标志为PendingIntent.getActivity(FLAG_UPDATE_CURRENT,FLAG_CANCEL_CURRENT,FLAG_ONE_SHOT),没有这些帮助的.
如代码所示,我使用getCurrentMillis来确保requestID发生变化....
还发现在MyActivity中,onCreate并onNewIntent没有被调用.只是onResume.即使FLAG_ACTIVITY_NEW_TASK设定......?
我错过了一些非常简单的事吗?
我一直在将我的源码推送到Mercurial存储库.今天我需要删除我的本地副本并重新克隆.我这样做只需将我的本地副本移动到其他地方(以防万一)并输入"hg clone url".
这部分工作得很好.
但是,当我尝试将新克隆的本地副本拉入Eclipse时,我收到以下错误:
/Users/Andrew/Dev/Workspace/Android/MyProject overlaps the location of another project: 'MyProject'
Run Code Online (Sandbox Code Playgroud)
我的猜测是我一直在提交一些我不应该拥有的元文件.有没有人有任何想法?这是我的.hgignore:
syntax: regexp
\.DS_Store
.swo
.swp
.metadata/
/bin/
Run Code Online (Sandbox Code Playgroud)
注意:看起来我的hgignore没有阻止gen文件夹.这可能是问题的一部分吗?
我想看看master分支和我的功能分支之间的区别.我有很多从主服务器到我的功能分支的东西,并希望看到如果我将我的功能合并到主服务器中将添加的更改.
这是我的情况:
-*--*--*-----*<master>
\ \ \
1--*--*--*--2--*<feature>
Run Code Online (Sandbox Code Playgroud)
我的问题是git diff master feature似乎只显示提交号2.我想看到一个github pull请求将显示的差异,我相信这是提交的所有方式1.我注意到git cherry显示我提交的我希望看到的区别为.
谢谢你的建议.
我试图实现的布局(我认为)非常简单.
一个TextView根据内部的内容进行扩展.下面是两个按钮(确定/取消).
我可以让按钮贴在屏幕的底部,并且工作正常.但我想在TextView下面放置这些按钮.我尝试了很多不同的东西,但这是我最新的布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ScrollView android:id="@+id/Scroll"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
>
<TextView
android:id="@+id/Text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</ScrollView>
<RelativeLayout android:id="@+id/buttons"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_below="@+id/Scroll"
android:layout_above="@+id/bottom"
>
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<Button android:id="@+id/ButtonOK"
android:layout_height="80dp"
android:layout_width="fill_parent"
android:text="OK"
android:layout_weight="1"/>
<Button android:id="@+id/ButtonCancel"
android:layout_height="80dp"
android:layout_width="fill_parent"
android:text="Cancel"
android:layout_weight="1"/>
</LinearLayout>
</RelativeLayout>
<LinearLayout android:id="@+id/bottom"
android:layout_height="0px"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
最后的空线性布局是(不成功)尝试阻止视图延伸到屏幕底部...
在我尝试过的所有内容中,按钮都位于屏幕的底部,或者当TextView太大时它们会经过它们.
这是我想要做的草图:
在我的小型Android应用程序中,我有一个ViewPager3页,每个页面包含一个片段,这一切都正常FragmentStatePagerAdapter(见前面的问题).
现在对于更大的屏幕,我想保留一个ViewPager,但我希望前两个片段在同一个第一页上.
为此,我实现了我自己的PagerAdapter,这主要是工作,我试图解决的唯一问题是当我旋转屏幕时,我收到一个错误:
12-11 16:34:13.526: ERROR/AndroidRuntime(9221): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.matthieu/com.matthieu.TestActivity}: java.lang.IllegalArgumentException: No view found for id 0x7f030002 (com.matthieu:id/top_fragment) for fragment TestFragment{481a3a98 #0 id=0x7f030002}
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3815)
at android.app.ActivityThread.access$2400(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2037)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: No view found for id 0x7f030002 (com.matthieu:id/top_fragment) for fragment TestFragment{481a3a98 #0 id=0x7f030002}
at …Run Code Online (Sandbox Code Playgroud) 在子/后台进程中运行时,我无法捕获信号.
这是我简单的bash脚本:
#!/bin/bash
echo "in child"
trap "got_signal" SIGINT
function got_signal {
echo "trapped"
exit 0
}
while [ true ]; do
sleep 2
done
Run Code Online (Sandbox Code Playgroud)
当运行这个以后再做
kill -SIGINT (pid)
Run Code Online (Sandbox Code Playgroud)
一切都按预期工作,打印"被困"并退出.
现在,如果我从父脚本启动相同的脚本,如下所示:
#!/bin/bash
echo "starting the child"
./child.sh &
Run Code Online (Sandbox Code Playgroud)
然后孩子不再陷入信号......?
更改为使用SIGTERM而不是SIGINT后,它似乎正常工作......?
我的bash脚本获取了两个带文件夹的参数(存在和所有内容).
在第一个内部我想创建第二个链接
假设我有文件夹/ home/matt/a和/ home/matt/b,我调用这样的脚本:
/home/matt # ./my_script ./a ./b
Run Code Online (Sandbox Code Playgroud)
我希望看到一个指向b的符号链接
当然,只是这样做
ln -s $2 $1/link
Run Code Online (Sandbox Code Playgroud)
在脚本中不起作用...(它将创建一个链接,在内部查找./b)
这只是一个非常简单的例子,我正在寻找一个足够通用的脚本来获取不同的参数(绝对路径或相对路径......等等)
以下是我希望我的应用程序在平板电脑上执行的操作.Fragment(0)有一些菜单会显示片段(1)...(n),如下所示:
-----------------
| | | | |
| | | | |
|(0)| X | X | X |
| | | | |
| | | | |
-----------------
becomes
-----------------
| | | | |
| | | | |
|(0)|(1)| X | X |
| | | | |
| | | | |
-----------------
and then
-----------------
| | | | |
| | | | |
|(0)|(2)|(1)| X |
| | | | |
| …Run Code Online (Sandbox Code Playgroud) 我试图用红色圆形物体检测黑色背景中的圆圈.
import cv2
import cv2.cv as cv
import numpy as np
img = cv2.imread('extracted.jpg',0)
img = cv2.medianBlur(img,5)
cimg = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
circles = cv2.HoughCircles(img,cv.CV_HOUGH_GRADIENT,1,20,
param1=50,param2=30,minRadius=0,maxRadius=0)
circles = np.uint8(np.around(circles))
for i in circles[0,:]:
# draw the outer circle
cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
# draw the center of the circle
cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)
cv2.imshow('detected circles',cimg)
cv2.waitKey(0)
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)
我已经以灰度模式加载了图像,但它仍然给我一个错误
"circles = np.uint8(np.around(circles))
File "/usr/lib/python2.7/dist-packages/numpy/core/fromnumeric.py", line 2277, in around
return _wrapit(a, 'round', decimals, out)
File "/usr/lib/python2.7/dist-packages/numpy/core/fromnumeric.py", line 37, in _wrapit
result = getattr(asarray(obj),method)(*args, **kwds)
AttributeError: rint"
Run Code Online (Sandbox Code Playgroud)
由于我目前的声誉,我无法发布图片.
我正从一个存储库移动到另一个存储库,需要移植一些更改.目录结构大致相同,但文件不完全相同.
我使用'git format-patch'和'git am'或'git apply'来移植这些更改.当它工作时,生活是美好的,但当它由于一些微小的变化或文件丢失而失败时,什么也没有应用.
我可以使用--exclude过滤文件,但我真正想要的是它尽可能多地应用并告诉我哪里有冲突/失败.
我也愿意接受应用补丁或其他类似的选项.