how to handle a Specific Url in android webview? - android

I want to open the link https://appear.in/terochat-t192f in my custom webview in my application. When I start a new Activity that contains this webview, I am faced with this page:
And when I click on the button "join conversation", I am faced with "page not found" like this:
I found out that I should handle the URL with intent-filter in AndroidManifest.xml with:
<activity android:name=".MainSegment.Team.Team_Profile.Chatroom.VideoChatroomActivity">
<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:scheme="https"
android:host="appear.in"/>
</intent-filter>
</activity>
But it has't resolved my problem yet!
This is my Java code in the activity that contains this WebView:
public class VideoChatroomActivity extends AppCompatActivity implements AdvancedWebView.Listener{
private AdvancedWebView teamChatWebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_chatroom);
teamChatWebView = (AdvancedWebView) findViewById(R.id.webview_team_video_chat);
teamChatWebView.setListener(this, this);
teamChatWebView.addPermittedHostname("appear.in");
teamChatWebView.loadUrl("https://appear.in/terochat-t192f");
}
#SuppressLint("NewApi")
#Override
protected void onResume() {
super.onResume();
teamChatWebView.onResume();
}
#SuppressLint("NewApi")
#Override
protected void onPause() {
teamChatWebView.onPause();
// ...
super.onPause();
}
#Override
protected void onDestroy() {
teamChatWebView.onDestroy();
// ...
super.onDestroy();
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
teamChatWebView.onActivityResult(requestCode, resultCode, intent);
// ...
}
#Override
public void onBackPressed() {
if (!teamChatWebView.onBackPressed()) { return; }
// ...
super.onBackPressed();
}
#Override
public void onPageStarted(String url, Bitmap favicon) {
}
#Override
public void onPageFinished(String url) {
}
#Override
public void onPageError(int errorCode, String description, String failingUrl) {
}
#Override
public void onDownloadRequested(String url, String suggestedFilename, String mimeType, long contentLength, String contentDisposition, String userAgent) {
}
#Override
public void onExternalPageRequest(String url) {
}
}
How can I solve this?

Related

UnityPlayer blackScreen on a subActivity

On a android Studio project, when i switch to a another Activity who contains also a UnityPlayer, the UnityPlayer display a BlackScreen on the subActivity.
I am on Arcore project where i use Android studio for have a good interface and easy to implement, i use the last Unity version and Android studio, and every last android librairy(Androidx).
I needed to open the Unity view on a another activity, but do not seems to working. And every research done on google send me to answer who do not resolve my problem or else to add a android:process on my manifest.xml, but impossible to get it to work.
Every code related to mUnityPlayer
Manifest.xml of the two activity:
[...]
<activity
android:name=".MainActivity"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density"
android:hardwareAccelerated="false"
android:label="#string/app_name"
android:launchMode="singleTask"
android:screenOrientation="landscape"
android:theme="#style/AppTheme"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
<meta-data
android:name="unityplayer.UnityActivity"
android:value="true" />
</activity>
<activity
android:name=".ViewerPlaneActivity"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density"
android:hardwareAccelerated="false"
android:label=""
android:screenOrientation="landscape"
android:theme="#style/AppTheme"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>
<meta-data
android:name="unityplayer.UnityActivity"
android:value="true" />
</activity>
[...]
MainActivity of my application:
public class MainActivity extends AppCompatActivity {
[...]
public UnityPlayer mUnityPlayer;
public static UnityPlayerActivity currentActivity;
private boolean switchToAnAnotherUnityAct=false;
[...]
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
mUnityPlayer = new UnityPlayer(this);
setContentView(R.layout.viewer_view_simple_viewer);
replaceUnityPlayerOnFrameLayout();
mUnityPlayer.getView().requestFocus();
currentActivity = this;
[...]
}
private void replaceUnityPlayerOnFrameLayout(){
FrameLayout frameLayout = findViewById(R.id.unity_player_layout);
if( mUnityPlayer.getView().getParent()==null)
frameLayout.addView(mUnityPlayer.getView());
}
#Override
protected void onDestroy() {
if(!switchToAnAnotherUnityAct)mUnityPlayer.destroy();
super.onDestroy();
}
#Override
protected void onPause() {
super.onPause();
if(!switchToAnAnotherUnityAct)mUnityPlayer.pause();
}
#Override
protected void onResume() {
super.onResume();
if(!switchToAnAnotherUnityAct){
mUnityPlayer.resume();
replaceUnityPlayerOnFrameLayout();
}
}
#Override
protected void onStart() {
super.onStart();
mUnityPlayer.start();
switchToAnAnotherUnityAct=false;
}
#Override
protected void onStop() {
super.onStop();
if(!switchToAnAnotherUnityAct)mUnityPlayer.stop();
}
#Override
public void onLowMemory() {
super.onLowMemory();
mUnityPlayer.lowMemory();
}
#Override
public void onTrimMemory(int level) {
super.onTrimMemory(level);
if (level == TRIM_MEMORY_RUNNING_CRITICAL) {
mUnityPlayer.lowMemory();
}
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mUnityPlayer.configurationChanged(newConfig);
}
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
mUnityPlayer.windowFocusChanged(hasFocus);
}
public void onClickSizeSettings(View view) {
FrameLayout frameLayout = findViewById(R.id.unity_player_layout);
frameLayout.removeAllViews();
switchToAnAnotherUnityAct=true;
Intent intent = new Intent(this, ViewerPlaneActivity.class);
this.startActivity(intent);
}
[...]
The sub-activity:
public class ViewerPlaneActivity extends AppCompatActivity {
public UnityPlayer mUnityPlayer;
public static ViewerPlaneActivity currentActivity;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
currentActivity = this;
mUnityPlayer= MainActivity.currentActivity.mUnityPlayer;
setContentView(R.layout.viewer_plane_unit);
FrameLayout frameLayout = findViewById(R.id.unity_player_layout);
frameLayout.addView(mUnityPlayer.getView());
mUnityPlayer.getView().requestFocus();
[...]
}
private void replaceUnityPlayerOnFrameLayout(){
FrameLayout frameLayout = findViewById(R.id.unity_player_layout);
if( mUnityPlayer.getView().getParent()==null)
frameLayout.addView(mUnityPlayer.getView());
}
#Override
public void onTrimMemory(int level) {
super.onTrimMemory(level);
if (level == TRIM_MEMORY_RUNNING_CRITICAL) {
mUnityPlayer.lowMemory();
}
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mUnityPlayer.configurationChanged(newConfig);
}
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
mUnityPlayer.windowFocusChanged(hasFocus);
}
#Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
return mUnityPlayer.injectEvent(event);
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
return mUnityPlayer.injectEvent(event);
}
#Override
public boolean onTouchEvent(MotionEvent event) {
return mUnityPlayer.injectEvent(event);
}
public void onClickAnchorPlane(View view){
[...]
finish();
}
#Override
public void finish() {
super.finish();
FrameLayout frameLayout = findViewById(R.id.unity_player_layout);
frameLayout.removeAllViews();
}
#Override
protected void onPause() {
super.onPause();
mUnityPlayer.pause();
}
#Override
protected void onResume() {
super.onResume();
replaceUnityPlayerOnFrameLayout();
mUnityPlayer.resume();
}
#Override
protected void onStart() {
super.onStart();
mUnityPlayer.start();
}
The result than i expect is to see the UnityPlayer displayed, but i got just a blackscreen. And zero errors.
I precise than i do not get problem for return on my MainActivity where the UnityPlayer work and display correctly the viewer. Just the SecondViewer, where i got a blackscreen where i expect just to see the unity to display my plane and the camera.
Thank for your help.
For finish, i have found no solution to my problem so i have used two ViewStub on my main layout.

Android activity doesn't start regardless of the method used to start it

I've defined an android activity and it just fails to start regardless of how I try to start it. It's supposed to be launched as the main activity, but the app just hangs if I declare it as the default activity like this:
<activity
android:name=".activity.StartupActivity"
android:screenOrientation="portrait"
android:theme="#style/NoActionAppTheme">
<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="url"
android:pathPrefix="/prefix"
android:scheme="https" />
<data
android:host="url"
android:scheme="https" />
</intent-filter>
</activity>
I've tried putting a breakpoint at the first line of onCreate and Log lines in this activity, but this activity just doesn't start. I think the source code of the activity is irrelevent since it doesn't ever start. Please let me know if it's needed. I tried setting another activity as the default one and start StartupActivity from it like this:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (! AppRuntime.b) {
AppRuntime.b = true;
startActivity(new Intent(this, StartupActivity.class));
finish();
return;
}
// other stuff
}
But the result is similar to what I see when StartupActivity is the default activity. The breakpoints in this activity work as expected. The problem arises when the StartupActivity is started. What's causing this problem?
Note: StartupActivity extends AppCompatActivity and overrides only onCreate and onActivityResult.
Edit: here's the activity code:
public class StartupActivity extends AppCompatActivity {
SharedPreferences sp;
String deepLink = "";
final int SIGNUP_REQUEST_CODE = 0;
final int TUTORIAL_REQUEST_CODE = 1;
#Override
public void onCreate(#Nullable Bundle savedInstanceState, #Nullable PersistableBundle persistentState) {
super.onCreate(savedInstanceState);
addressInvitation();
sp = App.getSharedPreferences();
MobileAds.initialize(this, Utils.getAdmobID());
setContentView(R.layout.activity_splash_screen);
//load the ad
// mAdView = findViewById(R.id.adView);
// AdRequest adRequest = new AdRequest.Builder().build();
// mAdView.loadAd(adRequest);
Log.d("DEBUGGING", "calling bootstrap");
bootstrapApp();
}
private void bootstrapApp() {
if (! sp.contains("signed_in")) {
sp.edit().clear().apply();
Log.d("DEBUGGING", "starting signup activity");
startActivityForResult(new Intent(this, SignUp.class), SIGNUP_REQUEST_CODE);
} else if (! sp.contains("isFirstTime")) {
Log.d("DEBUGGING", "starting tutorial");
startActivityForResult(new Intent(this, TutorialsActivity.class), TUTORIAL_REQUEST_CODE);
} else {
Log.d("DEBUGGING", "going to splash screen");
startActivity(new Intent(this, SplashScreen.class));
finish();
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case SIGNUP_REQUEST_CODE:
Log.d("DEBUGGING", "signup returned");
if (resultCode == RESULT_OK) {
sp.edit()
.putBoolean("signed_in", true)
.apply();
} else {
finish();
}
break;
case TUTORIAL_REQUEST_CODE:
Log.d("DEBUGGING", "tutorial returned");
if (resultCode == RESULT_OK) {
sp.edit()
.putBoolean("isFirstTime", true)
.apply();
} else {
finish();
}
break;
}
bootstrapApp();
}
private void addressInvitation() {
FirebaseDynamicLinks.getInstance().getDynamicLink(getIntent())
.addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
#Override
public void onSuccess(PendingDynamicLinkData data) {
if (data == null) {
return;
}
// Get the deep link
deepLink = data.getLink().toString();
// Extract invite
FirebaseAppInvite invite = FirebaseAppInvite.getInvitation(data);
if (invite != null) {
String invitationId = invite.getInvitationId();
}
}
})
.addOnFailureListener(this, new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Log.e("HandleInvitaiton", "COULD NOT HANDLE");
}
});
}
}
I see the problem. You're using
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState)
instead of
protected void onCreate(#Nullable Bundle savedInstanceState)
You're overriding the wrong method.

How to get the proper actions from intent on android

There are two applications : Caller, Callee
Case 1 >
When I launch Callee application from home screen, I can get an action("android.intent.action.MAIN") from INTENT.
While Callee is running, I launch Callee application with an action("andoird.intent.action.test") again from Caller application. Then I get the action("android.intent.action.MAIN"). not action("andoird.intent.action.test").
How can I get the action("andoird.intent.action.test")?
Case 2 >
When I launch Callee application with an action("andoird.intent.action.test"), I get the action("andoird.intent.action.test").
While Callee is running, I launch Callee application from the home screen. Then I get the action("andoird.intent.action.test"). not action("android.intent.action.Main").
How can I get the action("android.intent.action.Main")?
What am I missing to get the proper action?
Here is Caller code below.
public class CallerActivity extends AppCompatActivity {
public static final String ACTION_TEST = "android.intent.action.test";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button test = (Button) findViewById(R.id.gotoSetting);
test.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = getPackageManager().getLaunchIntentForPackage(PACKAGE);
intent.setAction(ACTION_TEST);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
}
});
}
}
Here is Callee code below.
public class CalleeActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.e("test", "onCreate()");
Log.e("test", getIntent().getAction());
}
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Log.e("test", "onNewIntent()");
Log.e("test", getIntent().getAction());
}
}
Here is Callee's AndroidManifest.
<activity
android:name=".CalleeActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden">
<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.test"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
Please help.
Replace this code:
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Log.e("test", "onNewIntent()");
Log.e("test", getIntent().getAction());// getIntent() will return old intent
}
with
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Log.e("test", "onNewIntent()");
Log.e("test", intent.getAction()); //use new intent
}

intent.setAction() and intent.getAction() not working in BroadcastReceiver

I am using BroadCaastReceiver to allow user perform offline events.The issue is that it is never going insideintent.getAction().equals("beenthereclicked")if i try switching on wifi few seconds after clicking on beenThereView.However it does go inside if (wifi.isAvailable() || mobile.isAvailable()) whenever i switch on wifi.I failed to understand why intent.setAction() and intent.getAction() not working.I can see wificonnected in my log but can't see beenthereclicked in my log.
i wrote this inside onReceive- Log.e("NetworkChangeReceiver","intent"+intent.getAction()); .. then i am getting.. intentandroid.net.conn.CONNECTIVITY_CHANGE in log
beenThereView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent();
Bundle extras = new Bundle();
extras.putString("Is_been_there", video.getIs_been_there());
extras.putString("videoid", video.getId());
intent.putExtras(extras);
intent.setAction("beenthereclicked");
mContext.sendBroadcast(intent);
}
}
NetworkChangeReceiver.java
public class NetworkChangeReceiver extends BroadcastReceiver {
#Override
public void onReceive(final Context context, final Intent intent) {
if (wifi.isConnected() || mobile.isAvailable())
{
Log.e("NetworkChangeReceiver", "wificonnected");
Log.e("NetworkChangeReceiver","intent"+intent.getAction());//returns android.net.conn.CONNECTIVITY_CHANGE
if (intent.getAction().equals("beenthereclicked")) {
Log.e("NetworkChangeReceiver", "beenthereclicked");
Bundle extras = intent.getExtras();
String isbeenthere = extras.getString("Is_been_there");
String videoid = extras.getString("videoid");
if (isbeenthere.equals("false"))
{
BeenThereAPI.unlike(context, videoid, new APIResponseListener() {
#Override
public void onResponse(Object response) {
}
#Override
public void onError(VolleyError error) {
}
});
}
else
{
BeenThereAPI.like(context, videoid, new APIResponseListener()
{
#Override
public void onResponse(Object response)
{
}
#Override
public void onError(VolleyError error)
{
}
});
}
}
}
AndroidManifest
<receiver android:name="xyz.NetworkChangeReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE"></action>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
<action android:name="android.net.wifi.WIFI_STATE_CHANGED"/>
<action android:name="beenthereclicked"></action>
<action android:name="mustgoclicked"></action>
<action android:name="commentposted"></action>
</intent-filter>
</receiver>

Android 4.0 Device Admin Receiver not working

I'm trying to build a really simple app to wipe all the user data off a ICS device.
I've tried to create the app using the source code on http://developer.android.com/guide/topics/admin/device-admin.html
and
http://marakana.com/s/post/1291/android_device_policy_administration_tutorial
But I'm having an issue, no matter what I do, the broadcast receiver for prompting the user to allow admin does not appear!
Heres what I got so far if anyone can help with this issue.
Manifest:
<uses-sdk android:minSdkVersion="15" />
<application android:icon="#drawable/ic_launcher"
android:label="#string/app_name">
<activity android:name="com.CheckActivityService.CheckActivityServiceActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<receiver android:name=".mDeviceAdminReceiver"
android:label="device_admin" android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data android:name="android.app.device_admin"
android:resource="#xml/policies" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
</manifest>
Activity:
public class CheckActivityServiceActivity extends Activity implements OnCheckedChangeListener{
/** Called when the activity is first created. */
static final int ACTIVATION_REQUEST = 1; // identifies our request id
DevicePolicyManager devicePolicyManager;
ComponentName deviceAdmin;
ToggleButton toggleButton;
static final String TAG = "DevicePolicyActivity";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
toggleButton = (ToggleButton) super
.findViewById(R.id.toggle_device_admin);
toggleButton.setOnCheckedChangeListener(this);
Button btn = (Button) findViewById(R.id.wipeDataBtn);
btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
wipeData();
}
});
devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
deviceAdmin = new ComponentName(CheckActivityServiceActivity.this, mDeviceAdminReceiver.class);
}
/**
* Called when the state of toggle button changes. In this case, we send an
* intent to activate the device policy administration.
*/
public void onCheckedChanged(CompoundButton button, boolean isChecked) {
if (isChecked) {
// Launch the activity to have the user enable our admin.
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, deviceAdmin);
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "My Boss told me to do this!!");
startActivityForResult(intent, ACTIVATION_REQUEST);
}
Log.d(TAG, "onCheckedChanged to: " + isChecked);
}
public void wipeData(){
devicePolicyManager.wipeData(ACTIVATION_REQUEST);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case ACTIVATION_REQUEST:
if (resultCode == Activity.RESULT_OK) {
Log.i(TAG, "Administration enabled!");
toggleButton.setChecked(true);
} else {
Log.i(TAG, "Administration enable FAILED!");
toggleButton.setChecked(false);
}
return;
}
super.onActivityResult(requestCode, resultCode, data);
}
}
Reciever:
public class mDeviceAdminReceiver extends DeviceAdminReceiver {
static final String TAG = "DeviceAdminReceiver";
void showToast(Context context, String msg) {
String status = "TEST";
Toast.makeText(context, status, Toast.LENGTH_SHORT).show();
}
/** Called when this application is approved to be a device administrator. */
#Override
public void onEnabled(Context context, Intent intent) {
super.onEnabled(context, intent);
Toast.makeText(context, "Admin Enabeled",
Toast.LENGTH_LONG).show();
Log.d(TAG, "onEnabled");
}
/** Called when this application is no longer the device administrator. */
#Override
public void onDisabled(Context context, Intent intent) {
super.onDisabled(context, intent);
Toast.makeText(context, "Admin Disabled",
Toast.LENGTH_LONG).show();
Log.d(TAG, "onDisabled");
}
#Override
public void onPasswordChanged(Context context, Intent intent) {
super.onPasswordChanged(context, intent);
Log.d(TAG, "onPasswordChanged");
}
#Override
public void onPasswordFailed(Context context, Intent intent) {
super.onPasswordFailed(context, intent);
Log.d(TAG, "onPasswordFailed");
}
#Override
public void onPasswordSucceeded(Context context, Intent intent) {
super.onPasswordSucceeded(context, intent);
Log.d(TAG, "onPasswordSucceeded");
}
}
If anyone can help me to get this to work, as I really can't figure out why the broadcast receiver isn't firing.
Figured out problem, kind of stupid of me.
needed to put the receiver in the element.

Categories

Resources