我想打开外部存储目录路径以编程方式保存文件.我试过但没有获得SD卡路径.我怎么能这样做?有什么解决方案吗?
private File path = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "");
Run Code Online (Sandbox Code Playgroud)
要么
private File path = new File(Environment.getExternalStorageDirectory() + "");
Run Code Online (Sandbox Code Playgroud)
我尝试从两个方法上面获取路径,但两者都指向内部存储器.
当我们打开存储器时,如果sdcard没有,它将显示如下 -
设备存储和SD存储卡.
我想通过编码获得sd内存路径.我已经在清单中给予了许可 -
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Run Code Online (Sandbox Code Playgroud) 我收到以下错误:
> 02-06 23:10:24.104: E/dalvikvm(912): Could not find class
> 'android.support.v4.app.FragmentActivity', referenced from method
> com.robotium.solo.Waiter.getSupportFragment
Run Code Online (Sandbox Code Playgroud)
当我运行一个项目时,我正在使用Coursera上的Android手持系统的移动应用程序编程.我相信这个错误与我的输出答案被认为是不正确有关.如果我可以修复此错误,我可以修复输出.
我最初运行测试时没有最新版本的Android支持存储库(未安装),但我现在根据SDK Manager(v4)拥有最新版本的Android支持存储库,甚至重新启动了Eclipse和模拟器,但我仍然得到错误.
如何根据SDK安装LogCat声明ASR不存在?
即使屏幕被锁定,如何在设备上启动活动.我尝试如下,但它不起作用.
广播接收器:
Intent alarmIntent = new Intent("android.intent.action.MAIN");
alarmIntent.setClass(context, Alarm.class);
alarmIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
alarmIntent.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED +
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD +
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON +
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
context.startActivity(alarmIntent);
Run Code Online (Sandbox Code Playgroud) 在我的应用程序按钮单击我想改变imageview的大小.当我点击一个按钮我想增加5的视图尺寸(每个宽度和高度).点击其他按钮我想减小尺寸.i试过这个.我怎么能这样做?下面是code.its无法正常工作
public void increase(View v)
{
int height=imageView.getHeight();
int width=imageView.getWidth();
imageView.getLayoutParams().height = height+5;
int h=imageView.getHeight();
System.out.println("hhhhhhhhhh,,,,,,,,,,"+h);
System.out.println("width n hight..."+width+"and"+height);
}
Run Code Online (Sandbox Code Playgroud) 在我的自定义列表视图中,项目正在重复.项目的位置对于所有项目是相同的.代码如下
ListAdapter.java-
public class ListAdapter extends BaseAdapter{
private List<String> mName;
private List<Drawable> mIcon;
private Context mContext;
public ListAdapter(Context mContext, List<String> Name, List<Drawable> Icon) {
this.mContext=mContext;
this.mName=Name;
this.mIcon=Icon;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return mName.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(final int position, View v, ViewGroup parent) { …
Run Code Online (Sandbox Code Playgroud) 我想在地图视图中显示位置,地图大小应为200X200.我尝试在mapview中加载地图但是在点击方向指针2到3次显示正确的地图但没有移动之后它没有正确显示.
但是,当我使用完整大小的屏幕显示地图而不更改任何代码时,它正确加载.如何在小视图中显示相同的内容?
地图代码 -
static GoogleMap map;
private MapView mapView;
MapsInitializer.initialize(getApplicationContext());
switch (GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext()) )
{
case ConnectionResult.SUCCESS:
//Toast.makeText(getActivity(), "SUCCESS", Toast.LENGTH_SHORT).show();
mapView = (MapView)findViewById(R.id.map);
mapView.onCreate(savedInstanceState);
// Gets to GoogleMap from the MapView and does initialization stuff
if(mapView!=null)
{
map = mapView.getMap();
map.getUiSettings().setMyLocationButtonEnabled(false);
map.setMyLocationEnabled(true);
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(location, 10);
map.animateCamera(cameraUpdate);
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
break;
case ConnectionResult.SERVICE_MISSING:
//Toast.makeText(getActivity(), "SERVICE MISSING", Toast.LENGTH_SHORT).show();
break;
case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
//Toast.makeText(getActivity(), "UPDATE REQUIRED", Toast.LENGTH_SHORT).show();
break;
default: Toast.makeText(getApplicationContext(), GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext()), Toast.LENGTH_SHORT).show();
}
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(location).zoom(10).bearing(0) // Sets the orientation …
Run Code Online (Sandbox Code Playgroud) 我正在尝试从android sqlite数据库中检索数据但是它的givine异常没有这样的列:
c=db.rawQuery("Select Name from stud Where Address="+a,null);
Run Code Online (Sandbox Code Playgroud)
07-04 18:07:00.888: I/Database(648): sqlite returned: error code = 1, msg = no such column: aa
07-04 18:07:00.910: D/AndroidRuntime(648): Shutting down VM
07-04 18:07:00.910: W/dalvikvm(648): threadid=1: thread exiting with uncaught exception (group=0x40015560)
07-04 18:07:00.948: E/AndroidRuntime(648): FATAL EXCEPTION: main
07-04 18:07:00.948: E/AndroidRuntime(648): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my.StudentInfoManagement/com.my.StudentInfoManagement.ListData}: android.database.sqlite.SQLiteException: no such column: aa: , while compiling: Select Name from stud Where Address=aa
07-04 18:07:00.948: E/AndroidRuntime(648): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) …
Run Code Online (Sandbox Code Playgroud) 我已经创建了地图actvity.But它没有在mapview.just上显示地图显示空白块.有什么办法吗?
activity_main.xml-
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
Run Code Online (Sandbox Code Playgroud)
活动代码 -
package com.example.googlemap;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Run Code Online (Sandbox Code Playgroud)
清单文件 -
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<permission
android:name="com.example.googlemap.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<meta-data
android:name="com.google.android.maps.v2.AIzaSyDRv4Ul_9iPW-roHIsc8EuxKwkRN8jWivs"
android:value="AIzaSyDRv4Ul_9iPW-roHIsc8EuxKwkRN8jWivs" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<!--
The following two permissions are not required to use
Google Maps Android API v2, but are recommended.
--> …
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我只使用列表视图来显示图像和文本.这是我的适配器编码
ArrayAdapter<String> adapter=new ArrayAdapter<String>(MainActivity.this, R.layout.list_item, R.id.name, arrList);
listProductCategories.setAdapter(adapter);
listProductCategories.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
ImageView imgview = (ImageView) view.findViewById(R.id.iv_listitem);
//And change its background here
imgview.setBackgroundResource(R.drawable.fail);
String name = ((TextView) view.findViewById(R.id.name))
.getText().toString();
Toast.makeText(MainActivity.this, "" + name, 10).show();
}
});
Run Code Online (Sandbox Code Playgroud)
这是上面编码的屏幕截图.
这里我突出显示所选列表项.但是我的输出显示了许多列表视图项目图像背景中的一些已更改..
请给我一个解决方案....
<ImageView android:id="@+id/iv_listitem"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center_vertical"
android:background="@drawable/next_unselect"
android:focusable="false" />
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:focusable="false"
android:text="TextView"
android:textColor="#003366" />
Run Code Online (Sandbox Code Playgroud)
项目清单-
<ImageView android:id="@+id/iv_listitem" android:layout_width="20dp" android:layout_height="20dp" android:layout_gravity="center_vertical" android:background="@drawable/next_unselect" android:focusable="false" />
<TextView android:id="@+id/name" android:layout_width="match_parent" android:layout_height="wrap_content" …
Run Code Online (Sandbox Code Playgroud) 如何在android中锁定或打开屏幕?我尝试在广播接收器中使用SCREEN_OFF和SCREEN_ON操作,但它无法正常工作.
public void onReceive(Context context, Intent intent) {
Log.d("XYZ", "Screen ON/OFF");
Toast.makeText(context, "screen",10000).show();
if(intent.getAction().equals(Intent.ACTION_SCREEN_ON))
{
.......
}
}
Run Code Online (Sandbox Code Playgroud)
在活动中,我已注册广播,如 -
屏幕是我的广播接收器的对象
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
mContext.registerReceiver(screen, filter);
Run Code Online (Sandbox Code Playgroud) android ×10
google-maps ×2
listview ×2
baseadapter ×1
eclipse ×1
height ×1
imageview ×1
java ×1
layout ×1
mapactivity ×1
screen-lock ×1
screen-off ×1
sd-card ×1
width ×1