This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestProvider extends ContentProvider { | |
... | |
private SharedPreferences mPrefs; | |
@Override | |
public boolean onCreate() { | |
LogUtil.d(TAG, "onCreate " + Binder.getCallingPid() + ", " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AlertDialog.Builder b = new AlertDialog.Builder(activity); | |
b.setTitle("タイトル"); | |
b.setPositiveButton(android.R.string.ok, null); | |
// ここでリスナーを実装しても渡されないので実装しなくても構いません。 | |
b.setNegativeButton(android.R.string.cancel, null); | |
// AlertDialogを生成する前にgetButton等してもnullが返されます。 | |
final AlertDialog dialog = b.show(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<resources ...> | |
... | |
<item name="radius" format="float" type="dimen">200.34</item> | |
.... | |
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
… | |
// ロック画面解除とロック画面上に表示するフラグを追加します。 | |
getWindow().addFlags( | |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ActivityManagerServiceからはこんな風に呼ばれていました。 | |
mUsageStatsService = IUsageStats.Stub.asInterface(ServiceManager.getService("usagestats")); | |
// リフレクションではこう呼んだり。。ServiceLocatorは上記ブログ参照。。 | |
mUsageStatsService = ServiceLocator.getServiceStub("usagestats", | |
"com.android.internal.app.IUsageStats$Stub"); | |
// 関数のコールもリフレクション。。 | |
Class<?> clazz = Class.fromName("com.android.internal.app.IUsageStats$Stub"); | |
Method method = clazz.getDeclaredMethod("getAllPkgUsageStats"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// JavaのFileを扱うように自由に書き込みもできます。 | |
// ただしSAFのAPIを介する必要があります。 | |
// また、一度付与されたuriは保持しておく必要があります。 | |
// Create a new file and write into it | |
DocumentFile newFile = pickedDir.createFile("text/plain", "My Novel"); | |
try { | |
OutputStream out = getActivity().getContentResolver().openOutputStream(newFile.getUri()); | |
out.write("A long time ago...".getBytes()); | |
out.close(); | |
} catch (FileNotFoundException e) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyReceiver extends BroadcastReceiver { | |
@Override | |
public void onReceive(Context context, Intent intent) { | |
Context con = context.getApplicationContext(); | |
if ("myaction".equals(action)) { | |
... | |
} else if (Intent.ACTION_VIEW.equals(action)) { | |
// 今回はとりあえず、ここでintentを作っていますが、中に入れたりしたほうがいいと思います。 | |
Intent i = new Intent(Intent.ACTION_VIEW, intent.getData()); | |
AlarmManager am = (AlarmManager) con.getSystemService(Context.ALARM_SERVICE); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new NotificationCompat.Builder(this).setStyle(new Notification.MediaStyle() | |
.setMediaSession(mySession)) |
OlderNewer