当我尝试在我的Android 4.4 (Kitkat)上启用GPS时,我的Android应用程序崩溃了.它一直运行良好,直到Android 4.3.我正在使用以下代码打开GPS
Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", true);
this.sendBroadcast(intent);
Run Code Online (Sandbox Code Playgroud)
在我的Log Cat中给出安全例外.
我的LogCat详细信息如下: -
11-27 12:47:37.410: E/AndroidRuntime(3818): Caused by: java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.location.GPS_ENABLED_CHANGE from pid=3818, uid=10084
11-27 12:47:37.410: E/AndroidRuntime(3818): at android.os.Parcel.readException(Parcel.java:1461)
11-27 12:47:37.410: E/AndroidRuntime(3818): at android.os.Parcel.readException(Parcel.java:1415)
11-27 12:47:37.410: E/AndroidRuntime(3818): at android.app.ActivityManagerProxy.broadcastIntent(ActivityManagerNative.java:2373)
11-27 12:47:37.410: E/AndroidRuntime(3818): at android.app.ContextImpl.sendBroadcast(ContextImpl.java:1127)
11-27 12:47:37.410: E/AndroidRuntime(3818): at android.content.ContextWrapper.sendBroadcast(ContextWrapper.java:365)
11-27 12:47:37.410: E/AndroidRuntime(3818): at com.sus.SUSV7_1.Activity.Splash_ScreenActivity.turnGPSOn(Splash_ScreenActivity.java:66)
11-27 12:47:37.410: E/AndroidRuntime(3818): at com.sus.SUSV7_1.Activity.Splash_ScreenActivity.onCreate(Splash_ScreenActivity.java:26)
Run Code Online (Sandbox Code Playgroud)
当我评论代码时,它的工作正常.是否有任何特定参数可在Android 4.4上手动启用GPS.
我正在创建gridview来显示图像.即使我设置垂直和水平间距,静止图像也会相互重叠.为什么会这样?以及如何解决这个问题?你可以在图像中看到这一点.
我的代码:
public class Images extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.images);
GridView gridView = (GridView) findViewById(R.id.grid_view);
gridView.setAdapter(new ImageAdapter(this));
gridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Intent i = new Intent(getApplicationContext(), FullImageActivity.class);
i.putExtra("id", position);
startActivity(i);
}
});
}
public class ImageAdapter extends BaseAdapter {
private Context mContext;
int width, height;
public Integer[] mThumbIds = {
R.drawable.radhe, R.drawable.radhe,
R.drawable.radhe, R.drawable.radhe,
R.drawable.radhe, R.drawable.radhe,
R.drawable.radhe, R.drawable.radhe,
R.drawable.radhe
};
// Constructor
public …Run Code Online (Sandbox Code Playgroud) 我对android有疑问.我正在使用布局 - 土地用于横向视图和布局 - 大型平板电脑,当我使用平板电脑布局将由android系统,布局 - 土地或大?在什么基础上需要布局.请解释.
谢谢.
我有一个应用程序需要在有人退出其主要活动时调用完成(所以我不希望它被暂停),即使按下home活动也必须完成,处理这个当前我只是调用finish()我的onPause()方法,因为一切完成片段它很好地工作,并没有给出任何稳定性问题.
我唯一的问题是我无法处理onPause()以前调用的方向更改onConfigurationChanged()(允许我在发生旋转时禁用此行为).
我可以创建一个服务来处理这个,但它的方式复杂.
任何的想法?
我想创建活动背景音乐,但MediaPlayer不是重复播放:(为什么我MediaPlayer不循环?
有我的代码:
MediaPlayer mediaPlayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.tersetetete);
mediaPlayer = new MediaPlayer();
mediaPlayer.setVolume(8f, 8f);
mediaPlayer.setLooping(true);
mediaPlayer = MediaPlayer.create(this, R.raw.fon);
mediaPlayer.start();
}
Run Code Online (Sandbox Code Playgroud) 我试图接收(BroadcastReceiver关闭)关闭,启动和重新启动的操作.
我搜索了很多,但我无法弄清楚Intent.ACTION_REBOOT和之间的区别是什么Intent.ACTION_SHUTDOWN,以及什么时候被Intent.ACTION_REBOOT调用(或者我应该说"广播").
可以请有人为我解释一下吗?
我想把我的按钮移动到另一个触摸的位置.我的意思是,如果用户触摸一个按钮并通过触摸转到另一个地方,则按钮会移动.我为其中一个按钮编写了这个代码,但是当我触摸一个按钮时,三个按钮移动以及一个按钮无法向右或向左移动,当我移动到屏幕顶部时,图像按钮的一部分被删除!
问题是什么?我该如何解决这个问题?我想在android +2.2中运行这个程序
onButton.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
switch(event.getAction()){
case MotionEvent.ACTION_MOVE:
RelativeLayout.LayoutParams relativeLayout=(RelativeLayout.LayoutParams) oneButton.getLayoutParams();
int x=(int)event.getRawX();
int y=(int)event.getRawY();
relativeLayout.leftMargin=x-50;
relativeLayout.rightMargin=x-50;
relativeLayout.topMargin=y-50;
relativeLayout.bottomMargin=y-50;
oneButton.setLayoutParams(relativeLayout);
break;
default:
break;
}
return true;
}
});
Run Code Online (Sandbox Code Playgroud)
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/img"
android:src="@drawable/root"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:scaleType="fitXY"/>
<ImageButton
android:id="@+id/btnOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="35dip"
android:layout_alignParentTop="true"
android:layout_marginTop="70dip"
android:src="@drawable/oneButton"
android:background="@null"
android:visibility="invisible"/>
<ImageButton
android:id="@+id/btnTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="35dip"
android:layout_alignParentTop="true"
android:layout_marginTop="70dip"
android:src="@drawable/twoButton"
android:background="@null"
android:visibility="invisible"/>
<ImageButton …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,我试图定期获取用户位置并发送到服务器.我有一个附加到AlarmManager每分钟执行的服务(用于测试).该服务正确找到用户位置并注销GPS协议.一旦有GPS锁定,我就取消位置请求并停止服务.当我要求更新位置时,我开始Handler执行20秒后执行,这Handler将删除位置更新并Service在没有锁定的情况下停止.这一切都有效.
下面是使用Service该类工作的代码.
public class TrackingService extends Service {
private static final String TAG = TrackingService.class.getSimpleName();
LocationManager mlocManager;
LocationListener mlocListener;
NfcScannerApplication nfcscannerapplication;
String carerID;
Handler endServiceHandler;
Runnable endServiceRunnable;
@Override
public void onCreate() {
super.onCreate();
nfcscannerapplication = (NfcScannerApplication) getApplication();
mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
mlocListener = new MyLocationListener();
Log.e(TAG, "Service created and location manager and listener created");
}
@Override
public void onDestroy() {
super.onDestroy();
Log.e(TAG, "in onDestroy in LocationService class");
mlocManager.removeUpdates(mlocListener);
}
@Override …Run Code Online (Sandbox Code Playgroud) 我必须将A和B写入编辑文本的按钮.如果edittext中有什么内容,我怎么能用"Del"按钮删除最后一个字母?我的布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<Button
android:id="@+id/buttonb"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/buttona"
android:text="@string/buttonb"
android:textSize="50sp"
android:textStyle="bold" />
<Button
android:id="@+id/buttona"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="@string/buttona"
android:textSize="50sp"
android:textStyle="bold" />
<Button
android:id="@+id/buttondel"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="@string/buttondel"
android:textSize="50sp"
android:textStyle="bold" />
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:ems="58"
android:textSize="20sp"
android:textStyle="bold"
android:inputType="text" >
<requestFocus />
</EditText>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
而我的java:
package com.koostamas.keyboard;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.app.Activity;
public class MainActivity extends Activity implements OnClickListener {
Button buttona, buttonb;
EditText …Run Code Online (Sandbox Code Playgroud) 我正在玩Android版Google Play Services 4.4的新StreetView功能(链接),我想知道是否有任何方法/可能性来检查是否有任何给定位置的'view'/ foto材料.当我加载一个未被StreetView覆盖的位置时,streetViewPanorama.setPosition(someLatLng);
我只得到一个黑屏.有事先检查吗?
android ×10
gps ×1
intentfilter ×1
location ×1
onpause ×1
orientation ×1
reboot ×1
service ×1
shutdown ×1
touch ×1