Last active
December 24, 2015 16:55
-
-
Save ueno-yuhei/6a0a3d4e3ffe3eaf22a7 to your computer and use it in GitHub Desktop.
Pushで、アプリの起動チェックをしよう! ref: http://qiita.com/ueno-yuhei/items/60c76788af8646278be7
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 CustomReceiver extends ParsePushBroadcastReceiver { | |
@Override | |
protected void onPushReceive(Context context, Intent intent) { | |
JSONObject pushData = null; | |
try { | |
pushData = new JSONObject(intent.getStringExtra(KEY_PUSH_DATA)); | |
Log.d("pushData", pushData.toString()); | |
String url = pushData.getString("url"); | |
Uri uri = Uri.parse(url); | |
Intent i = new Intent(Intent.ACTION_VIEW,uri); | |
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
context.startActivity(i); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Push Test</title> | |
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script> | |
<script> | |
$(function(){ | |
var ua = navigator.userAgent.toLowerCase(); | |
var isAndroid = /android/.test(ua); | |
var isChrome = /chrome/.test(ua); | |
var package_name = "logiclogic.jp.myapplication"; | |
var event_id = "1"; | |
if (isAndroid) { | |
if (isChrome) { | |
window.location.href = 'intent://event/' + event_id + '#Intent;scheme=myapp;package=' + package_name + ';end'; | |
} else { | |
var iframe = document.createElement('iframe'); | |
iframe.className = 'is-hidden'; | |
iframe.onload= function() { | |
iframe.parentNode.removeChild(iframe); | |
window.location.href = "※アプリが入ってなかった時に遷移するページのURL"; | |
}; | |
iframe.src = 'myapp://event/' + event_id; | |
document.body.appendChild(iframe); | |
} | |
} | |
}); | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
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
<activity | |
android:name="logiclogic.jp.activity.MainActivity" | |
android:label="@string/app_name" | |
android:theme="@style/AppTheme"> | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN" /> | |
<category android:name="android.intent.category.LAUNCHER" /> | |
</intent-filter> | |
<intent-filter> | |
<action android:name="android.intent.action.VIEW" /> | |
<category android:name="android.intent.category.DEFAULT" /> | |
<category android:name="android.intent.category.BROWSABLE" /> | |
<data | |
android:host="event" | |
android:scheme="myapp" /> | |
</intent-filter> | |
</activity> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment