Skip to content

Instantly share code, notes, and snippets.

@wasnot
Created July 7, 2015 11:59
Show Gist options
  • Save wasnot/a4f4ac46442c8ec477a2 to your computer and use it in GitHub Desktop.
Save wasnot/a4f4ac46442c8ec477a2 to your computer and use it in GitHub Desktop.
[Android][Lollipop]ロックスクリーンの通知タップからChromeが起動できない ref: http://qiita.com/wasnot/items/36e29bde2bb8be9f3570
// httpなスキーマのACTION_VIEWの暗黙intentを渡してます。
Uri uri = Uri.parse("http://example.co.jp");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
PendingIntent pi = PendingIntent.getActivity(context, NOTIFICATION_ID, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
// 普通にbuilderで渡したり。。
new NotificationCompat.Builder(context).setIcon(
...
).setContentIntent(pi).build();
// 中身はそのまま、自分のアプリへの明示的intentにします。
Uri uri = Uri.parse("http://example.co.jp");
Intent intent = new Intent(con, MyReceiver.class);
intent.setAction(Intent.ACTION_VIEW);
intent.setData(uri);
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);
// 500msの遅延を入れてintentを飛ばしてもらいます。これは何秒でもいいと思います
am.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 500,
PendingIntent.getActivity(con, 0, i, 0));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment