标签: android-2.1-eclair

如何将变量传递给新的Runnable声明?

我有以下内容:

Runnable done = new Runnable()
    {
        public void run()
        {
            System.out.println("Hello");
        }
    };
Run Code Online (Sandbox Code Playgroud)

然后在我的Android活动中,我会称之为:

runOnUIThread(done);
Run Code Online (Sandbox Code Playgroud)

然后我打电话给你.但是,我希望"Hello"不要硬编码,所以我可以传入它.否则我将必须为我想要打印的每个字符串都有一个这样的声明.

(这实际上是一个android问题,但是它缩小到基本Java,所以更容易回答)

谢谢

java android runnable android-2.1-eclair

23
推荐指数
2
解决办法
3万
查看次数

android 2.1中的getExternalFilesDir替代方案

我在android 2.2上构建了一个Android应用程序,用于将文件保存到SD卡中我使用以下内容:

 context.getExternalFilesDir(null).getAbsolutePath();
Run Code Online (Sandbox Code Playgroud)

返回一个字符串,如:

 /mnt/sdcard/Android/data/com.hello.example1/files
Run Code Online (Sandbox Code Playgroud)

现在我需要让我的应用程序与android 2.1兼容,我需要使用什么方法来获取外部文件目录?


public static String sTellMeWhereToSaveMyData(Context context) 
{
        String packageName = context.getPackageName();
        File externalPath = Environment.getExternalStorageDirectory();
        File appFiles = new File(externalPath.getAbsolutePath() + "/Android/data/" + packageName+ "/");

        if (appFiles.exists() && appFiles.isDirectory()) 
        {
            return appFiles.getAbsolutePath();
        }
        else 
        {
            if(appFiles.exists())
            {
                Log.v("File Manager","not exists");
            }
            if (!appFiles.mkdir())
            {
                Log.v("File Manager","Could not create");
            }   
        }
        return appFiles.getAbsolutePath();
}
Run Code Online (Sandbox Code Playgroud)

java android android-2.1-eclair

12
推荐指数
1
解决办法
6151
查看次数

有没有办法使用Intents为新的日历事件添加提醒?

我需要支持Android 2.1及更高版本.我知道CalendarContract在Android 2.1中不可用,所以我做了以下解决方法.

Intent intent = new Intent(Intent.ACTION_EDIT)
                        .setType("vnd.android.cursor.item/event")
                        .putExtra("beginTime", beginTime.getTimeInMillis())
                        .putExtra("title", title)
                        .putExtra("description", description)
                        .putExtra("eventLocation", location)
                        .putExtra("allDay", allDay)
                        .putExtra(Intent.EXTRA_EMAIL, email );
                if(!allDay) {
                    intent.putExtra("endTime", endTime.getTimeInMillis());
                }

               startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

到目前为止,这非常有效.我已经在2.1到4.1上进行了测试.

我也想添加提醒,但是我找不到任何关于如何使用Intents的文档.有人有例子吗?我想避免为我的清单添加更多权限以便写入日历,所以如果你有一个需要的建议,我将无法使用它.

android android-2.1-eclair android-calendar

11
推荐指数
1
解决办法
1212
查看次数

了解自定义程序包的XML属性

我正在尝试使用这个优秀项目中的拖放功能:https://github.com/bauerca/drag-sort-listview/

首先,我使用GitHub上的说明添加了库.

其次,我正在尝试使用XML声明.这是我的main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:dslv="http://schemas.android.com/apk/res/com.mobeta.android.dslv"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <include layout="@layout/header"/>

    <com.mobeta.android.dslv.DragSortListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:divider="#D9D9D9"
        android:dividerHeight="2dp"
        android:listSelector="@drawable/list_selector"
        dslv:drag_enabled="true"
        dslv:drag_scroll_start="0.33"
        dslv:drag_start_mode="onDown"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

但是,Eclipse正在抛出这个错误:No resource identifier found for attribute 'drag_enabled' in package 'com.mobeta.android.dslv';同样适用于'drag_scroll_start''drag_start_mode'.

我想在更一般的层面上理解我在这里做错了什么.如果有人能为我提供使用这个库的具体帮助,我也会很感激.

android android-xml android-2.1-eclair

11
推荐指数
1
解决办法
3216
查看次数

菜单项选择的Android启动活动

我有2节课.一个将是一个基本的指令屏幕,在该屏幕上它将有一个菜单,让你去另一个班级.另一个类是MapActivity.我认为问题在于它找不到其他类.我尝试了几种不同的方式来声明找到课程的意图.这是我尝试过的最新事情:

@Override
public boolean onCreateOptionsMenu(Menu menu){        
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.mainmenu, menu);
    return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
    switch(item.getItemId()){
    case R.id.goToMap:
        Intent intent = new Intent();
        intent.setClassName(Main.this, "Map.Class");
        startActivity(intent);
        return true;            
    }
    return false;
}
Run Code Online (Sandbox Code Playgroud)

它是一个扩展Activity的基本类,map类是扩展MapActivity的基本类(会导致问题吗?).这是我的清单文件的重要部分:

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".Campus_Map"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".Main" android:label="Instructions" ></activity>
    <activity android:name=".Map" android:label="Map">
        <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        </intent-filter>
    </activity>

</application>
Run Code Online (Sandbox Code Playgroud)

编辑:当看到LogCat来弄清楚发生了什么时,我得到一个java.lang.NoClassDefFoundError和一些其他消息说"类的链接./Map失败","找不到类./Map引用自方法./Main.run"和"VFY:无法解析const-class 37"

android menu android-intent android-2.1-eclair android-activity

10
推荐指数
1
解决办法
3万
查看次数

即使数据流量处于活动状态,ConnectivityManager getActiveNetworkInfo()也始终为null

我正在研究一个Android项目,我需要检查互联网连接.我搜索了网络,我在stackoverflow上找到了解决方案.但是,我在检查互联网状态时遇到了问题.我已经到处搜索,但我找不到解决问题的方法.

这是清单:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
Run Code Online (Sandbox Code Playgroud)

以下是检查互联网是否已连接的代码:

cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
if (cm != null) {
NetworkInfo ni = cm.getActiveNetworkInfo();
isConnected = (ni != null && ni.isAvailable() && ni.isConnected()) ? true : false;
}
Run Code Online (Sandbox Code Playgroud)

问题是即使TYPE_MOBILE数据流量处于活动状态,ni变量也始终为空.要访问运营商互联网流量,这是正确的测试方式吗?或者我必须使用TelephonyManager?这很奇怪,因为我使用了getNetworkInfo()[]并对其进行了调试,TYPE_MOBILE的HSPA出现在那里,但isAvalaible总是false而getState()= DISCONNECTED.但是我启用了运营商的数据流量并且正在工作(在其他应用程序中)

[编辑]:顺便说一下我直接在设备中测试它而不是在模拟器中:).

提前致谢.问候.

null android connectivity android-2.1-eclair android-wireless

8
推荐指数
1
解决办法
9711
查看次数

Android:同时翻译和旋转动画

我想以编程方式同时显示两个动画而不是XML文件.它应该ROTATE和TRANSLATE 我该怎么做?

请建议我一些方法??????

这是ma代码:>

ImageView snowImg1 = (ImageView) findViewById(R.id.snowimg1);
        snowImg1.setVisibility(0);
        ImageView snowImg2 = (ImageView) findViewById(R.id.snowimg2);
        snowImg2.setVisibility(0);
        ImageView snowImg3 = (ImageView) findViewById(R.id.snowimg3);
        snowImg3.setVisibility(0);
        ImageView snowImg4 = (ImageView) findViewById(R.id.snowimg4);
        snowImg4.setVisibility(0);
        ImageView snowImg6 = (ImageView) findViewById(R.id.snowimg6);
        snowImg6.setVisibility(0);
        ImageView snowImg5 = (ImageView) findViewById(R.id.snowimg5);
        snowImg5.setVisibility(0);

        View snowArray[] = {snowImg1, snowImg2, snowImg3, snowImg4, snowImg5, snowImg6};

        Animation snowMov7 = new RotateAnimation(0,360, Animation.RELATIVE_TO_SELF,0.5f , Animation.RELATIVE_TO_SELF,0.5f );
        snowMov7.setRepeatCount(Animation.INFINITE);
        Animation snowMov1 =  new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.1f, Animation.RELATIVE_TO_PARENT, 0.3f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.9f);
        snowMov1.setDuration(10000);
        Animation snowMov2 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.3f, Animation.RELATIVE_TO_PARENT, …
Run Code Online (Sandbox Code Playgroud)

animation android-2.1-eclair rotateanimation translate-animation

8
推荐指数
1
解决办法
8744
查看次数

如何将结构化数据添加到新联系人Intent

我需要支持Android 2.1及更高版本.

谷歌发布了一个如何使用ContactsContract的例子,但其中一些使用了从API级别11开始可用的东西,所以我需要即兴发挥,但我被卡住了.

所以,我有这个:

            String firstName = contactProperties.get("firstName");
            String lastName = contactProperties.get("lastName");
            String phone = contactProperties.get("phone");
            String email = contactProperties.get("email");
            String company = contactProperties.get("company");
            String postal = contactProperties.get("street") + ", " + contactProperties.get("city") + ", " + contactProperties.get("state") + " " + contactProperties.get("zip") + " " + contactProperties.get("country");

            // Creates a new intent for sending to the device's contacts application
            Intent insertIntent = new Intent(ContactsContract.Intents.Insert.ACTION);

            // Sets the MIME type to the one expected by the insertion activity
            insertIntent.setType(ContactsContract.RawContacts.CONTENT_TYPE);
            insertIntent.putExtra(ContactsContract.Intents.Insert.NAME, …
Run Code Online (Sandbox Code Playgroud)

android contactscontract android-2.1-eclair

8
推荐指数
1
解决办法
1665
查看次数

如何强制GridView使用整个屏幕(无论显示尺寸如何)?

我有以下布局文件,后面有一个GridViewImageView后面的布局文件.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#FFFFFF">
    <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|right"
            android:layout_marginRight="-70dp"
            android:layout_marginBottom="-50dp"
            android:src="@drawable/s_background"/>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent">
        <GridView xmlns:android="http://schemas.android.com/apk/res/android"
                  android:id="@+id/gridview"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:columnWidth="90dp"
                  android:numColumns="auto_fit"
                  android:verticalSpacing="10dp"
                  android:horizontalSpacing="10dp"
                  android:stretchMode="columnWidth"
                  android:gravity="center"/>
    </LinearLayout>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

这是我用于网格的每个"单元格"中的实际项目的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
    <TextView
            android:id="@+id/cardInGrid"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:singleLine="true"
            android:textSize="40sp"
            android:textColor="#660099"
            android:typeface="serif"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我现在在设备上看到以下内容:

在此输入图像描述

是否有任何方法可以使GridView中的每个项目更大,所以它适合屏幕的大小,我在显示屏的底部没有未使用的空白区域?

这在模拟器上工作正常,但在设备上屏幕分辨率更高,因此在底部获得空白区域.

非常感谢

android gridview android-2.0-eclair android-2.1-eclair

7
推荐指数
2
解决办法
1万
查看次数

JavaScript 中的 URI 验证

仅使用 JavaScript 来验证 URI 是否适用于 Android 的稳健方法是什么(不必是正则表达式,是吗?)

也就是Android SDK端的校验不是用Java来做的;它是在使用 JavaScript 的网页中完成的。

编辑:通过“适用于 Android”,我的意思是 Android 可以找到一个使用该 URI 响应 Intent 的 Activity。

javascript android-2.1-eclair

7
推荐指数
1
解决办法
4274
查看次数