action.MY_PACKAGE_REPLACEDによる受信ができない
デバッグ環境において、今まで正常に動作していたMY_PACKAGE_REPLACEDによる受信ができなくなった。
Android端末を再起動すれば、受信できるようになりました。
2017年1月4日水曜日
2017年1月3日火曜日
ContentResolver#query() return null
ContentResolver#query() return null
古い機種は、端末の電源投入後、起動完了状態になるまで、1分以上かかる。
この間(起動が完了していない状態。起動途中の段階)で、ContentResolver#query()を使うと、nullが返る。
起動途中の段階でgetContentResolver()を実行した場合であっても、利用可能なContentResolverが返されてくる。
ContentResolver#query()を使いnullが返された場合、その原因が、起動途中の段階なのか、それともAndroidシステムに異常があるのか確認した方が良いかもしれない。
例えば、SystemClock#elapsedRealtime()とThread#sleep()を併用して、2分程度待つようにすれば良い。
なお、elapsedRealtime()は、電源投入を起点とした経過時間をミリ秒単位で返す。
古い機種は、端末の電源投入後、起動完了状態になるまで、1分以上かかる。
この間(起動が完了していない状態。起動途中の段階)で、ContentResolver#query()を使うと、nullが返る。
起動途中の段階でgetContentResolver()を実行した場合であっても、利用可能なContentResolverが返されてくる。
ContentResolver#query()を使いnullが返された場合、その原因が、起動途中の段階なのか、それともAndroidシステムに異常があるのか確認した方が良いかもしれない。
例えば、SystemClock#elapsedRealtime()とThread#sleep()を併用して、2分程度待つようにすれば良い。
なお、elapsedRealtime()は、電源投入を起点とした経過時間をミリ秒単位で返す。
2016年10月1日土曜日
Android端末がWindowsで認識しない
Android端末がWindowsで認識しない
今まで問題なく認識できていたAndroid端末が、2016年10月1日に、Windows10で認識できなくなりました。
私の事例の場合、Windows10に接続するUSB機器を、キーボード、マウス及びAndroid端末の3個だけにすれば、問題なくAndroid端末を認識できるようになりました。
第四番目に接続させていたUSB機器との相性が悪かったのかと思います。
今まで問題なく認識できていたAndroid端末が、2016年10月1日に、Windows10で認識できなくなりました。
私の事例の場合、Windows10に接続するUSB機器を、キーボード、マウス及びAndroid端末の3個だけにすれば、問題なくAndroid端末を認識できるようになりました。
第四番目に接続させていたUSB機器との相性が悪かったのかと思います。
2016年7月11日月曜日
「データがありません」ANRに関する報告の受け取り
「データがありません」ANRに関する報告の受け取り
ANRの報告に「データがありません」という表示がされる場合があります。
この場合、半日程度経ってから、ドラム缶アイコンから「クラッシュとANR」を選択し、ANRデータをCSVファイルで開発機にダウンロードして、見てください。
そうすると、ある程度情報が記載させています。
ANRの報告に「データがありません」という表示がされる場合があります。
この場合、半日程度経ってから、ドラム缶アイコンから「クラッシュとANR」を選択し、ANRデータをCSVファイルで開発機にダウンロードして、見てください。
そうすると、ある程度情報が記載させています。
2016年3月9日水曜日
BroadcastReceiverでIntent.ACTION_PACKAGE_REPLACEDを受け取る
BroadcastReceiverでIntent.ACTION_PACKAGE_REPLACEDを受け取る
アプリの改版を行った場合、アプリは、BroadcastReceiverでandroid.intent.action.PACKAGE_REPLACEDを受け取ります。
このPACKAGE_REPLACEDに基づき実行されるコードは、旧版でしょうか、それとも新版でしょうか。
解答は、新版です。
何の根拠も無く、間違った方で、自分勝手に思い込みをしてしまわないようにしましょう。
アプリの改版を行った場合、アプリは、BroadcastReceiverでandroid.intent.action.PACKAGE_REPLACEDを受け取ります。
このPACKAGE_REPLACEDに基づき実行されるコードは、旧版でしょうか、それとも新版でしょうか。
解答は、新版です。
何の根拠も無く、間違った方で、自分勝手に思い込みをしてしまわないようにしましょう。
2016年2月29日月曜日
PreferenceFragmentを使って複雑なViewGroupを表示・操作したい場合
PreferenceFragmentを使って複雑なViewGroupを表示・操作したい場合
表示する画面のxml:preference_version.xml
<?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="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="web"
android:text="@string/test"
>
</TextView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:paddingTop="20dp"
android:text="@string/app_name"
>
</TextView>
<TextView
android:id="@+id/TextView_Preference_Version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:paddingTop="20dp"
>
</TextView>
</RelativeLayout>
</LinearLayout>
\res\xml\preferences.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
>
<PackageName.VersionPreference
android:key="PreferenceScreen_Version"
android:layout="@layout/preference_version"ここがポイント
widgetLayoutを使うと適切に表示されない。
>
</PackageName.VersionPreference>
</PreferenceScreen>
PackageName.VersionPreference.java
public class VersionPreference extends Preference{
private Context con;
public VersionPreference(Context context){
super(context);
con = context;
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public VersionPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
con = context;
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public VersionPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
con = context;
}
public VersionPreference(Context context, AttributeSet attrs) {
super(context, attrs);
con = context;
}
@Override
protected void onBindView(View view){
super.onBindView(view);
LinearLayout llParent = (LinearLayout) view;
TextView tv = (TextView) llParent.findViewById(R.id.TextView_Preference_Version);
PackageInfo pi;
try{
pi = con.getPackageManager().getPackageInfo(
con.getPackageName(),
PackageManager.GET_ACTIVITIES
);
Resources r = con.getResources();
String s = r.getString(R.string.Version) + pi.versionName;
tv.setText(s);
}
catch(PackageManager.NameNotFoundException e){
}
}
}
表示する画面のxml:preference_version.xml
<?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="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="web"
android:text="@string/test"
>
</TextView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:paddingTop="20dp"
android:text="@string/app_name"
>
</TextView>
<TextView
android:id="@+id/TextView_Preference_Version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:paddingTop="20dp"
>
</TextView>
</RelativeLayout>
</LinearLayout>
\res\xml\preferences.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
>
<PackageName.VersionPreference
android:key="PreferenceScreen_Version"
android:layout="@layout/preference_version"ここがポイント
widgetLayoutを使うと適切に表示されない。
>
</PackageName.VersionPreference>
</PreferenceScreen>
PackageName.VersionPreference.java
public class VersionPreference extends Preference{
private Context con;
public VersionPreference(Context context){
super(context);
con = context;
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public VersionPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
con = context;
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public VersionPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
con = context;
}
public VersionPreference(Context context, AttributeSet attrs) {
super(context, attrs);
con = context;
}
@Override
protected void onBindView(View view){
super.onBindView(view);
LinearLayout llParent = (LinearLayout) view;
TextView tv = (TextView) llParent.findViewById(R.id.TextView_Preference_Version);
PackageInfo pi;
try{
pi = con.getPackageManager().getPackageInfo(
con.getPackageName(),
PackageManager.GET_ACTIVITIES
);
Resources r = con.getResources();
String s = r.getString(R.string.Version) + pi.versionName;
tv.setText(s);
}
catch(PackageManager.NameNotFoundException e){
}
}
}
ListPreferenceを使って、longのデータを保存・読込を行う
ListPreferenceを使って、longのデータを保存・読込を行う
ListPreferenceをそのまま使うと、保存・読込のデータはStringになる。
これは不便だ。そこで、longによりデータの保存・読込を行う。
public class myLP extends ListPreference{
public myLP(Context context){
super(context);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public myLP(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public myLP(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public myLP(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onSetInitialValue(boolean restoreValue, Object defaultValue){
if(restoreValue){//long型データをファイルから読む。
long lValue;
String s;
lValue = //PreferenceManager.getDefaultSharedPreferences()を使ってデータを読む。
s = String.valueOf(lValue);
setValue(s);
}
else{//ファイルへ保存する。
//このファイルへ保存する部分は、別途本体において、自分でプログラムする。
}
}
}
String sValue = (String)newValue;
//Long.parseLong(sValue)を
//PreferenceManager.getDefaultSharedPreferences()を使って保存する
return true;
}
ListPreferenceをそのまま使うと、保存・読込のデータはStringになる。
これは不便だ。そこで、longによりデータの保存・読込を行う。
public class myLP extends ListPreference{
public myLP(Context context){
super(context);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public myLP(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public myLP(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public myLP(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onSetInitialValue(boolean restoreValue, Object defaultValue){
if(restoreValue){//long型データをファイルから読む。
long lValue;
String s;
lValue = //PreferenceManager.getDefaultSharedPreferences()を使ってデータを読む。
s = String.valueOf(lValue);
setValue(s);
}
else{//ファイルへ保存する。
//このファイルへ保存する部分は、別途本体において、自分でプログラムする。
}
}
}
class SettingsFragment extends PreferenceFragmentにて
@Override
public boolean onPreferenceChange(Preference preference, Object newValue){String sValue = (String)newValue;
//Long.parseLong(sValue)を
//PreferenceManager.getDefaultSharedPreferences()を使って保存する
return true;
}
(参考)
登録:
投稿 (Atom)