我在我的应用程序中尝试做的是让用户从他手机的图库中选择一张图片(不想只获取图库图片,还允许用户选择他们选择的应用程序).我正在使用的代码如下:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), 1);
Run Code Online (Sandbox Code Playgroud)
EXTRA_LOCAL_ONLY仅告知接收应用程序它应该只返回存在的数据.
添加intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);上面的代码后,它隐藏了谷歌驱动器应用程序和picasa应用程序,但仍显示谷歌照片(这些照片不在我的设备中.)
此外,我只为本地文件尝试了Android图像选择器,但它隐藏了所有具有远程图像的应用程序,不包括谷歌照片.
注意:所有图像路径都是正确的,因为我在KitKat上的Android Gallery为Intent.ACTION_GET_CONTENT返回不同的Uri(感谢@Paul Burke),但我不想选择互联网/远程图像.
所以我的问题是否有任何方法隐藏谷歌照片应用程序,只从本地设备选择图像.或谷歌照片是否属于Intent.EXTRA_LOCAL_ONLY
以下代码始终为位置管理器返回空指针异常。
我的 GPSTracker 类私有 final Context mContext;
// flag for GPS status
boolean isGPSEnabled = false;
// flag for network status
boolean isNetworkEnabled = false;
// flag for GPS status
boolean canGetLocation = false;
Location location; // location
double latitude; // latitude
double longitude; // longitude
// The minimum distance to change Updates in meters
private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; // 10 meters
// The minimum time between updates in milliseconds
private static final long MIN_TIME_BW_UPDATES = 1000 …Run Code Online (Sandbox Code Playgroud) 我正在尝试从服务器获取 JSON 值。我不知道我的代码有什么问题。我正在使用AsyncTask,这是我的代码doInBackground
代码:
@Override
protected Void doInBackground(List<String>... articlesRec) {
for (List<String> articlesPostValue : articlesRec) {
event = articlesPostValue.get(0);
category = articlesPostValue.get(1);
paged = articlesPostValue.get(2);
deviceID = articlesPostValue.get(3);
}
List<NameValuePair> articlesPostValues = new ArrayList<NameValuePair>();
articlesPostValues.add(new BasicNameValuePair("_event", event));
articlesPostValues.add(new BasicNameValuePair("cat", category));
articlesPostValues.add(new BasicNameValuePair("paged", paged));
articlesPostValues.add(new BasicNameValuePair("_deviceID", deviceID));
HttpClient hc = new DefaultHttpClient();
HttpPost hp = new HttpPost(AutoLifeConstants.BASE_URL);
try {
hp.setEntity(new UrlEncodedFormEntity(articlesPostValues));
// Execute HTTP Post Request
HttpResponse response = hc.execute(hp);
String result = EntityUtils.toString(response.getEntity());
String jsontext = new …Run Code Online (Sandbox Code Playgroud) 我想循环遍历sqlite数据库if if(johnny)是否存在于数据库中,但我的代码不起作用
if(!cursor.isAfterLast())
{
do
{
for(int i = 0; i<cursor.getCount(); i++)
{
if("johnny" == cursor.getString(1))
{
Toast.makeText(getApplicationContext(), "string found!!! =)", Toast.LENGTH_LONG).show();
}
}
}
while (cursor.moveToNext());
}
cursor.close();
}
Run Code Online (Sandbox Code Playgroud) 我想使用 xml 在 android 中创建全宽按钮。这是我的代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/menu"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ImageView
android:id="@+id/imageView2"
android:layout_width="180dp"
android:layout_height="180dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:src="@drawable/manulogo" />
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawableLeft="@android:drawable/btn_star_big_on"
android:layout_centerHorizontal="true"
android:layout_marginTop="220dp"
android:text="Drawable left"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)