Cannot resolve symbol '#xml/device_admin' - java

I am trying to implement screen pinning on an Android 5.1 Device. I came across This Answer, and in trying to add a intent-filter to my Manifest, I get this error: Cannot resolve symbol '#xml/device_admin'.
I assume this is because xml/device_admin doesn't exist, so if this is the case, where do I create it?
My Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="MY_PACKAGE">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.app.action.PROFILE_PROVISIONING_COMPLETE" />
</intent-filter>
</activity>
<receiver
android:name=".MyDeviceAdminReceiver"
android:label="#string/app_name"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data
android:name="android.app.device_admin"
android:resource="#xml/device_admin" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
<!-- <receiver android:name=".BootReceiver"> -->
<!-- <intent-filter > -->
<!-- <action android:name="android.intent.action.BOOT_COMPLETED"/> -->
<!-- </intent-filter> -->
<!-- </receiver> -->
</application>
</manifest>
My MainActivity
package MY_PACKAGE;
import android.content.ComponentName;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.app.admin.*;
public class MainActivity extends AppCompatActivity {
private WebView mWebView;
private static final String TAG = "MainActivity";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ComponentName deviceAdmin = new ComponentName(this, MyDeviceAdminReceiver.class);
DevicePolicyManager mDpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
mWebView = (WebView) findViewById(R.id.activity_main_webview);
// Enable Javascript
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient());
mWebView.loadUrl("my_website.com"); //Note that this is a placeholder website.
if (mDpm.isDeviceOwnerApp(getPackageName())) {
mDpm.setLockTaskPackages(deviceAdmin, new String[]{getPackageName()});
}
if (mDpm.isLockTaskPermitted(this.getPackageName()))
startLockTask();
// try {
// Runtime.getRuntime().exec("dpm set-device-owner MY_PACKAGE/.MyDeviceAdminReceiver");
// } catch (Exception e) {
// Log.e(TAG, "device owner not set");
// Log.e(TAG, e.toString());
// e.printStackTrace();
// }
try {
startLockTask();
} catch (Exception e) {
e.printStackTrace();
}
}
#Override
public void onBackPressed() {
if(mWebView.canGoBack()) {
mWebView.goBack();
} else {
System.out.print("LOCKED IN PLACE!");
}
}
}

I assume this is because xml/device_admin doesn't exist, so if this is
the case, where do I create it?
Create Folder in hierarchy application/src/main/res/xml keep the file device_admin.xml in this XML folder
Structure of device_admin.xml file is
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
<uses-policies>
<limit-password />
<watch-login />
<reset-password />
<force-lock />
<wipe-data />
<expire-password />
<encrypted-storage />
<disable-camera />
</uses-policies>
</device-admin>
Device_admin GuideLine

Related

App Crash Stuck on Splash Screen- Back Button shows error [duplicate]

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 2 years ago.
Build version: 2.9
Build date: 1979-11-30 00:00:00
Current date: 2020-12-12 17:01:30
Device: Samsung SM-N970U
OS version: Android 10 (SDK 29)
Stack trace:
java.lang.RuntimeException: Unable to destroy activity {com.jmctstudios.vibe/com.jmctstudios.vibe.ActivitiesFragment.Splash_A}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.os.CountDownTimer.cancel()' on a null object reference
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:5456)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:5493)
at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:44)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2267)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8167)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.os.CountDownTimer.cancel()' on a null object reference
at com.jmctstudios.vibe.ActivitiesFragment.Splash_A.onDestroy(Splash_A.java:83)
at android.app.Activity.performDestroy(Activity.java:8225)
at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1342)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:5441)
... 11 more
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.jmctstudios.vibe">
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature
android:name="android.hardware.camera2.full"
android:required="false" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.MANAGE_DOCUMENTS"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.RECORD_VIDEO" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.READ_PHONE_NUMBERS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<application
android:name=".SimpleClasses.VIBE"
android:allowBackup="false"
android:hardwareAccelerated="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:largeHeap="true"
android:networkSecurityConfig="#xml/network_security_config"
android:requestLegacyExternalStorage="true"
android:roundIcon="#mipmap/ic_launcher"
android:screenOrientation="portrait"
android:supportsRtl="false"
android:theme="#style/AppTheme"
tools:replace="allowBackup,supportsRtl">
<activity android:name=".ActivitiesFragment.Accounts.Forgot_Pass_A"
android:theme="#style/transparent_status"/>
<activity
android:name=".ActivitiesFragment.Video_Recording.Trim_video_A"
android:theme="#style/black_status" />
<activity
android:name=".ActivitiesFragment.Video_Recording.Video_Recoder_Duet_A"
android:theme="#style/black_status" />
<activity
android:name="cat.ereza.customactivityoncrash.activity.DefaultErrorActivity"
android:process=":error_activity"
android:theme="#style/error_activity_theme" />
<activity
android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
android:screenOrientation="portrait"
android:theme="#style/Base.Theme.AppCompat"
tools:ignore="LockedOrientationActivity" />
<activity android:name=".ActivitiesFragment.SoundLists.VideoSound_A" />
<activity
android:name=".ActivitiesFragment.Video_Recording.DraftVideos_A"
android:screenOrientation="portrait"
android:theme="#style/white_status"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".ActivitiesFragment.Video_Recording.GallerySelectedVideo_A"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".ActivitiesFragment.Accounts.Login_A"
android:screenOrientation="portrait"
android:theme="#style/Transparent"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".ActivitiesFragment.Splash_A"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Main_Menu.MainMenuActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="#style/transparent_status"
android:windowSoftInputMode="stateAlwaysHidden|adjustNothing"
tools:ignore="LockedOrientationActivity"/>
<activity
android:name=".ActivitiesFragment.WatchVideos_F"
android:parentActivityName=".Main_Menu.MainMenuActivity"
android:screenOrientation="portrait"
android:theme="#style/transparent_status"
android:windowSoftInputMode="stateAlwaysHidden|adjustNothing"
tools:ignore="LockedOrientationActivity">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="bringthings.com"
android:scheme="http" />
</intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.jmctstudios.vibe.Main_Menu.MainMenuActivity" />
</activity>
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<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="#string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
<activity
android:name=".ActivitiesFragment.Video_Recording.Video_Recoder_A"
android:screenOrientation="portrait"
android:theme="#style/black_status"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".ActivitiesFragment.Video_Recording.Preview_Video_A"
android:screenOrientation="portrait"
android:theme="#style/black_status"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".ActivitiesFragment.Video_Recording.Post_Video_A"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustNothing"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".ActivitiesFragment.SoundLists.SoundList_Main_A"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="#string/ad_app_id"/>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/ic_tic" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="#color/redcolor" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths" />
</provider>
<service
android:name=".Services.Upload_Service"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="startservice" />
</intent-filter>
</service>
<service android:name=".Firebase_Notification.Notification_Receive">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
</application>
</manifest>
package com.jmctstudios.vibe.ActivitiesFragment;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.CountDownTimer;
import androidx.appcompat.app.AppCompatActivity;
import android.provider.Settings;
import android.view.Window;
import android.view.WindowManager;
import com.jmctstudios.vibe.Main_Menu.MainMenuActivity;
import com.jmctstudios.vibe.R;
import com.jmctstudios.vibe.ApiClasses.ApiLinks;
import com.jmctstudios.vibe.ApiClasses.ApiRequest;
import com.jmctstudios.vibe.Interfaces.Callback;
import com.jmctstudios.vibe.SimpleClasses.Variables;
import org.json.JSONException;
import org.json.JSONObject;
public class Splash_A extends AppCompatActivity {
CountDownTimer countDownTimer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_splash);
Variables.sharedPreferences = getSharedPreferences(Variables.pref_name, MODE_PRIVATE);
if(Variables.sharedPreferences.getString(Variables.device_id,"0").equals("0")) {
Call_api_register_device();
}
else
Set_Timer();
}
public void Set_Timer(){
countDownTimer = new CountDownTimer(2500, 500) {
public void onTick(long millisUntilFinished) {
// this will call on every 500 ms
}
public void onFinish() {
Intent intent=new Intent(Splash_A.this, MainMenuActivity.class);
if(getIntent().getExtras()!=null) {
intent.putExtras(getIntent().getExtras());
setIntent(null);
}
startActivity(intent);
overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
finish();
}
}.start();
}
#Override
protected void onDestroy() {
countDownTimer.cancel();
super.onDestroy();
}
public void Call_api_register_device(){
String androidId = Settings.Secure.getString(getContentResolver(),
Settings.Secure.ANDROID_ID);
JSONObject param=new JSONObject();
try {
param.put("key",androidId);
} catch (JSONException e) {
e.printStackTrace();
}
ApiRequest.Call_Api(this, ApiLinks.registerDevice, param, new Callback() {
#Override
public void Responce(String resp) {
try {
JSONObject jsonObject=new JSONObject(resp);
String code=jsonObject.optString("code");
if(code.equals("200")){
Set_Timer();
JSONObject msg=jsonObject.optJSONObject("msg");
JSONObject Device=msg.optJSONObject("Device");
SharedPreferences.Editor editor2 = Variables.sharedPreferences.edit();
editor2.putString(Variables.device_id, Device.optString("id")).commit();
}else {
Call_api_show_register_device();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
public void Call_api_show_register_device(){
String androidId = Settings.Secure.getString(getContentResolver(),
Settings.Secure.ANDROID_ID);
JSONObject param=new JSONObject();
try {
param.put("key",androidId);
} catch (JSONException e) {
e.printStackTrace();
}
ApiRequest.Call_Api(this, ApiLinks.showDeviceDetail, param, new Callback() {
#Override
public void Responce(String resp) {
try {
JSONObject jsonObject=new JSONObject(resp);
String code=jsonObject.optString("code");
if(code.equals("200")){
Set_Timer();
JSONObject msg=jsonObject.optJSONObject("msg");
JSONObject Device=msg.optJSONObject("Device");
SharedPreferences.Editor editor2 = Variables.sharedPreferences.edit();
editor2.putString(Variables.device_id, Device.optString("id")).commit();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
}
Your object is null during onDestroy, maybe wrap it around a check like
#Override
protected void onDestroy() {
super.onDestroy();
if (countDownTimer!=null) {
countDownTimer.cancel();
}
}

Splashscreen and Intents

I'm developing this android application, that receives data from the gallery (in my case an image) and displays it. What i also had to do is to create a SplashScreen for my app. But when i did my intent became null .
Manifest code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.xkbc1923.myapplication">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".AlertExampleActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="text/*" />
</intent-filter>
</activity>
</application>
SplashScreen
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class SplashScreen extends Activity {
private static final int DISPLAY_DURATION = 1000;
#Override
protected final void onCreate(final Bundle savedInstState) {
super.onCreate(savedInstState);
setContentView(R.layout.activity_splashscreen);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent i = new Intent(SplashScreen.this, AlertExampleActivity.class);
startActivity(i);
// close this activity
finish();
}
}, DISPLAY_DURATION);
}
}
MainActivity
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import java.io.File;
import static android.provider.CalendarContract.CalendarCache.URI;
public class AlertExampleActivity extends AppCompatActivity {
ImageView picView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
///get the image view
//get the text view
setContentView(R.layout.activity_alert_example);
picView = (ImageView) findViewById(R.id.picture);
TextView txtView = (TextView) findViewById(R.id.txt);
if (txtView ==null) {
Log.w("Example", "TextView is null");
}
//get the received intent
Intent receivedIntent = getIntent();
//get the action
String receivedAction = receivedIntent.getAction();
//find out what we are dealing with
String receivedType = receivedIntent.getType();
//make sure it's an action and type we can handle
if (receivedAction.equals(Intent.ACTION_SEND)) {
Log.d("Example", "Send received");
//content is being shared
if (receivedType.startsWith("text/")) {
Log.d("Example", "Text received");
//handle sent text
//hide the other ui item
picView.setVisibility(View.GONE);
//get the received text
String receivedText = receivedIntent.getStringExtra(Intent.EXTRA_TEXT);
//check we have a string
if (receivedText != null) {
//set the text
txtView.setText(receivedText);
}
} else if (receivedType.startsWith("image/")) {
Log.d("Example", "Image received");
//handle sent image
handleSendImage(receivedIntent);
}
} else if (receivedAction.equals(Intent.ACTION_MAIN)) {
//app has been launched directly, not from share list
Log.d("Example", "Direct launch of App");
}
}
private void handleSendImage(Intent intent) {
// Get the image URI from intent
Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
// When image URI is not null
if (imageUri != null) {
// Update UI to reflect image being shared
picView.setImageURI(imageUri);
} else{
Toast.makeText(this, "Error occured, URI is invalid", Toast.LENGTH_LONG).show();
}
}
}
You did not add any extra data to your intent. So it would be null normally. Just add necessary data to Intent (i) on SplashScreen.java. Ex -
i.setAction("action");
i.setType("type");
i.putExtra("key", "value");
I am not sure if this gonna solve your problem but you can try.
Instead of :
Intent i = new Intent(SplashScreen.this, AlertExampleActivity.class);
startActivity(i);
// close this activity
finish();
Try this:
startActivity(new Intent(SplashScreen.this, AlertExampleActivity.class));
finish();
I've changed the manifest file since i want the splashscreen to appear even when it's externally called .
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".AlertExampleActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".SplashScreen">
<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.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="text/*" />
</intent-filter>
</activity>
</application>
And changed the SplashscreenActivity :
public class SplashScreen extends Activity {
private static final int DISPLAY_DURATION = 1000;
#Override
protected final void onCreate(final Bundle savedInstState) {
super.onCreate(savedInstState);
setContentView(R.layout.activity_splashscreen);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent i = new Intent(SplashScreen.this, AlertExampleActivity.class);
i.setAction(Intent.ACTION_SEND);
i.setType("*/*");
String[] mimetypes = {"image/*", "video/*"};
i.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
startActivity(i);
// close this activity
finish();
}
}, DISPLAY_DURATION);
}
}
I haven't changed anything in the MainActivity , but now i no longer receive the image ... I'm new to Android so i would really appreciate the explanation.

Facebook Graph API on Android - creating new post on my own page

I have this sourcecode :
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import java.net.URL;
import facebook4j.Account;
import facebook4j.Facebook;
import facebook4j.FacebookFactory;
import facebook4j.PostUpdate;
import facebook4j.auth.AccessToken;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try{
Facebook facebook = new FacebookFactory().getInstance();
facebook.setOAuthAppId(String.valueOf(R.string.facebook_app_id), String.valueOf(R.string.facebook_app_secret));
facebook.setOAuthAccessToken(new facebook4j.auth.AccessToken("10000000000003|mqs000000000000C46A"));
String pageToken = "EAAUB000000000000000000000000000000000000000000000123000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000AZDZD";
for (Account a : facebook.getAccounts()) {
if (a.getName().toLowerCase().contains("nameOfPage")) {
pageToken = a.getAccessToken();
PostUpdate post = new PostUpdate(new URL("https://facebook.com/1000000000000003/feed"))
.picture(new URL("http://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.png"))
.name("example name")
.caption("example caption")
.message("example message")
.description("example description");
if (pageToken != null) {
facebook.setOAuthAccessToken(new AccessToken("EAAUB000000000000000000000000000000000000000000000000000123000000000000000000000000000000000000000000123000000000000000000000000000000000000000000000000000000000000000000000AZDZD"));
facebook.postFeed(post);
//ScriptGroup.Input.addInfoAnnotation(req, "sysAdminTools.annotation.fb.ok");
}
}
}
}catch(Exception e){
System.out.println();
}
}
}
With manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="test.app">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/facebook_app_id"/>
<provider android:authorities="com.facebook.app.FacebookContentProvider1400000000000003"
android:name="com.facebook.FacebookContentProvider"
android:exported="true" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
and it is not working. I am trying to Google it for over a hour and I cant find anything expect this. I have PageToken, AppToken with AppSecret already generated by myself. Can you please explain me whats wrong and recommend sollution?
Every time I press button logcat shows this but nothing happen:
09-11 8:24:69.420 28087-28087/test.app I/HwSecImmHelper: mSecurityInputMethodService is null
App is not crashing, no errors are thrown, just nothing is happening at all.
Thanks

cant get sound to play on android splash screen (android studio)

i am trying to get a sound file to play when my splash screen is showing on my android app.... i have been trying to figure it out for a few hours now..... when i run my app it just skips the splash sreen all together now
here is my SplashScreen.java
package com.skapaidbeats.app.skapaidbeats;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import com.skapaidbeats.app.skapaidbeats.MainActivity;
import com.skapaidbeats.app.skapaidbeats.R;
public class SplashScreen extends Activity {
MediaPlayer music;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread timerThread = new Thread(){
public void run(){
try{
music= MediaPlayer.create(SplashScreen.this, R.raw.sound);
music.start();
sleep(3000);
}catch(InterruptedException e){
e.printStackTrace();
}finally{
Intent intent = new Intent(SplashScreen.this,MainActivity.class);
startActivity(intent);
}
}
};
timerThread.start();
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
music.release();
finish();
}
}
Here is my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
package="com.skapaidbeats.app.skapaidbeats">
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".SplashScreen"
android:screenOrientation="portrait"
android:label="#string/icon_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar">
</activity>
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:screenOrientation="portrait"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="com.startapp.android.publish.list3d.List3DActivity"
android:theme="#android:style/Theme" />
<activity
android:name="com.startapp.android.publish.AppWallActivity"
android:configChanges="orientation|keyboardHidden"
android:theme="#android:style/Theme.Translucent" />
<activity
android:name="com.startapp.android.publish.OverlayActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="#android:style/Theme.Translucent" />
<activity
android:name="com.startapp.android.publish.FullScreenActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="#android:style/Theme" />
</application>
</manifest>
Did you declare your activity in the manifest?
If you did, this question was asked before, try the following:
Android Sound not playing in splash screen
How to play audio in splash screen in android
You can try this
MediaPlayer player = new MediaPlayer();
player.setDataSource("/sdcard/audiotrack.mp3");
player.prepare();
player.start();

android: can't play video

I'm trying to play an video on my android app, but when I click on the activity through my menu list, the app stays on the list and doesn't play the video.
The code is below
my menu
package com.example.taekwondobuddy.util;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Kicks extends ListActivity {
String classes[] = {"FrontKick","RoundhouseKick","AxeKick"} ;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Kicks.this, android.R.layout.simple_list_item_1, classes));
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String cheese = classes[position];
try{
Class ourclass = Class.forName("com.example.taekwondobuddy.util" + cheese);
Intent ourIntent = new Intent(Kicks.this, ourclass);
startActivity(ourIntent);
} catch(ClassNotFoundException e){
e.printStackTrace();
}
}
}
the video I'm trying to play
package com.example.taekwondobuddy.util;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class RoundhouseKick extends Activity {
private VideoView mVideoView;
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.roundhousekick);
mVideoView = (VideoView) findViewById(R.id.roundhousekick);
mVideoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() +"/"+R.raw.roundhousekick));
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();
}
}
the xml layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<VideoView
android:id="#+id/roundhousekick"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
and the manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.taekwondobuddy.util"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.taekwondobuddy.util.Menu"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.taekwondobuddy.util.Tools"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.taekwondobuddy.util.Techniques"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.taekwondobuddy.util.Kicks"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
</activity>
<activity
android:name="com.example.taekwondobuddy.util.Counter"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
</activity>
<activity
android:name="com.example.taekwondobuddy.util.Time"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
</activity>
<activity
android:name="com.example.taekwondobuddy.util.Accelermeter"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
</activity>
<activity
android:name="com.example.taekwondobuddy.util.FrontKick"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
</activity>
<activity
android:name="com.example.taekwondobuddy.util.RoundhouseKick"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
</activity>
<activity
android:name="com.example.taekwondobuddy.util.AxeKick"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
</activity>
</application>
</manifest>
I think it something wrong with the manifest but I can't really see what's wrong, any ideas? Plus the video are in mp4 so they're are in the right format for android
I think, you just missed one little thing: a dot (.)
See at your code here:
Class ourclass = Class.forName("com.example.taekwondobuddy.util" + cheese);
don't you think it should be like this:
Class ourclass = Class.forName("com.example.taekwondobuddy.util." + cheese);
Try to use:
mVideoView.start();

Categories