OK、私はアンドロイド開発に慣れていないので、ここで我慢してください。私は学習用のAndroidブックに従っていますが、必要な権限がないため更新サービスが機能しないというこの問題があります。誰が問題の原因を教えてもらえますか? * java.lang.SecurityException: Not allowed to start service Intent { cmp=com.example.yamba/ .RefreshService } without permission com.example.yamba.permission.REFRESH at com.example.yamba. TimelineActivity.onOptionsItemSelected(TimelineActivity.java:138) *
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.yamba"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="com.example.yamba.permission.REFRESH" />
<application
android:name=".YambaApp"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name="com.example.yamba.StatusActivity"
android:configChanges="orientation"
android:icon="@drawable/ic_launcher"
android:label="@string/status_Update" >
</activity>
<activity
android:name=".TimelineActivity"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".UpdaterService" >
</service>
<service
android:name=".RefreshService"
android:permission="com.example.yamba.permission.REFRESH" >
<intent-filter>
<action android:name="com.example.yamba.RefreshService" />
</intent-filter>
</service>
<activity
android:name=".PrefsActivity"
android:label="@string/Preferences" >
</activity>
<receiver android:name=".BootReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="com.example.yamba.REFRESH_ALARM" />
</intent-filter>
</receiver>
</application>
package com.example.yamba;
import java.util.List;
import winterwell.jtwitter.Twitter.Status;
import winterwell.jtwitter.TwitterException;
import android.app.IntentService;
import android.content.Intent;
import android.util.Log;
public class RefreshService extends IntentService {
static final String TAG = "RefreshService";
public RefreshService() {
super(TAG);
}
@Override
protected void onHandleIntent(Intent intent) {
((YambaApp) getApplication()).pullAndInsert();
Log.d(TAG, "onHandleIntent");
}
@Override
public void onCreate() {
super.onCreate();
Log.d(TAG, "OnCreated");
}
@Override
public void onDestroy() {
super.onDestroy();
Log.d(TAG, "OnDestroy");
}
}
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
Intent intentUpdater = new Intent(this, UpdaterService.class);
Intent intentRefresh = new Intent(this, RefreshService.class);
Intent intentPrefs = new Intent(this, PrefsActivity.class);
Intent intentTimeline = new Intent(this, StatusActivity.class);
switch (item.getItemId()) {
case R.id.item_start_service:
startService(intentUpdater);
return true;
case R.id.item_stop_service:
stopService(intentUpdater);
return true;
case R.id.item_refresh:
startService(intentRefresh);
return true;
case R.id.item_prefs:
startActivity(intentPrefs);
return true;
case R.id.item_status_update:
startActivity(intentTimeline);
default:
return false;
}
onOptionsItemSelected は、更新サービスを呼び出すために使用されます。
助けてくれて本当にありがとう。ありがとう!!