我想在特定间隔(比如说30分钟)之后捕获android设备的当前位置(经度和纬度).我的类(或服务??不确定要使用什么)将LocationManagerListener在设备启动完成时开始监听.实现这个的最佳方法是什么?我们如何locationChanged()在这种情况下使用方法?
这是我认为它可以去:
监听启动完成事件并设置警报服务:
public class OnBootReceiver extends BroadcastReceiver {
private static final int PERIOD=1800000; // 30 minutes
@Override
public void onReceive(Context context, Intent intent) {
AlarmManager mgr=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent i=new Intent(context, OnAlarmReceiver.class);
PendingIntent pi=PendingIntent.getBroadcast(context, 0,
i, 0);
mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime()+60000,
PERIOD,
pi);
}
}
Run Code Online (Sandbox Code Playgroud)
监听警报服务并启动位置捕获类或服务:
public class OnAlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
WakefulIntentService.acquireStaticLock(context);
context.startService(new Intent(context, locationCapture.class));
or
new locationCapture().classmethod();
}
}
Run Code Online (Sandbox Code Playgroud)
我不确定locationCapture应该如何实施课程.它应该是普通的Java类还是Service类?
任何帮助将不胜感激.
当我在模拟器上运行android项目时,模拟器启动但是在我的eclipse中有一段时间后控制台说:
emulator-5554 disconnected! Cancelling 'com.and.test.pahse1.Phase1AndEngineActivity activity launch'!
Run Code Online (Sandbox Code Playgroud)
这是什么问题?还有一件事我想提到的是,当我运行项目时,它要求选择网络摄像头,当我做取消确定或应用然后模拟器运行.
事情就是这样:我想以编程方式添加一些图像.图像应当必须具有topMargin的5dip除了第一图像,在一个LinearLayout具有一个vertical orientation方式.在代码段下方:
LinearLayout body = (LinearLayout) findViewById(R.id.body);
for (int i = 1; i <= 4; i++) {
ImageView img = new ImageView(this);
MarginLayoutParams lp = new MarginLayoutParams(-2, -2);
img.setImageResource(R.drawable.image);
if (i != 1) {
lp.setMargins(0, 5, 0, 0);
}
img.setLayoutParams(lp);
body.addView(img);
body.requestLayout();
}
Run Code Online (Sandbox Code Playgroud)
通过运行程序,我可以看到4个图像(这里)逐个垂直对齐,但没有topMargin(如代码中所示5dip).body是id的LinearLayout.这是以下XML部分:
<LinearLayout
android:id="@+id/body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#901b0e08"
android:orientation="vertical"
android:paddingLeft="6dp"
android:paddingRight="8dp" >
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我不知道这里出了什么问题.
谢谢.
我正在开发Android 2.1上的任务管理器.我想在单击重置按钮到当前日期和时间时重置日期和时间.帮我处理代码..
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final EditText next = (EditText) findViewById(R.id.editText1);
final Button sub = (Button) findViewById(R.id.button1);
final Button res = (Button) findViewById(R.id.button2);
final DatePicker dp= (DatePicker) findViewById(R.id.datePicker1);
final TimePicker tp = (TimePicker) findViewById(R.id.timePicker1);
res.setOnClickListener(new View.OnClickListener() {
public void onClick(final View view) {
next.setText("");
dp.refreshDrawableState();
}
});
}}
Run Code Online (Sandbox Code Playgroud) 我正在研究一个分析JAR文件的封闭源Java应用程序.由于java可以很容易地反编译,并且混淆真的不是什么大问题,我想提供一个在我的服务器上执行应用程序的在线服务,并返回它的结果,就像这里的fernflower:www.reversed-java.com/fernflower /.
问题是,我担心这是一个灾难的秘诀我的应用程序加载服务器上的任何可能有害的罐子,即使我从来没有运行罐子.我正在做的就是使用URLClassLoader和JarInputStream加载它们.
我正在加载的jar可以覆盖原始应用程序中的类,以便执行恶意代码或搞乱我的程序吗?
动态加载罐子有哪些风险?
我正在创建自定义ViewGroup,其中我使用的onLayout方法,我调用它addViewInLayout(),ViewGroup但它View只是水平添加.
如何强制它View像ListViewAndroid 一样垂直添加
寻求帮助.
我想导入 org.eclipse.ui.PlatformUI,但找不到JAR包含它的内容?
我是Eclipse rcp的新手.如果有人给我一个提示,将非常感激.
我在Eclipse中有一个Java项目,类MainClass中包含main方法:
com.nik.mypackage.
Run Code Online (Sandbox Code Playgroud)
该项目还引用了两个外部库,我将其复制lib到Eclipse 中的文件夹中,然后使用ADD JAR函数添加到构建路径中.图书馆正在one.jar和two.jar
该库lib位于eclipse 中的文件夹中,并添加到构建路径中.
我想JAR使用ant脚本创建应用程序的可执行文件.这样用户就可以使用命令访问我的应用程序:
c:>java -jar MyProject-20111126.jar
Run Code Online (Sandbox Code Playgroud)
我知道Eclipse插件直接将java应用程序导出为runnable JAR.但我想学习ant和构建过程,因此手动想要创建build.xm.
我正在一个应用程序中工作,我必须从Facebook获取所有朋友列表.
我已经实现了这样的代码:
Facebook mFacebook = new Facebook("141118172662401");
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(mFacebook);
Bundle params = new Bundle();
params.putString("fields", "name,id");
mAsyncRunner.request("me/friends", params, "GET", new FriendListRequestListener(), null);
}
});
}
public class FriendListRequestListener {
public void onComplete(final String response) {
_error = null;
try {
JSONObject json = Util.parseJson(response);
final JSONArray friends = json.getJSONArray("data");
FacebookFriendsActivity.this.runOnUiThread(new Runnable() {
JSONObject data;
public void run() {
try{
try {
data = Util.parseJson(response);
} catch (FacebookError e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JSONArray …Run Code Online (Sandbox Code Playgroud) 我不确定我做错了什么但是当我设置我的Nexus以使用eclipse进行调试时我在控制台中收到错误说
[2011-12-27 21:48:31 - DeviceMonitor]无法开始监控0146BF5417006010
然后我adb通过Android平台工具/ adb.exe 运行设备,我的设备显示为"离线".
我尝试过以下方法:
在旁注上我确实以前在我的Droid和Droid 3上工作过
任何帮助,将不胜感激.
我正在研究地图应用程序,并且根据要求我需要为单个区域显示单个引脚,即使它在完全缩小时有多个用户坐标但是当它放大到地图时我应该将所有引脚显示为按其坐标.我在下面举例说明了我的问题.我在这个城市有纽约市我在mapview上有100个引脚当我从我的地图缩小时它应该只显示100个引脚位置上的一个注释引脚但是当我放大时它应该再显示100个引脚在地图上.有谁知道这件事.我需要建议.请注意,除了我当前的位置,我从Web服务获取所有位置.这不应该影响应用程序,因此应用程序不应该变慢.
请提出一些解决方案.
我在我的数据库中存储文件路径:
该
selecteddestinationfilepath = selectedPfile.getPath();
.
.
.
state.execute("INSERT INTO "+tablename+" (filename,filepath) VALUES ('"+theselecteddestinationname+"','"+theselecteddestinationfilepath+"')");
Run Code Online (Sandbox Code Playgroud)
但是当它存储到数据库中时,它会丢弃所有的"\"
而不是D:\Programs\Rynmag181 -TFC
它D:ProgramsRynmag181 -TFC
我该如何解决这个问题?