私はフローがas_であるアプリを作っています
1- facebook に正常にログインした後、すべての友人 ID を取得して Arraylist に保存します。2-その後、alarmManaget を 1 日 1 回実行するように設定しています。コードは次のとおりです。
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.friendlist);
lvfrnd = (ListView)findViewById(R.id.listview);
Bundle mbundle = getIntent().getExtras();
if(mbundle!=null && Constant.isService==false )
{
appId = mbundle.getString("appid");
}
if(mbundle!=null && Constant.isService==true )
{
isSuccess = mbundle.getString("success");
}
mUserIdFetcher = new UserIdFetcher();
mfriendIdlist = mUserIdFetcher.getFriendIdList(appId);
String friendId = makeStringOfId(mfriendIdlist);
SharedPreferences mprePreferences = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
SharedPreferences.Editor editor = mprePreferences.edit();
editor.putString("userId", friendId);
editor.commit();
setAlarmManager(appId);
setListView();
}
private String makeStringOfId(ArrayList<String> mfIdlist)
{
int length =0;
String midstring = "";
if(mfIdlist!=null)
{
length = mfIdlist.size();
}
for(int mindex =0;mindex<length;mindex++)
{
midstring = midstring+mfIdlist.get(mindex)+"/";
}
return midstring;
}
private void setAlarmManager(String appid)
{
// add minutes to the calendar object
Calendar updateTime = Calendar.getInstance();
updateTime.setTimeZone(TimeZone.getDefault());
updateTime.set(Calendar.HOUR_OF_DAY,10);
updateTime.set(Calendar.MINUTE,42);
Intent mintent = new Intent(this,BirthDayReciever.class);
mintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, mintent, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
// should be AlarmManager.INTERVAL_DAY (but changed to 15min for testing)
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, updateTime.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
System.out.println("call--------------1");
}
private void setListView()
{
if(Constant.mfriendInfolist!=null &&Constant.mfriendInfolist.size()>0)
{
mlistcustomer = new ListCustomAdapter(Friendlist.this,Constant.mfriendInfolist);
lvfrnd.setAdapter(mlistcustomer);
mlistcustomer.notifyDataSetChanged();
}
}
上記のアクティビティで、実行が保留中のインテントに達すると、この例外が発生します:-
07-16 10:44:26.193: E/AndroidRuntime(773): Uncaught handler: thread main exiting due to uncaught exception
07-16 10:44:26.333: E/AndroidRuntime(773): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bday.Alarm/com.bday.Alarm.Friendlist}: java.lang.IllegalArgumentException: Can't use FLAG_RECEIVER_BOOT_UPGRADE here
07-16 10:44:26.333: E/AndroidRuntime(773): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
07-16 10:44:26.333: E/AndroidRuntime(773): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2621)
07-16 10:44:26.333: E/AndroidRuntime(773): at android.app.ActivityThread.access$2200(ActivityThread.java:126)
07-16 10:44:26.333: E/AndroidRuntime(773): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
07-16 10:44:26.333: E/AndroidRuntime(773): at android.os.Handler.dispatchMessage(Handler.java:99)
07-16 10:44:26.333: E/AndroidRuntime(773): at android.os.Looper.loop(Looper.java:123)
07-16 10:44:26.333: E/AndroidRuntime(773): at android.app.ActivityThread.main(ActivityThread.java:4595)
07-16 10:44:26.333: E/AndroidRuntime(773): at java.lang.reflect.Method.invokeNative(Native Method)
07-16 10:44:26.333: E/AndroidRuntime(773): at java.lang.reflect.Method.invoke(Method.java:521)
07-16 10:44:26.333: E/AndroidRuntime(773): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-16 10:44:26.333: E/AndroidRuntime(773): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-16 10:44:26.333: E/AndroidRuntime(773): at dalvik.system.NativeStart.main(Native Method)
07-16 10:44:26.333: E/AndroidRuntime(773): Caused by: java.lang.IllegalArgumentException: Can't use FLAG_RECEIVER_BOOT_UPGRADE here
07-16 10:44:26.333: E/AndroidRuntime(773): at android.os.Parcel.readException(Parcel.java:1222)
07-16 10:44:26.333: E/AndroidRuntime(773): at android.os.Parcel.readException(Parcel.java:1206)
07-16 10:44:26.333: E/AndroidRuntime(773): at android.app.ActivityManagerProxy.getIntentSender(ActivityManagerNative.java:2065)
07-16 10:44:26.333: E/AndroidRuntime(773): at android.app.PendingIntent.getBroadcast(PendingIntent.java:230)
07-16 10:44:26.333: E/AndroidRuntime(773): at com.bday.Alarm.Friendlist.setAlarmManager(Friendlist.java:102)
07-16 10:44:26.333: E/AndroidRuntime(773): at com.bday.Alarm.Friendlist.onCreate(Friendlist.java:71)
07-16 10:44:26.333: E/AndroidRuntime(773): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-16 10:44:26.333: E/AndroidRuntime(773): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2544)
07-16 10:44:26.333: E/AndroidRuntime(773): ... 11 more
ユーザーのFacebookの友達情報名、生年月日を取得してオブジェクトクラスに設定し、そのクラスをarralistに入れ、その配列リストをListviewに表示するブロードキャストクラス開始サービス私はこのfriendLIstを1日1回更新するためにブロードキャストを使用しています私のサービスクラスは次のとおりです:-
public static final String PREFS_NAME = "MyPrefsFile";
String [] friendFBId=null;
public UIUpdater(String name)
{
super("UIUpdater");
System.out.println("call--------------3");
SharedPreferences mprePreferences = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
String stringofUserId = mprePreferences.getString("userId","");
if(stringofUserId!=null)
{
friendFBId = stringofUserId.split("/");
}
}
@Override
protected void onHandleIntent(Intent intent)
{
Log.d("check--------------", "entered DisplayLoggingInfo");
URL img_value = null;
Bundle params =new Bundle();
int length = friendFBId.length;
String mAccessdata=Facebook.getAccessToken();
try {
System.out.println("fdartr");
params.putString("format", "json");
params.putString("access_token", mAccessdata);
if(friendFBId!=null && friendFBId.length>0)
{
FriendsObject mFriendsObject = null;
for(int mindex =0;mindex<10;mindex++)
{
mFriendsObject = new FriendsObject();
String url = "https://graph.facebook.com/"+friendFBId[mindex];
System.out.println("infourl "+url);
String response = Util.openUrl(url, "GET", params);
JSONObject json = new JSONObject(response);
try {
String name=json.getString("name");
mFriendsObject.setName(name);
} catch (Exception e) {
e.printStackTrace();
}
try {
String fname = json.getString("first_name");
mFriendsObject.setFirst_name(fname);
} catch (Exception e) {
e.printStackTrace();
}
try {
String lname = json.getString("last_name");
mFriendsObject.setLast_name(lname);
} catch (Exception e) {
e.printStackTrace();
}
try {
String gender = json.getString("gender");
mFriendsObject.setGender(gender);
} catch (Exception e) {
e.printStackTrace();
}
try {
String location = json.getString("locale");
mFriendsObject.setLocale(location);
} catch (Exception e) {
e.printStackTrace();
}
try {
String web = json.getString("link");
mFriendsObject.setLink(web);
} catch (Exception e) {
e.printStackTrace();
}
try {
String bdate=json.getString("birthday");
mFriendsObject.setBirthday(bdate);
} catch (Exception e) {
e.printStackTrace();
}
try {
String username=json.getString("username");
mFriendsObject.setUsername(username);
} catch (Exception e) {
e.printStackTrace();
}
try {
String imgurl =" http://graph.facebook.com/"+friendFBId[mindex]+"/picture";
System.out.println("imgurl ========= "+imgurl);
mFriendsObject.setImgUrl(imgurl);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("================="+Constant.mfriendInfolist.size());
Constant.mfriendInfolist.add(mindex,mFriendsObject);
}
}
} catch (Exception e) {
e.printStackTrace();
}
Bundle mbundle = new Bundle();
intent = new Intent(this,Friendlist.class);
Constant.isService = true;
mbundle.putString("success","SUCCESS");
startActivity(intent);
}
ブロードキャストの実行後、この例外が発生しました:-
07-16 11:39:01.443: E/AndroidRuntime(1012): Uncaught handler: thread main exiting due to uncaught exception
07-16 11:39:01.463: E/AndroidRuntime(1012): java.lang.RuntimeException: Unable to instantiate service com.bday.Alarm.UIUpdater: java.lang.InstantiationException: com.bday.Alarm.UIUpdater
07-16 11:39:01.463: E/AndroidRuntime(1012): at android.app.ActivityThread.handleCreateService(ActivityThread.java:2878)
07-16 11:39:01.463: E/AndroidRuntime(1012): at android.app.ActivityThread.access$3200(ActivityThread.java:126)
07-16 11:39:01.463: E/AndroidRuntime(1012): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1986)
07-16 11:39:01.463: E/AndroidRuntime(1012): at android.os.Handler.dispatchMessage(Handler.java:99)
07-16 11:39:01.463: E/AndroidRuntime(1012): at android.os.Looper.loop(Looper.java:123)
07-16 11:39:01.463: E/AndroidRuntime(1012): at android.app.ActivityThread.main(ActivityThread.java:4595)
07-16 11:39:01.463: E/AndroidRuntime(1012): at java.lang.reflect.Method.invokeNative(Native Method)
07-16 11:39:01.463: E/AndroidRuntime(1012): at java.lang.reflect.Method.invoke(Method.java:521)
07-16 11:39:01.463: E/AndroidRuntime(1012): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-16 11:39:01.463: E/AndroidRuntime(1012): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-16 11:39:01.463: E/AndroidRuntime(1012): at dalvik.system.NativeStart.main(Native Method)
07-16 11:39:01.463: E/AndroidRuntime(1012): Caused by: java.lang.InstantiationException: com.bday.Alarm.UIUpdater
07-16 11:39:01.463: E/AndroidRuntime(1012): at java.lang.Class.newInstanceImpl(Native Method)
07-16 11:39:01.463: E/AndroidRuntime(1012): at java.lang.Class.newInstance(Class.java:1479)
07-16 11:39:01.463: E/AndroidRuntime(1012): at android.app.ActivityThread.handleCreateService(ActivityThread.java:2875)
07-16 11:39:01.463: E/AndroidRuntime(1012): ... 10 more