GVKun编程网logo

使用Android 4.0(ICS)内容提供商创建日历(android risc-v)

6

本文的目的是介绍使用Android4.0(ICS)内容提供商创建日历的详细情况,特别关注androidrisc-v的相关信息。我们将通过专业的研究、有关数据的分析等多种方式,为您呈现一个全面的了解使用

本文的目的是介绍使用Android 4.0(ICS)内容提供商创建日历的详细情况,特别关注android risc-v的相关信息。我们将通过专业的研究、有关数据的分析等多种方式,为您呈现一个全面的了解使用Android 4.0(ICS)内容提供商创建日历的机会,同时也不会遗漏关于Android 4“没有找到内容提供商或许可撤销”、android – 从内容提供商URI查看意图?、android – 多个应用使用相同的内容提供商、android – 如何使用内容提供者添加限制子句的知识。

本文目录一览:

使用Android 4.0(ICS)内容提供商创建日历(android risc-v)

使用Android 4.0(ICS)内容提供商创建日历(android risc-v)

我正在尝试使用ICS的新日历内容提供程序创建日历.由于日历创建只能在SyncAdapter中完成,我创建了一个:

public class CalendarSyncAdapter extends AbstractThreadedSyncAdapter 
{

    public CalendarSyncAdapter(Context context,boolean autoInitialize)
    {
        super(context,autoInitialize);
    }

    @Override
    public void onPerformSync(Account account,Bundle extras,String authority,ContentProviderClient provider,SyncResult syncResult)
    {
        Log.i( Debug.TAG,"onPerformSync()" );
    }

    public void doCreateCalendar( Account account )
    {
            ContentResolver cr = getContext().getContentResolver();

            ContentValues values = new ContentValues();
            values.put(Calendars.ACCOUNT_NAME,account.name);
            values.put(Calendars.ACCOUNT_TYPE,account.type);
            values.put(Calendars.NAME,"newesttest");
            values.put(Calendars.CALENDAR_disPLAY_NAME,"newestTest");
            values.put(Calendars.CALENDAR_COLOR,0xFFFFFFFF);
            values.put(Calendars.CALENDAR_ACCESS_LEVEL,Calendars.CAL_ACCESS_OWNER );
            values.put(Calendars.OWNER_ACCOUNT,account.name);

            values.put(Calendars.SYNC_EVENTS,1);
            values.put(Calendars.VISIBLE,1);

            Uri creationUri = asSyncAdapter( Calendars.CONTENT_URI,account.name,account.type );
            Uri created = cr.insert( creationUri,values );
            long id = Long.parseLong( created.getLastPathSegment() );

            Log.i( Debug.TAG,"Calendar created: " + id + " - " + created );
    }

    private Uri asSyncAdapter( Uri uri,String account,String accountType )
    {
        return uri.buildUpon()
        .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER,"true")
        .appendQueryParameter(Calendars.ACCOUNT_NAME,account)
        .appendQueryParameter(Calendars.ACCOUNT_TYPE,accountType).build();
    }
}

但它并不像我到处看到的那样在服务中运行,因为我想要的只是使用它来插入新的日历.不需要在服务中运行吗?似乎不是.

无论如何,我在我的Activity中实例化它并调用我的方法:

public void createCalendar( View v )
{
    m_syncAdapter.doCreateCalendar( this,m_account );
}

它成功执行,没有投诉,但它返回的URI始终是相同的.当我为行ID解析它时,它始终是12.当我查看我的日历时,没有什么新东西.

在我的清单中,我有一切设置:
    
    

...

<application

...

    <activity android:name="Setup" android:label="@string/activity_title_setup">
        <intent-filter>
            <action android:name="android.content.SyncAdapter" />
        </intent-filter>
        <Meta-data android:name="android.content.SyncAdapter" android:resource="@xml/calendar_sync_adapter" />
    </activity>

而calendar_sync_adapter.xml:

<?xml version="1.0" encoding="utf-8"?>
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
   android:contentAuthority="com.android.calendar"
   android:accountType="com.google"
   android:userVisible="true"
/>

所以不确定我在这里做错了什么.但这是我执行时在日志中看到的:

02-17 16:43:07.783: I/ActivityManager(184): Start proc com.android.providers.calendar for content provider com.android.providers.calendar/.CalendarProvider2: pid=20132 uid=10008 gids={3003,1015}
02-17 16:43:07.806: I/ActivityThread(20132): Pub com.android.calendar: com.android.providers.calendar.CalendarProvider2
02-17 16:43:07.869: I/ActivityManager(184): Start proc com.google.android.calendar for service com.google.android.calendar/com.google.android.syncadapters.calendar.CalendarSyncAdapterService: pid=20145 uid=10007 gids={3003}
02-17 16:43:07.900: I/ActivityThread(20145): Pub com.google.android.calendar.CalendarRecentSuggestionsprovider: com.android.calendar.CalendarRecentSuggestionsprovider

// This is my print of the returned URI
02-17 16:43:08.009: I/C3(19995): Calendar created: 12 - content://com.android.calendar/calendars/12?caller_is_syncadapter=true&account_name=xxx%40gmail.com&account_type=com.google

02-17 16:43:08.876: I/CalendarProvider2(20132): Sending notification intent: Intent { act=android.intent.action.PROVIDER_CHANGED dat=content://com.android.calendar }
02-17 16:43:08.876: W/ContentResolver(20132): Failed to get type for: content://com.android.calendar (UnkNown URL content://com.android.calendar)

解决方法

直接的答案是:
同步适配器必须与服务相关联. Service在onCreate()中实例化同步适配器,并将IBinder返回到onBind()中的同步适配器. SyncManager在想要运行同步适配器时调用服务.

同步适配器由Android系统控制,特别是由SyncManager控制,而不是由您的应用程序控制.

SampleSyncAdapter示例应用程序显示了如何编写同步适配器和服务.如果您不想进行身份验证,则可以删除该部分.您需要做的就是实现扩展AbstractThreadedSyncAdapter的类和绑定它的Service类,以及同步适配器的XML文件.

更好的答案是:
同步适配器可帮助您在服务器和设备之间同步数据.如果您只想将日历数据从服务器下载到设备,则可以使用从服务器中删除数据并将其写入日历提供程序的应用程序.那不是同步;您没有保证您将进行更多下载或上传.当然,如果您确实希望保持两个数据源同步,则同步适配器具有以下优势:

>系统将定期运行它,无需用户干预.>系统在尝试运行同步之前确保网络可用.但请注意,系统无法阻止您在网络服务脱机时尝试对服务器进行身份验证等愚蠢行为.>系统确保在开始同步时,同一服务器和内容提供程序没有其他同步正在运行.>系统提供标准工具,用于在用户想要添加帐户时显示可用的同步适配器.

Android 4“没有找到内容提供商或许可撤销”

Android 4“没有找到内容提供商或许可撤销”

我有一个 Android应用程序,在 Android 2-2和2-3上完美运行.但是当我尝试在android 4-0或4-2-2上安装应用程序时,我两次得到以下错误:

找不到许可内容提供者撤销:file:///data/local/tmp/myapp.apk

我发现其他人有类似的问题,我尝试了以下链接中给出的解决方案:

Cannot install APK on Android device through Eclipse
对于这一个我不得不说我的设备没有根.我尝试在模拟器上运行我的应用程序.

Android 4.0.3 emulator: install fails with “permission revoke”

Android error message on install “no content provider found”
在这里我尝试了另一部手机用于模拟器.最初我使用了galaxy nexus,但我也试过nexus 7

Android “No content provider found for permission revoke”
最后但并非最不重要的是我试图将主要动作添加到“androidmanifest.xml”我不确定我是否以正确的方式做到这里是清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.service"
android:versionCode="1"
android:versionName="1.0" >

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />

<uses-sdk
    android:minSdkVersion="4"
    android:targetSdkVersion="6" 
    android:maxsdkVersion="17"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" android:debuggable="true">
    <activity android:name=".SMSReceiver">
        <intent-filter android:priority="1000">
            <action android:name="android.intent.action.MAIN"/>
            <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
            <action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
</application>

我的manifest.xml文件是否还有问题,或者您是否有另外的想法为什么我可以在Android 2上运行此应用程序但不在4上运行?

解决方法

我遇到了同样的问题,当前的答案都没有成功.这对我有用:

adb install -s C:/path/to/your/package/bin/MyApp.apk

‘-s’把它放在SD卡上,我不确定你的情况是否有必要.

android – 从内容提供商URI查看意图?

android – 从内容提供商URI查看意图?

我有一些保护一些敏感数据的要求.数据从URL下载为PDF,并使用以下代码保存为应用程序专用文件:
public File downloadPDF(final Context fileContext,Uri reportUri,final String fileName)
{
    try
    {
        HttpGet get = new HttpGet(reportUri.toString());

        File file = httpClient.execute(get,new ResponseHandler<File>()
        {
            @Override
            public File handleResponse(HttpResponse response) throws ClientProtocolException,IOException
            {
                if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
                {
                    response.getEntity().writeto(fileContext.openFileOutput(fileName,Context.MODE_WORLD_READABLE));
                    return fileContext.getFileStreamPath(fileName);
                }
                return null;
            }
        });

        return file;
    }
    catch (IOException e)
    {
        Log.e(TAG,"Unable to download report.",e);
    }

    return null;
}

现在,我想做的是将其改为使用Context.MODE_PRIVATE并创建一个ContentProvider,以便我的应用程序完全控制这个文件共享到PDF阅读器,如Adobe Reader.这可能吗?我目前使用如下代码将报告URI传递给当前配置的PDF阅读器.

// Fire up a PDF viewer intent for the URL.
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(uri,"application/pdf");
    startActivity(intent);

通过ContentProvider类型URI可以同样的工作吗?一个内容:// package / fileid type URI?明天我会尝试一点点,看看是否可以,但是如果有人知道只有文件:// URI被允许,这将是非常有帮助的.

UPDATE

通过实现一个ContentProvider子类,我能够令人满意地解决我的问题,覆盖了以下方法:

@Override
public ParcelFileDescriptor openFile(Uri uri,String mode) throws FileNotFoundException 
{
    // The filename is the path in the URI without the initial slash.
    String fileName = uri.getPath().substring(1);
    File file = getContext().getFileStreamPath(fileName);
    return ParcelFileDescriptor.open(file,ParcelFileDescriptor.MODE_READ_ONLY);
}

然后,当我消除观看意图时,它被重写成如下:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.withAppendedpath(Uri.parse("content://providername/"),filePath);
intent.setData(uri);
startActivity(intent);

在我的情况下,我使用Adobe Reader,它正确地从content:// URIs实现加载.

解决方法

Would the same work through a ContentProvider type URI? A content://package/fileid type URI?

这应该.您将需要让ContentProvider返回应用程序/ pdf for getType().而且,有些PDF阅读器可能无法处理内容:// Uri值.

您可以做的是使ContentProvider,然后使用PackageManager来查看是否有任何内容将了解您的ACTION_VIEW Intent内容:// Uri.如果有什么回应,你就被设置了.如果没有,您可以回到使文件变得世界可读,并使用您当前的实现.或者,由于将文件更改为世界可读可能会很痛苦,您可以尽早运行测试(例如,当您的应用程序启动时)与您的ContentProvider支持的一些废品Uri一起使用,因此您将了解当您执行哪个路由时你的下载

android – 多个应用使用相同的内容提供商

android – 多个应用使用相同的内容提供商

我正在开发一组仅在某些品牌中有所区别的应用程序(想想不同的运动队);但是,我遇到了一个问题,我正在为所有特定品牌的应用程序使用一个Library项目,并希望为所有这些应用程序使用相同的ContentProvider.当我创建ContentProvider时,我将AUTHORITY声明为类中的常量(根据dev示例代码),并且我在清单文件中的每个特定应用程序中使用相同的权限.看起来我不能在每个应用程序中使用相同的权限,因为我在尝试安装第二个应用程序时遇到此错误(我安装一个品牌的应用程序,但第二个安装):

WARN/PackageManager(66): Can''t install because provider name com.xxx.Provider (in package com.xxx) is already used by com.zzz

我尝试过几种方法,但似乎没有一种方法可行.我还没有完成的一个想法是创建一个库jar,只省略我拥有的Provider类,并在每个特定的应用程序中自定义它.关于如何解决这个问题而不诉诸于此的任何想法?

解决方法

ContentProviders由权威机构识别,因此它必须是唯一的.我不认为有任何伎俩.

此外,Android平台中存在一个错误,该错误还会阻止对两个不同的ContentProviders使用相同的类名,即使它们具有不同的权限并且包含在单独的APK中.请参阅错误here.

我建议您使用的解决方案是在库项目中创建抽象提供程序类,然后在每个单独的应用程序中使用唯一名称对其进行扩展.为了实现这一点,您可能需要创建一个脚本来生成/修改单个清单和contentprovider类.

希望这可以帮助.

android – 如何使用内容提供者添加限制子句

android – 如何使用内容提供者添加限制子句

参见英文答案 > Specifying limit / offset for ContentProvider queries                                    4个
有没有办法限制从内容提供程序返回的行数?
我发现这是solution,然而,它对我不起作用.所有行仍在返回.

Uri uri = Playlists.createIdUri(playlistId); //generates URI
uri = uri.buildUpon().appendQueryParameter("limit", "3").build();     
Cursor cursor = activity.managedQuery(playlistUri, null, null, null, null);

解决方法:

我遇到过这个问题,不得不打破我的脑袋,直到我终于明白了,或者更确切地说,这对我有用.请尝试以下方法

Cursor cursor = activity.managedQuery(playlistUri, null, null, null, " ASC "+" LIMIT 2");

最后一个参数是sortOrder.我提供了排序顺序,并附加了LIMIT.确保正确地给出空间.我必须检查正在形成的查询,这似乎有效.

今天的关于使用Android 4.0(ICS)内容提供商创建日历android risc-v的分享已经结束,谢谢您的关注,如果想了解更多关于Android 4“没有找到内容提供商或许可撤销”、android – 从内容提供商URI查看意图?、android – 多个应用使用相同的内容提供商、android – 如何使用内容提供者添加限制子句的相关知识,请在本站进行查询。

本文标签: