Created
July 7, 2015 11:59
-
-
Save wasnot/a4f4ac46442c8ec477a2 to your computer and use it in GitHub Desktop.
[Android][Lollipop]ロックスクリーンの通知タップからChromeが起動できない ref: http://qiita.com/wasnot/items/36e29bde2bb8be9f3570
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
// 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(); |
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
// 中身はそのまま、自分のアプリへの明示的intentにします。 | |
Uri uri = Uri.parse("http://example.co.jp"); | |
Intent intent = new Intent(con, MyReceiver.class); | |
intent.setAction(Intent.ACTION_VIEW); | |
intent.setData(uri); |
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); | |
// 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